Skip to content

Commit 9fed48b

Browse files
committed
fix(claws): preserve extension update provenance
1 parent 2c6f023 commit 9fed48b

4 files changed

Lines changed: 98 additions & 6 deletions

File tree

‎src/claws/packages.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,56 @@ describe("preflightClawPackage isolated plugin inspection", () => {
284284
expect(createProbeExtensionsDir).not.toHaveBeenCalled();
285285
});
286286

287+
it("preserves canonical inspection when an installed plugin version conflicts", async () => {
288+
const probePluginConflict = vi.fn(async () => ({
289+
ok: true as const,
290+
pluginId: "audit",
291+
packageName: "@owner/audit",
292+
targetDir: "/tmp/claw-plugin-probe/audit",
293+
extensions: [],
294+
artifactInspection: {
295+
format: "claude" as const,
296+
mapped: ["commands", "skills"],
297+
unavailable: ["agents"],
298+
},
299+
clawhub: {
300+
source: "clawhub" as const,
301+
clawhubUrl: "https://clawhub.ai",
302+
clawhubPackage: "@owner/audit",
303+
clawhubFamily: "code-plugin" as const,
304+
integrity,
305+
},
306+
}));
307+
308+
await expect(
309+
preflightClawPackage(pluginPackage, "/tmp/workspace", {
310+
deps: {
311+
preflightPlugin: vi.fn(async () => ({
312+
ok: false as const,
313+
code: "plugin_version_conflict" as const,
314+
error: "Installed plugin has a different version.",
315+
installedVersion: "1.0.0",
316+
expectedVersion: pluginPackage.version,
317+
request: {} as never,
318+
})),
319+
probePlugin: probePluginConflict,
320+
createProbeExtensionsDir: vi.fn(async () => "/tmp/claw-plugin-probe"),
321+
removeProbeExtensionsDir: vi.fn(async () => undefined),
322+
},
323+
}),
324+
).resolves.toMatchObject({
325+
ok: false,
326+
code: "plugin_version_conflict",
327+
installedVersion: "1.0.0",
328+
integrity: `sha256-${Buffer.from("a".repeat(64), "hex").toString("base64")}`,
329+
installId: "audit",
330+
detectedFormat: "claude",
331+
mapped: ["commands", "skills"],
332+
unavailable: ["agents"],
333+
adapterIdentity: expect.stringMatching(/^openclaw\//),
334+
});
335+
});
336+
287337
it("inspects an exact installed plugin outside its live extension directory", async () => {
288338
const removeProbeExtensionsDir = vi.fn(async () => {
289339
throw new Error("temporary directory is still busy");

‎src/claws/packages.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,23 @@ export async function preflightClawPackage(
257257
message: `Plugin ${pkg.ref}@${pkg.version} did not resolve an artifact integrity.`,
258258
};
259259
}
260+
const requirements = resolveClawPluginSetupRequirements({
261+
pluginId: probe.pluginId,
262+
setup: probe.setup,
263+
env: options.env ?? process.env,
264+
});
260265
if (!result.ok) {
261266
return {
262267
ok: false,
263268
code: result.code,
264269
installedVersion: result.installedVersion,
265270
integrity,
266271
installId: probe.pluginId,
272+
...(requirements.length > 0 ? { requirements } : {}),
273+
detectedFormat: probe.artifactInspection.format,
274+
mapped: probe.artifactInspection.mapped,
275+
unavailable: probe.artifactInspection.unavailable,
276+
adapterIdentity: `openclaw/${VERSION}`,
267277
...(probe.warning ? { warning: probe.warning } : {}),
268278
message: `Plugin ${pkg.ref}@${pkg.version} conflicts with installed version ${result.installedVersion}.`,
269279
};
@@ -280,11 +290,6 @@ export async function preflightClawPackage(
280290
message: `Plugin ${pkg.ref}@${pkg.version} is installed as ${result.installedId} with integrity ${result.installedIntegrity ?? "unknown"}, expected ${probe.pluginId} with ${integrity}.`,
281291
};
282292
}
283-
const requirements = resolveClawPluginSetupRequirements({
284-
pluginId: probe.pluginId,
285-
setup: probe.setup,
286-
env: options.env ?? process.env,
287-
});
288293
return {
289294
ok: true,
290295
action: result.action,

‎src/claws/update-apply.test.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
33
import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js";
44
import type { OpenClawConfig } from "../config/types.openclaw.js";
55
import { ClawCronUpdateError } from "./cron-update.js";
6+
import type { buildClawAddPlan } from "./lifecycle.js";
67
import {
78
persistClawInstallRecord,
89
readClawInstallRecord,
@@ -590,6 +591,35 @@ describe("applyClawUpdatePlan", () => {
590591
},
591592
],
592593
};
594+
const conflictPreflight = {
595+
ok: false as const,
596+
code: "plugin_version_conflict",
597+
message: "The Claw owns the installed previous version.",
598+
installedVersion: "1.0.0",
599+
integrity: packageDetails.integrity,
600+
installId: packageDetails.installId,
601+
detectedFormat: extensionProvenance.detectedFormat,
602+
mapped: extensionProvenance.mapped,
603+
unavailable: extensionProvenance.unavailable,
604+
adapterIdentity: extensionProvenance.adapterIdentity,
605+
};
606+
const buildAddPlan = vi.fn(async (params: Parameters<typeof buildClawAddPlan>[0]) => {
607+
const preflight = await params.context.packagePreflight?.(
608+
targetPackage,
609+
addPlan.agent.workspace,
610+
);
611+
expect(preflight).toMatchObject({
612+
ok: true,
613+
action: "install",
614+
integrity: packageDetails.integrity,
615+
installId: packageDetails.installId,
616+
detectedFormat: extensionProvenance.detectedFormat,
617+
mapped: extensionProvenance.mapped,
618+
unavailable: extensionProvenance.unavailable,
619+
adapterIdentity: extensionProvenance.adapterIdentity,
620+
});
621+
return targetAddPlan;
622+
});
593623
const applyPackage = vi.fn(async () => ({
594624
appliedIds: ["plugin:github"],
595625
rollback: vi.fn(async () => undefined),
@@ -602,7 +632,8 @@ describe("applyClawUpdatePlan", () => {
602632
config: {},
603633
...consent(updatePlan),
604634
rebuildPlan: vi.fn(async () => updatePlan),
605-
buildAddPlan: vi.fn(async () => targetAddPlan),
635+
buildAddPlan,
636+
packagePreflight: vi.fn(async () => conflictPreflight),
606637
readInstall: vi.fn(() => install),
607638
persistInstall: vi.fn(() => ({ ...install, claw: source })),
608639
applyWorkspace: vi.fn(async () => ({
@@ -621,6 +652,7 @@ describe("applyClawUpdatePlan", () => {
621652
},
622653
);
623654

655+
expect(buildAddPlan).toHaveBeenCalledOnce();
624656
expect(applyPackage).toHaveBeenCalledOnce();
625657
});
626658

‎src/claws/update-apply.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ export async function applyClawUpdatePlan(
208208
...(preflight.integrity ? { integrity: preflight.integrity } : {}),
209209
...(preflight.installId ? { installId: preflight.installId } : {}),
210210
...(preflight.warning ? { warning: preflight.warning } : {}),
211+
...(preflight.requirements ? { requirements: preflight.requirements } : {}),
212+
...(preflight.detectedFormat ? { detectedFormat: preflight.detectedFormat } : {}),
213+
...(preflight.mapped ? { mapped: preflight.mapped } : {}),
214+
...(preflight.unavailable ? { unavailable: preflight.unavailable } : {}),
215+
...(preflight.adapterIdentity ? { adapterIdentity: preflight.adapterIdentity } : {}),
211216
}
212217
: preflight;
213218
},

0 commit comments

Comments
 (0)