Skip to content

Commit f3bcee8

Browse files
authored
fix: clarify pinned plugin dry-run updates (#97282)
* fix: clarify pinned plugin dry-run updates * fix(plugins): normalize pinned npm dry-run versions
1 parent a083c76 commit f3bcee8

3 files changed

Lines changed: 124 additions & 2 deletions

File tree

‎docs/cli/plugins.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ Updates apply to tracked plugin installs in the managed plugin index and tracked
437437
<Accordion title="Resolving plugin id vs npm spec">
438438
When you pass a plugin id, OpenClaw reuses the recorded install spec for that plugin. That means previously stored dist-tags such as `@beta` and exact pinned versions continue to be used on later `update <id>` runs.
439439

440+
During `update <id> --dry-run`, exact pinned npm installs stay pinned. If OpenClaw can also resolve the package's registry default line and that default line is newer than the installed pinned version, the dry run reports the pin and prints the explicit `@latest` package update command to follow the registry default line.
441+
440442
That targeted-update rule is different from the bulk `openclaw plugins update --all` maintenance path. Bulk updates still respect ordinary tracked install specs, but trusted official OpenClaw plugin records can sync to the current official catalog target instead of staying on a stale exact official package. Use targeted `update <id>` when you intentionally want to keep an exact or tagged official spec untouched.
441443

442444
For npm installs, you can also pass an explicit npm package spec with a dist-tag or exact version. OpenClaw resolves that package name back to the tracked plugin record, updates that installed plugin, and records the new npm spec for future id-based updates.

‎src/plugins/update.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,62 @@ describe("updateNpmInstalledPlugins", () => {
24602460
});
24612461
});
24622462

2463+
it.each(["@acme/[email protected]", "@acme/[email protected]"])(
2464+
"reports newer registry default releases for exact pinned npm dry-runs from %s",
2465+
async (spec) => {
2466+
const installPath = createInstalledPackageDir({
2467+
name: "@acme/demo",
2468+
version: "1.2.3",
2469+
});
2470+
mockNpmViewMetadata({
2471+
name: "@acme/demo",
2472+
version: "1.2.4",
2473+
});
2474+
installPluginFromNpmSpecMock.mockResolvedValue({
2475+
ok: true,
2476+
pluginId: "demo",
2477+
targetDir: installPath,
2478+
version: "1.2.3",
2479+
extensions: ["index.ts"],
2480+
npmResolution: {
2481+
name: "@acme/demo",
2482+
version: "1.2.3",
2483+
resolvedSpec: spec,
2484+
},
2485+
});
2486+
2487+
const result = await updateNpmInstalledPlugins({
2488+
config: createNpmInstallConfig({
2489+
pluginId: "demo",
2490+
spec,
2491+
installPath,
2492+
}),
2493+
pluginIds: ["demo"],
2494+
dryRun: true,
2495+
});
2496+
2497+
expect(npmInstallCall()?.spec).toBe(spec);
2498+
expect(npmViewCall()?.[0]).toEqual([
2499+
"npm",
2500+
"view",
2501+
"@acme/demo",
2502+
"name",
2503+
"version",
2504+
"dist.integrity",
2505+
"dist.shasum",
2506+
"openclaw",
2507+
"--json",
2508+
]);
2509+
expectRecordFields(result.outcomes[0], {
2510+
pluginId: "demo",
2511+
status: "unchanged",
2512+
currentVersion: "1.2.3",
2513+
nextVersion: "1.2.3",
2514+
message: `demo is pinned to ${spec} (installed 1.2.3); registry default resolves to 1.2.4. Pass \`openclaw plugins update @acme/demo@latest\` to follow the registry default line.`,
2515+
});
2516+
},
2517+
);
2518+
24632519
it("updates disabled trusted official ClawHub installs through the catalog spec", async () => {
24642520
installPluginFromClawHubMock.mockResolvedValue(
24652521
createSuccessfulClawHubUpdateResult({

‎src/plugins/update.ts‎

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,38 @@ function compareNpmSemverForUpdate(left: string, right: string): number {
400400
return compareComparableSemver(parseComparableSemver(left), parseComparableSemver(right)) ?? 0;
401401
}
402402

403+
async function resolveNewerExactPinnedNpmDefaultLine(params: {
404+
currentVersion: string | undefined;
405+
effectiveSpec: string | undefined;
406+
probeNpmVersion: string | undefined;
407+
timeoutMs?: number;
408+
}): Promise<{ packageName: string; version: string } | undefined> {
409+
if (!params.currentVersion || !params.probeNpmVersion || !params.effectiveSpec) {
410+
return undefined;
411+
}
412+
const packageName = resolveNpmSpecPackageName(params.effectiveSpec);
413+
const exactVersion = resolveExactNpmSpecVersion(params.effectiveSpec);
414+
const probeNpmVersion = normalizeExactNpmVersion(params.probeNpmVersion);
415+
if (!packageName || !exactVersion || probeNpmVersion !== exactVersion) {
416+
return undefined;
417+
}
418+
419+
const metadataResult = await resolveNpmSpecMetadata({
420+
spec: packageName,
421+
timeoutMs: params.timeoutMs,
422+
}).catch(() => undefined);
423+
if (
424+
!metadataResult?.ok ||
425+
metadataResult.metadata.name !== packageName ||
426+
!metadataResult.metadata.version
427+
) {
428+
return undefined;
429+
}
430+
return compareNpmSemverForUpdate(metadataResult.metadata.version, params.currentVersion) > 0
431+
? { packageName, version: metadataResult.metadata.version }
432+
: undefined;
433+
}
434+
403435
async function loadNpmPackageVersionsForUpdate(params: {
404436
packageName: string;
405437
timeoutMs?: number;
@@ -876,7 +908,20 @@ function resolveNpmSpecPackageName(spec: string | undefined): string | undefined
876908

877909
function resolveExactNpmSpecVersion(spec: string | undefined): string | undefined {
878910
const parsed = spec ? parseRegistryNpmSpec(spec) : null;
879-
return parsed?.selectorKind === "exact-version" ? parsed.selector : undefined;
911+
return parsed?.selectorKind === "exact-version"
912+
? normalizeExactNpmVersion(parsed.selector)
913+
: undefined;
914+
}
915+
916+
function normalizeExactNpmVersion(value: string | undefined): string | undefined {
917+
if (!value) {
918+
return undefined;
919+
}
920+
const trimmed = value.trim();
921+
if (!isExactSemverVersion(trimmed)) {
922+
return undefined;
923+
}
924+
return trimmed.startsWith("v") ? trimmed.slice(1) : trimmed;
880925
}
881926

882927
function resolveNpmResultVersion(result: {
@@ -1950,13 +1995,32 @@ export async function updateNpmInstalledPlugins(params: {
19501995
: Boolean(
19511996
currentVersion && resolvedProbeVersion && currentVersion === resolvedProbeVersion,
19521997
);
1998+
const newerExactPinnedDefaultLine =
1999+
unchanged &&
2000+
record.source === "npm" &&
2001+
!params.specOverrides?.[pluginId] &&
2002+
!officialNpmSpec
2003+
? await resolveNewerExactPinnedNpmDefaultLine({
2004+
currentVersion,
2005+
effectiveSpec,
2006+
probeNpmVersion: npmProbeVersion,
2007+
timeoutMs: params.timeoutMs,
2008+
})
2009+
: undefined;
19532010
if (unchanged) {
2011+
const message =
2012+
newerExactPinnedDefaultLine && effectiveSpec
2013+
? `${pluginId} is pinned to ${effectiveSpec} (installed ${currentLabel}); ` +
2014+
`registry default resolves to ${newerExactPinnedDefaultLine.version}. ` +
2015+
`Pass \`openclaw plugins update ${newerExactPinnedDefaultLine.packageName}@latest\` to follow the registry default line.` +
2016+
channelFallbackSuffix
2017+
: `${pluginId} is up to date (${currentLabel}).${channelFallbackSuffix}`;
19542018
outcomes.push({
19552019
pluginId,
19562020
status: "unchanged",
19572021
currentVersion: currentVersion ?? undefined,
19582022
nextVersion: resolvedProbeVersion,
1959-
message: `${pluginId} is up to date (${currentLabel}).${channelFallbackSuffix}`,
2023+
message,
19602024
...(npmChannelFallback ? { channelFallback: npmChannelFallback } : {}),
19612025
});
19622026
} else {

0 commit comments

Comments
 (0)