Skip to content

Commit eb28780

Browse files
LilacLilac
authored andcommitted
fix(plugins): pin official npm install records
1 parent d9d5d97 commit eb28780

9 files changed

Lines changed: 202 additions & 21 deletions

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export async function runPluginUpdateCommand(params: {
6060
config: cfgWithPluginInstallRecords,
6161
pluginIds: pluginSelection.pluginIds,
6262
specOverrides: pluginSelection.specOverrides,
63+
syncOfficialPluginInstalls: true,
6364
dryRun: params.opts.dryRun,
6465
dangerouslyForceUnsafeInstall: params.opts.dangerouslyForceUnsafeInstall,
6566
logger,

‎src/commands/doctor/shared/missing-configured-plugin-install.test.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ describe("repairMissingConfiguredPluginInstalls", () => {
17481748
const records = mockCallArg(mocks.writePersistedInstalledPluginIndexInstallRecords);
17491749
expectRecordFields((records as Record<string, unknown>).codex, {
17501750
source: "npm",
1751-
spec: "@openclaw/codex",
1751+
spec: "@openclaw/codex@2026.5.2",
17521752
installPath: "/tmp/openclaw-plugins/codex",
17531753
version: "2026.5.2",
17541754
});
@@ -1849,7 +1849,7 @@ describe("repairMissingConfiguredPluginInstalls", () => {
18491849
]);
18501850
expectRecordFields(result.records.codex, {
18511851
source: "npm",
1852-
spec: "@openclaw/codex",
1852+
spec: `@openclaw/codex@${VERSION}`,
18531853
installPath: "/tmp/openclaw-plugins/codex",
18541854
version: VERSION,
18551855
resolvedName: "@openclaw/codex",
@@ -1948,7 +1948,7 @@ describe("repairMissingConfiguredPluginInstalls", () => {
19481948
]);
19491949
expectRecordFields(firstPass.records.codex, {
19501950
source: "npm",
1951-
spec: "@openclaw/codex",
1951+
spec: `@openclaw/codex@${codexBetaVersion}`,
19521952
installPath: installDir,
19531953
version: codexBetaVersion,
19541954
resolvedName: "@openclaw/codex",
@@ -2159,7 +2159,7 @@ describe("repairMissingConfiguredPluginInstalls", () => {
21592159
const records = mockCallArg(mocks.writePersistedInstalledPluginIndexInstallRecords);
21602160
expectRecordFields((records as Record<string, unknown>).codex, {
21612161
source: "npm",
2162-
spec: "@openclaw/codex",
2162+
spec: "@openclaw/codex@2026.5.2",
21632163
installPath: "/tmp/openclaw-plugins/codex",
21642164
version: "2026.5.2",
21652165
});
@@ -2173,7 +2173,7 @@ describe("repairMissingConfiguredPluginInstalls", () => {
21732173
expect(Object.keys(result.records)).toEqual(["codex"]);
21742174
expectRecordFields(result.records.codex, {
21752175
source: "npm",
2176-
spec: "@openclaw/codex",
2176+
spec: "@openclaw/codex@2026.5.2",
21772177
installPath: "/tmp/openclaw-plugins/codex",
21782178
version: "2026.5.2",
21792179
resolvedName: "@openclaw/codex",
@@ -2677,6 +2677,7 @@ describe("repairMissingConfiguredPluginInstalls", () => {
26772677
});
26782678
const persistedRecords = mockCallArg(mocks.writePersistedInstalledPluginIndexInstallRecords);
26792679
expectRecordFields((persistedRecords as Record<string, unknown>).discord, {
2680+
spec: "@openclaw/[email protected]",
26802681
installPath: "/tmp/openclaw-plugins/discord",
26812682
});
26822683
expect(mockCallArg(mocks.writePersistedInstalledPluginIndexInstallRecords, 0, 1)).toEqual({
@@ -3040,7 +3041,7 @@ describe("repairMissingConfiguredPluginInstalls", () => {
30403041
) as Record<string, unknown>;
30413042
expectRecordFields(persistedRecords.brave, {
30423043
source: "npm",
3043-
spec: "@openclaw/brave-plugin",
3044+
spec: "@openclaw/brave-plugin@2026.5.12",
30443045
installPath: "/tmp/openclaw-plugins/brave",
30453046
version: "2026.5.12",
30463047
});
@@ -3527,7 +3528,9 @@ describe("repairMissingConfiguredPluginInstalls", () => {
35273528
const persistedRecords = mockCallArg(
35283529
mocks.writePersistedInstalledPluginIndexInstallRecords,
35293530
) as Record<string, unknown>;
3530-
expectRecordFields(persistedRecords.brave, { spec: "@openclaw/brave-plugin" });
3531+
expectRecordFields(persistedRecords.brave, {
3532+
spec: "@openclaw/[email protected]",
3533+
});
35313534
expect(mockCallArg(mocks.writePersistedInstalledPluginIndexInstallRecords, 0, 1)).toEqual({
35323535
env: {},
35333536
});

‎src/commands/doctor/shared/missing-configured-plugin-install.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ import { installPluginFromNpmSpec } from "../../../plugins/install.js";
3737
import { loadInstalledPluginIndexInstallRecords } from "../../../plugins/installed-plugin-index-records.js";
3838
import { writePersistedInstalledPluginIndexInstallRecords } from "../../../plugins/installed-plugin-index-records.js";
3939
import { loadInstalledPluginIndex } from "../../../plugins/installed-plugin-index.js";
40-
import { buildNpmResolutionInstallFields } from "../../../plugins/installs.js";
40+
import {
41+
buildNpmResolutionInstallFields,
42+
resolveNpmInstallRecordSpec,
43+
} from "../../../plugins/installs.js";
4144
import { readLegacyNpmPluginDeclaration } from "../../../plugins/legacy-npm-declaration.js";
4245
import { loadManifestMetadataSnapshot } from "../../../plugins/manifest-contract-eligibility.js";
4346
import type { PluginPackageInstall } from "../../../plugins/manifest.js";
@@ -1028,7 +1031,11 @@ async function installCandidate(params: {
10281031
...params.records,
10291032
[pluginId]: {
10301033
source: "npm",
1031-
spec: npmSpecs?.recordSpec ?? npmInstallSpec,
1034+
spec: resolveNpmInstallRecordSpec({
1035+
requestedSpec: npmSpecs?.recordSpec ?? npmInstallSpec,
1036+
resolution: result.npmResolution,
1037+
pinResolvedRegistrySpec: candidate.trustedSourceLinkedOfficialInstall === true,
1038+
}),
10321039
installPath: result.targetDir,
10331040
version: result.version,
10341041
installedAt: new Date().toISOString(),
@@ -1113,18 +1120,29 @@ async function adoptExistingNpmPackage(params: {
11131120
warnings: string[];
11141121
}> {
11151122
const npmName = parseRegistryNpmSpec(params.npmInstallSpec)?.name;
1123+
const npmResolution = npmName
1124+
? {
1125+
name: npmName,
1126+
version: params.version,
1127+
resolvedSpec: `${npmName}@${params.version}`,
1128+
}
1129+
: undefined;
11161130
return {
11171131
records: {
11181132
...params.records,
11191133
[params.candidate.pluginId]: {
11201134
source: "npm",
1121-
spec: params.npmRecordSpec,
1135+
spec: resolveNpmInstallRecordSpec({
1136+
requestedSpec: params.npmRecordSpec,
1137+
resolution: npmResolution,
1138+
pinResolvedRegistrySpec: params.candidate.trustedSourceLinkedOfficialInstall === true,
1139+
}),
11221140
installPath: params.packagePath,
11231141
installedAt: new Date().toISOString(),
11241142
version: params.version,
11251143
resolvedVersion: params.version,
11261144
...(npmName ? { resolvedName: npmName } : {}),
1127-
...(npmName ? { resolvedSpec: `${npmName}@${params.version}` } : {}),
1145+
...(npmResolution ? { resolvedSpec: npmResolution.resolvedSpec } : {}),
11281146
},
11291147
},
11301148
changes: [

‎src/commands/onboarding-plugin-install.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,24 @@ const recordPluginInstall = vi.hoisted(() =>
7878
})),
7979
);
8080
const buildNpmResolutionInstallFields = vi.hoisted(() => vi.fn(() => ({})));
81+
const resolveNpmInstallRecordSpec = vi.hoisted(() =>
82+
vi.fn(
83+
(params: {
84+
requestedSpec?: string;
85+
resolution?: { resolvedSpec?: string };
86+
pinResolvedRegistrySpec?: boolean;
87+
}) => {
88+
if (params.pinResolvedRegistrySpec && params.resolution?.resolvedSpec) {
89+
return params.resolution.resolvedSpec;
90+
}
91+
return params.requestedSpec;
92+
},
93+
),
94+
);
8195
vi.mock("../plugins/installs.js", () => ({
8296
recordPluginInstall,
8397
buildNpmResolutionInstallFields,
98+
resolveNpmInstallRecordSpec,
8499
}));
85100

86101
const withTimeout = vi.hoisted(() => vi.fn(async <T>(promise: Promise<T>) => await promise));

‎src/commands/onboarding-plugin-install.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ import {
3131
installPluginFromNpmPackArchive,
3232
type InstallPluginResult,
3333
} from "../plugins/install.js";
34-
import { buildNpmResolutionInstallFields, recordPluginInstall } from "../plugins/installs.js";
34+
import {
35+
buildNpmResolutionInstallFields,
36+
recordPluginInstall,
37+
resolveNpmInstallRecordSpec,
38+
} from "../plugins/installs.js";
3539
import type { PluginPackageInstall } from "../plugins/manifest.js";
3640
import type { RuntimeEnv } from "../runtime.js";
3741
import { withTimeout } from "../utils/with-timeout.js";
@@ -1240,7 +1244,11 @@ export async function ensureOnboardingPluginInstalled(params: {
12401244
const install = {
12411245
pluginId: result.pluginId,
12421246
source: "npm",
1243-
spec: npmSpecs?.recordSpec ?? npmInstallSpec,
1247+
spec: resolveNpmInstallRecordSpec({
1248+
requestedSpec: npmSpecs?.recordSpec ?? npmInstallSpec,
1249+
resolution: result.npmResolution,
1250+
pinResolvedRegistrySpec: entry.trustedSourceLinkedOfficialInstall === true,
1251+
}),
12441252
installPath: result.targetDir,
12451253
version: result.version,
12461254
...buildNpmResolutionInstallFields(result.npmResolution),

‎src/plugins/installs.test.ts‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { afterEach, describe, expect, it, vi } from "vitest";
2-
import { buildNpmResolutionInstallFields, recordPluginInstall } from "./installs.js";
2+
import {
3+
buildNpmResolutionInstallFields,
4+
recordPluginInstall,
5+
resolveNpmInstallRecordSpec,
6+
} from "./installs.js";
37

48
function expectRecordedInstall(pluginId: string, next: ReturnType<typeof recordPluginInstall>) {
59
expect(next).toEqual({
@@ -78,6 +82,60 @@ describe("buildNpmResolutionInstallFields", () => {
7882
] as const)("$name", expectResolutionFieldsCase);
7983
});
8084

85+
describe("resolveNpmInstallRecordSpec", () => {
86+
it("uses an exact resolved registry spec when managed installs request pinning", () => {
87+
expect(
88+
resolveNpmInstallRecordSpec({
89+
requestedSpec: "@openclaw/codex",
90+
resolution: {
91+
name: "@openclaw/codex",
92+
version: "2026.5.30-beta.1",
93+
resolvedSpec: "@openclaw/[email protected]",
94+
},
95+
pinResolvedRegistrySpec: true,
96+
}),
97+
).toBe("@openclaw/[email protected]");
98+
});
99+
100+
it("keeps moving specs unless the caller owns managed pinning", () => {
101+
expect(
102+
resolveNpmInstallRecordSpec({
103+
requestedSpec: "@openclaw/codex",
104+
resolution: {
105+
name: "@openclaw/codex",
106+
version: "2026.5.30-beta.1",
107+
resolvedSpec: "@openclaw/[email protected]",
108+
},
109+
}),
110+
).toBe("@openclaw/codex");
111+
});
112+
113+
it("does not replace the requested spec with tags or non-registry resolutions", () => {
114+
expect(
115+
resolveNpmInstallRecordSpec({
116+
requestedSpec: "@openclaw/codex",
117+
resolution: {
118+
name: "@openclaw/codex",
119+
version: "2026.5.30-beta.1",
120+
resolvedSpec: "@openclaw/codex@beta",
121+
},
122+
pinResolvedRegistrySpec: true,
123+
}),
124+
).toBe("@openclaw/codex");
125+
expect(
126+
resolveNpmInstallRecordSpec({
127+
requestedSpec: "file:codex.tgz",
128+
resolution: {
129+
name: "@openclaw/codex",
130+
version: "2026.5.30-beta.1",
131+
resolvedSpec: "file:codex.tgz",
132+
},
133+
pinResolvedRegistrySpec: true,
134+
}),
135+
).toBe("file:codex.tgz");
136+
});
137+
});
138+
81139
describe("recordPluginInstall", () => {
82140
it("stores install metadata for the plugin id", () => {
83141
vi.useFakeTimers();

‎src/plugins/installs.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { OpenClawConfig } from "../config/types.openclaw.js";
22
import type { PluginInstallRecord } from "../config/types.plugins.js";
33
import { buildNpmResolutionFields, type NpmSpecResolution } from "../infra/install-source-utils.js";
4+
import { parseRegistryNpmSpec } from "../infra/npm-registry-spec.js";
45

56
export type PluginInstallUpdate = PluginInstallRecord & { pluginId: string };
67

@@ -13,6 +14,23 @@ export function buildNpmResolutionInstallFields(
1314
return buildNpmResolutionFields(resolution);
1415
}
1516

17+
function isExactRegistryNpmSpec(spec: string | undefined): spec is string {
18+
const parsed = spec ? parseRegistryNpmSpec(spec) : null;
19+
return parsed?.selectorKind === "exact-version";
20+
}
21+
22+
export function resolveNpmInstallRecordSpec(params: {
23+
requestedSpec?: string;
24+
resolution?: NpmSpecResolution;
25+
pinResolvedRegistrySpec?: boolean;
26+
}): string | undefined {
27+
const resolvedSpec = params.resolution?.resolvedSpec;
28+
if (!params.pinResolvedRegistrySpec || !isExactRegistryNpmSpec(resolvedSpec)) {
29+
return params.requestedSpec;
30+
}
31+
return resolvedSpec;
32+
}
33+
1634
export function recordPluginInstall(
1735
cfg: OpenClawConfig,
1836
update: PluginInstallUpdate,

‎src/plugins/update.test.ts‎

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,15 @@ describe("updateNpmInstalledPlugins", () => {
599599
pluginId: "acpx",
600600
targetDir: installPath,
601601
version: "2026.5.2-beta.2",
602+
npmResolution: {
603+
name: "@openclaw/acpx",
604+
version: "2026.5.2-beta.2",
605+
resolvedSpec: "@openclaw/[email protected]",
606+
},
602607
}),
603608
);
604609

605-
await updateNpmInstalledPlugins({
610+
const result = await updateNpmInstalledPlugins({
606611
config: createNpmInstallConfig({
607612
pluginId: "acpx",
608613
spec: "@openclaw/acpx",
@@ -617,6 +622,49 @@ describe("updateNpmInstalledPlugins", () => {
617622
expect(npmInstallCall()?.spec).toBe("@openclaw/acpx");
618623
expect(npmInstallCall()?.expectedPluginId).toBe("acpx");
619624
expect(npmInstallCall()?.trustedSourceLinkedOfficialInstall).toBe(true);
625+
expect(result.config.plugins?.installs?.acpx?.spec).toBe("@openclaw/[email protected]");
626+
});
627+
628+
it("keeps third-party moving npm specs when their updates resolve exact artifacts", async () => {
629+
const installPath = createInstalledPackageDir({
630+
name: "@martian-engineering/lossless-claw",
631+
version: "0.9.0",
632+
});
633+
mockNpmViewMetadata({
634+
name: "@martian-engineering/lossless-claw",
635+
version: "0.9.1",
636+
});
637+
installPluginFromNpmSpecMock.mockResolvedValue(
638+
createSuccessfulNpmUpdateResult({
639+
pluginId: "lossless-claw",
640+
targetDir: installPath,
641+
version: "0.9.1",
642+
npmResolution: {
643+
name: "@martian-engineering/lossless-claw",
644+
version: "0.9.1",
645+
resolvedSpec: "@martian-engineering/[email protected]",
646+
},
647+
}),
648+
);
649+
650+
const result = await updateNpmInstalledPlugins({
651+
config: createNpmInstallConfig({
652+
pluginId: "lossless-claw",
653+
spec: "@martian-engineering/lossless-claw",
654+
installPath,
655+
resolvedName: "@martian-engineering/lossless-claw",
656+
resolvedSpec: "@martian-engineering/[email protected]",
657+
resolvedVersion: "0.9.0",
658+
}),
659+
pluginIds: ["lossless-claw"],
660+
});
661+
662+
expect(result.config.plugins?.installs?.["lossless-claw"]?.spec).toBe(
663+
"@martian-engineering/lossless-claw",
664+
);
665+
expect(result.config.plugins?.installs?.["lossless-claw"]?.resolvedSpec).toBe(
666+
"@martian-engineering/[email protected]",
667+
);
620668
});
621669

622670
it("does not skip trusted official default updates when latest resolves to the installed prerelease", async () => {
@@ -1468,7 +1516,7 @@ describe("updateNpmInstalledPlugins", () => {
14681516
});
14691517
expectRecordFields(result.config.plugins?.installs?.codex, {
14701518
source: "npm",
1471-
spec: "@openclaw/codex",
1519+
spec: "@openclaw/codex@2026.5.4",
14721520
version: "2026.5.4",
14731521
resolvedName: "@openclaw/codex",
14741522
resolvedVersion: "2026.5.4",
@@ -2364,7 +2412,7 @@ describe("updateNpmInstalledPlugins", () => {
23642412
expect(result.config.plugins?.entries?.discord?.enabled).toBeUndefined();
23652413
expectRecordFields(result.config.plugins?.installs?.discord, {
23662414
source: "npm",
2367-
spec: "@openclaw/discord",
2415+
spec: "@openclaw/discord@2026.5.16-beta.5",
23682416
installPath: "/tmp/openclaw-plugins/discord",
23692417
version: "2026.5.16-beta.5",
23702418
});
@@ -2436,7 +2484,7 @@ describe("updateNpmInstalledPlugins", () => {
24362484
expect(npmInstallCall()?.spec).toBe("@openclaw/discord");
24372485
expectRecordFields(result.config.plugins?.installs?.discord, {
24382486
source: "npm",
2439-
spec: "@openclaw/discord",
2487+
spec: "@openclaw/discord@2026.5.16",
24402488
installPath: "/tmp/openclaw-plugins/discord",
24412489
version: "2026.5.16",
24422490
});

0 commit comments

Comments
 (0)