Skip to content

Commit 7ab05df

Browse files
steipetePeter Steinberger
andauthored
fix(plugins): require tracked owners for targeted updates (#117333)
Co-authored-by: Peter Steinberger <[email protected]>
1 parent a84302c commit 7ab05df

4 files changed

Lines changed: 90 additions & 16 deletions

File tree

‎src/cli/plugins-cli.update.test.ts‎

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,64 @@ describe("plugins cli update", () => {
270270
expect(writeConfigFile).not.toHaveBeenCalled();
271271
});
272272

273+
it.each([
274+
{ id: "missing-plugin", args: [] },
275+
{ id: "missing-plugin", args: ["--dry-run"] },
276+
{ id: "constructor", args: [] },
277+
{ id: "@acme/missing-plugin@beta", args: [] },
278+
])("rejects untracked update target $id $args", async ({ id, args }) => {
279+
const config = {} as OpenClawConfig;
280+
primeUpdateConfigSnapshot({ config });
281+
updateNpmInstalledPlugins.mockResolvedValue({
282+
config,
283+
changed: false,
284+
outcomes: [{ pluginId: id, status: "skipped", message: `No install record for "${id}".` }],
285+
});
286+
287+
await expect(runPluginsCommand(["plugins", "update", id, ...args])).rejects.toThrow(
288+
"__exit__:1",
289+
);
290+
291+
expect(runtimeErrors.at(-1)).toContain(`No tracked plugin or hook pack found for "${id}".`);
292+
expect(updateNpmInstalledPlugins).not.toHaveBeenCalled();
293+
expect(updateNpmInstalledHookPacks).not.toHaveBeenCalled();
294+
expect(writeConfigFile).not.toHaveBeenCalled();
295+
});
296+
297+
it("rejects an npm update target shared by multiple tracked plugins", async () => {
298+
const config = {
299+
plugins: {
300+
installs: {
301+
alpha: {
302+
source: "npm",
303+
spec: "@acme/shared",
304+
installPath: "/tmp/alpha",
305+
resolvedName: "@acme/shared",
306+
},
307+
beta: {
308+
source: "npm",
309+
spec: "@acme/shared",
310+
installPath: "/tmp/beta",
311+
resolvedName: "@acme/shared",
312+
},
313+
},
314+
},
315+
} as OpenClawConfig;
316+
primeUpdateConfigSnapshot({ config });
317+
setInstalledPluginIndexInstallRecords(config.plugins?.installs ?? {});
318+
319+
await expect(runPluginsCommand(["plugins", "update", "@acme/shared@beta"])).rejects.toThrow(
320+
"__exit__:1",
321+
);
322+
323+
expect(runtimeErrors.at(-1)).toContain(
324+
'No tracked plugin or hook pack found for "@acme/shared@beta".',
325+
);
326+
expect(updateNpmInstalledPlugins).not.toHaveBeenCalled();
327+
expect(updateNpmInstalledHookPacks).not.toHaveBeenCalled();
328+
expect(writeConfigFile).not.toHaveBeenCalled();
329+
});
330+
273331
it("updates tracked hook packs through plugins update", async () => {
274332
const cfg = {} as OpenClawConfig;
275333
const nextConfig = cfg;
@@ -303,8 +361,9 @@ describe("plugins cli update", () => {
303361
await runPluginsCommand(["plugins", "update", "demo-hooks"]);
304362

305363
const hookUpdateParams = expectSingleCallParams(updateNpmInstalledHookPacks);
306-
expect(hookUpdateParams.config).toBe(cfg);
364+
expect(hookUpdateParams.config).toEqual({ ...cfg, plugins: { installs: {} } });
307365
expect(hookUpdateParams.hookIds).toEqual(["demo-hooks"]);
366+
expect(updateNpmInstalledPlugins).not.toHaveBeenCalled();
308367
expect(writeConfigFile).toHaveBeenCalledWith(nextConfig);
309368
expect(replaceConfigFile).toHaveBeenCalledWith(
310369
expect.objectContaining({ nextConfig, baseHash: "update-config" }),
@@ -973,12 +1032,12 @@ describe("plugins cli update", () => {
9731032
await runPluginsCommand(["plugins", "update", "demo-hooks"]);
9741033

9751034
expect(runtimeErrors).toEqual([]);
976-
const pluginUpdateParams = expectSingleCallParams(updateNpmInstalledPlugins);
977-
expect(pluginUpdateParams.config).toEqual({
1035+
const hookUpdateParams = expectSingleCallParams(updateNpmInstalledHookPacks);
1036+
expect(hookUpdateParams.config).toEqual({
9781037
...cfg,
9791038
plugins: { installs: {} },
9801039
});
981-
expect(updateNpmInstalledHookPacks).toHaveBeenCalledOnce();
1040+
expect(updateNpmInstalledPlugins).not.toHaveBeenCalled();
9821041
expect(writeConfigFile).not.toHaveBeenCalled();
9831042
});
9841043

‎src/cli/plugins-update-command.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ async function runPluginUpdateCommandUnlocked(params: RunPluginUpdateCommandPara
248248
defaultRuntime.log("No tracked plugins or hook packs to update.");
249249
return;
250250
}
251-
defaultRuntime.error("Provide a plugin or hook-pack id, or use --all.");
251+
defaultRuntime.error(
252+
params.id
253+
? `No tracked plugin or hook pack found for "${params.id}". Run "openclaw plugins list" or "openclaw hooks list" to inspect installed packages.`
254+
: "Provide a plugin or hook-pack id, or use --all.",
255+
);
252256
return defaultRuntime.exit(1);
253257
}
254258

‎src/cli/plugins-update-selection.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ function createNpmHookInstall(params: {
3434
}
3535

3636
describe("resolvePluginUpdateSelection", () => {
37+
it.each(["missing-plugin", "@acme/missing-plugin@beta", "constructor"])(
38+
"does not select the untracked plugin target %s",
39+
(rawId) => {
40+
expect(resolvePluginUpdateSelection({ installs: {}, rawId })).toEqual({ pluginIds: [] });
41+
},
42+
);
43+
44+
it("does not guess an owner when an npm package maps to multiple tracked plugins", () => {
45+
expect(
46+
resolvePluginUpdateSelection({
47+
installs: {
48+
alpha: createNpmInstall({ spec: "@acme/shared", resolvedName: "@acme/shared" }),
49+
beta: createNpmInstall({ spec: "@acme/shared", resolvedName: "@acme/shared" }),
50+
},
51+
rawId: "@acme/shared@beta",
52+
}),
53+
).toEqual({ pluginIds: [] });
54+
});
55+
3756
it("maps an explicit unscoped npm dist-tag update to the tracked plugin id", () => {
3857
expect(
3958
resolvePluginUpdateSelection({

‎src/cli/plugins-update-selection.ts‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,18 @@ export function resolvePluginUpdateSelection(params: {
2727

2828
const parsedSpec = parseRegistryNpmSpec(params.rawId);
2929
if (!parsedSpec) {
30-
return { pluginIds: [params.rawId] };
30+
return { pluginIds: [] };
3131
}
3232
const matches = Object.entries(params.installs).filter(([, install]) => {
3333
return extractInstalledNpmPackageName(install) === parsedSpec.name;
3434
});
3535
if (matches.length !== 1) {
36-
return { pluginIds: [params.rawId] };
36+
return { pluginIds: [] };
3737
}
3838

3939
const [pluginId] = expectDefined(matches[0], "matches capture group 0");
4040
if (!pluginId) {
41-
return { pluginIds: [params.rawId] };
42-
}
43-
if (parsedSpec.selectorKind === "none") {
44-
return {
45-
pluginIds: [pluginId],
46-
specOverrides: {
47-
[pluginId]: parsedSpec.raw,
48-
},
49-
};
41+
return { pluginIds: [] };
5042
}
5143
return {
5244
pluginIds: [pluginId],

0 commit comments

Comments
 (0)