Skip to content

Commit 3be24fe

Browse files
NirvanJainsteipete
andauthored
fix(plugins): report missing manifest instead of misleading id mismatch on install (#128527)
* fix(plugins): report missing manifest instead of misleading id mismatch on install Added comments to clarify error handling for missing or invalid plugin manifests. * fix/comfy-manifest-mismatch-error * fix(plugins): require manifests for trusted npm installs Co-authored-by: Voidra <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent e5e90fb commit 3be24fe

2 files changed

Lines changed: 99 additions & 10 deletions

File tree

‎src/plugins/install-managed-npm.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ export async function installPluginFromManagedNpmRoot(
602602
dependencyScanRootDir: npmRoot,
603603
logger,
604604
expectedPluginId: installedExpectedPluginId,
605+
requirePluginManifest: params.trustedSourceLinkedOfficialInstall,
605606
trustedSourceLinkedOfficialInstall: params.trustedSourceLinkedOfficialInstall,
606607
mode: policyMode,
607608
installPolicyRequest: params.installPolicyRequest,

‎src/plugins/install.npm-spec.test.ts‎

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ function writeInstalledNpmPlugin(params: {
222222
packageName: string;
223223
version: string;
224224
pluginId?: string;
225+
nativeManifest?: "missing" | "malformed";
225226
legacyPluginIds?: string[];
226227
indexJs?: string;
227228
extraDistFiles?: Record<string, string>;
@@ -249,16 +250,20 @@ function writeInstalledNpmPlugin(params: {
249250
}),
250251
"utf-8",
251252
);
252-
fs.writeFileSync(
253-
path.join(pluginDir, "openclaw.plugin.json"),
254-
JSON.stringify({
255-
id: params.pluginId ?? params.packageName,
256-
name: params.pluginId ?? params.packageName,
257-
...(params.legacyPluginIds ? { legacyPluginIds: params.legacyPluginIds } : {}),
258-
configSchema: { type: "object" },
259-
}),
260-
"utf-8",
261-
);
253+
if (params.nativeManifest !== "missing") {
254+
fs.writeFileSync(
255+
path.join(pluginDir, "openclaw.plugin.json"),
256+
params.nativeManifest === "malformed"
257+
? "{invalid plugin manifest"
258+
: JSON.stringify({
259+
id: params.pluginId ?? params.packageName,
260+
name: params.pluginId ?? params.packageName,
261+
...(params.legacyPluginIds ? { legacyPluginIds: params.legacyPluginIds } : {}),
262+
configSchema: { type: "object" },
263+
}),
264+
"utf-8",
265+
);
266+
}
262267
fs.writeFileSync(
263268
path.join(pluginDir, "dist", "index.js"),
264269
params.indexJs ?? "export {};",
@@ -302,6 +307,7 @@ type MockNpmPackage = {
302307
version: string;
303308
npmRoot: string;
304309
pluginId?: string;
310+
nativeManifest?: "missing" | "malformed";
305311
legacyPluginIds?: string[];
306312
integrity?: string;
307313
shasum?: string;
@@ -3426,6 +3432,88 @@ describe("installPluginFromNpmSpec", () => {
34263432
},
34273433
);
34283434

3435+
it.each([
3436+
{
3437+
name: "missing manifest with a different expected id",
3438+
packageName: "@openclaw/comfy-provider",
3439+
expectedPluginId: "comfy",
3440+
nativeManifest: "missing",
3441+
},
3442+
{
3443+
name: "missing manifest even when the package name matches the expected id",
3444+
packageName: "@openclaw/official-placeholder",
3445+
expectedPluginId: "@openclaw/official-placeholder",
3446+
nativeManifest: "missing",
3447+
},
3448+
{
3449+
name: "malformed manifest",
3450+
packageName: "@openclaw/official-malformed",
3451+
expectedPluginId: "official-malformed",
3452+
nativeManifest: "malformed",
3453+
},
3454+
] as const)("rejects a trusted official npm plugin with a $name", async (testCase) => {
3455+
const npmRoot = path.join(suiteTempRootTracker.makeTempDir(), "npm");
3456+
const npmProjectRoot = resolvePluginNpmProjectDir({
3457+
npmDir: npmRoot,
3458+
packageName: testCase.packageName,
3459+
});
3460+
mockNpmViewAndInstall({
3461+
spec: testCase.packageName,
3462+
packageName: testCase.packageName,
3463+
version: "0.0.0",
3464+
pluginId: testCase.expectedPluginId,
3465+
nativeManifest: testCase.nativeManifest,
3466+
npmRoot,
3467+
});
3468+
3469+
const result = await installPluginFromNpmSpec({
3470+
spec: testCase.packageName,
3471+
npmDir: npmRoot,
3472+
expectedPluginId: testCase.expectedPluginId,
3473+
trustedSourceLinkedOfficialInstall: true,
3474+
logger: { info: () => {}, warn: () => {} },
3475+
});
3476+
3477+
expect(result.ok).toBe(false);
3478+
if (result.ok) {
3479+
return;
3480+
}
3481+
expect(result.code).toBe(PLUGIN_INSTALL_ERROR_CODE.MISSING_PLUGIN_MANIFEST);
3482+
expect(result.error).toContain("package missing valid openclaw.plugin.json");
3483+
expect(result.error).not.toContain("plugin id mismatch");
3484+
expect(fs.existsSync(resolveTestPluginPackageDir(npmRoot, testCase.packageName))).toBe(false);
3485+
expect(fs.existsSync(path.join(npmProjectRoot, "package.json"))).toBe(false);
3486+
expect(fs.existsSync(path.join(npmProjectRoot, "package-lock.json"))).toBe(false);
3487+
expect(fs.existsSync(path.join(npmProjectRoot, "node_modules"))).toBe(false);
3488+
});
3489+
3490+
it("preserves untrusted manifestless npm updates keyed by the legacy package name", async () => {
3491+
const packageName = "@third-party/legacy-plugin";
3492+
const npmRoot = path.join(suiteTempRootTracker.makeTempDir(), "npm");
3493+
mockNpmViewAndInstall({
3494+
spec: packageName,
3495+
packageName,
3496+
version: "1.0.0",
3497+
nativeManifest: "missing",
3498+
npmRoot,
3499+
});
3500+
3501+
const result = await installPluginFromNpmSpec({
3502+
spec: packageName,
3503+
npmDir: npmRoot,
3504+
expectedPluginId: "legacy-plugin",
3505+
trustedSourceLinkedOfficialInstall: false,
3506+
mode: "update",
3507+
logger: { info: () => {}, warn: () => {} },
3508+
});
3509+
3510+
expect(result.ok).toBe(true);
3511+
if (result.ok) {
3512+
expect(result.pluginId).toBe(packageName);
3513+
expect(fs.existsSync(resolveTestPluginPackageDir(npmRoot, packageName))).toBe(true);
3514+
}
3515+
});
3516+
34293517
it("accepts a trusted manifest-declared plugin id replacement during update", async () => {
34303518
const npmRoot = path.join(suiteTempRootTracker.makeTempDir(), "npm");
34313519
mockNpmViewAndInstall({

0 commit comments

Comments
 (0)