Skip to content

Commit 446ce98

Browse files
author
macmini
committed
fix(plugins): limit core drift hint to stale lockstep pins
1 parent b9559de commit 446ce98

4 files changed

Lines changed: 135 additions & 7 deletions

File tree

‎src/plugins/official-external-install-records.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ function resolveNpmSpecPackageName(spec: string | undefined): string | undefined
1212
return spec ? parseRegistryNpmSpec(spec)?.name : undefined;
1313
}
1414

15+
/** Official catalog npm specs without an exact version follow the OpenClaw release line. */
16+
export function isOfficialNpmSpecVersionLockstep(spec: string | undefined): boolean {
17+
return Boolean(spec && parseRegistryNpmSpec(spec)?.selectorKind !== "exact-version");
18+
}
19+
1520
function resolveClawHubSpecPackageName(spec: string | undefined): string | undefined {
1621
return spec ? parseClawHubPluginSpec(spec)?.name : undefined;
1722
}

‎src/plugins/plugin-version-drift.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { parseClawHubPluginSpec } from "../infra/clawhub-spec.js";
55
import { parseRegistryNpmSpec } from "../infra/npm-registry-spec.js";
66
import { normalizePluginsConfig, resolveEffectiveEnableState } from "./config-state.js";
77
import {
8+
isOfficialNpmSpecVersionLockstep,
89
resolveTrustedSourceLinkedOfficialClawHubInstall,
910
resolveTrustedSourceLinkedOfficialNpmSpec,
1011
} from "./official-external-install-records.js";
@@ -71,7 +72,7 @@ function shouldCompareOfficialInstallToGateway(params: {
7172
}): boolean {
7273
const officialNpmSpec = resolveTrustedSourceLinkedOfficialNpmSpec(params);
7374
if (officialNpmSpec) {
74-
return parseRegistryNpmSpec(officialNpmSpec)?.selectorKind !== "exact-version";
75+
return isOfficialNpmSpecVersionLockstep(officialNpmSpec);
7576
}
7677
const officialClawHubInstall = resolveTrustedSourceLinkedOfficialClawHubInstall(params);
7778
if (officialClawHubInstall) {

‎src/plugins/update.test.ts‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,62 @@ describe("updateNpmInstalledPlugins", () => {
16371637
]);
16381638
});
16391639

1640+
it.each([
1641+
{
1642+
caseName: "independently versioned official catalog plugins",
1643+
pluginId: "openclaw-plugin-yuanbao",
1644+
packageName: "openclaw-plugin-yuanbao",
1645+
version: "2.15.0",
1646+
coreVersion: "2026.7.1-beta.5",
1647+
},
1648+
{
1649+
caseName: "newer lockstep exact pins",
1650+
pluginId: "codex",
1651+
packageName: "@openclaw/codex",
1652+
version: "2026.8.1",
1653+
coreVersion: "2026.7.1-beta.5",
1654+
},
1655+
])("keeps the normal up-to-date message for $caseName", async (fixture) => {
1656+
const installPath = createInstalledPackageDir({
1657+
name: fixture.packageName,
1658+
version: fixture.version,
1659+
});
1660+
fs.mkdirSync(path.join(installPath, "node_modules", "openclaw"), { recursive: true });
1661+
mockNpmViewMetadata({
1662+
name: fixture.packageName,
1663+
version: fixture.version,
1664+
integrity: "sha512-same",
1665+
shasum: "same",
1666+
});
1667+
installPluginFromNpmSpecMock.mockRejectedValue(new Error("installer should not run"));
1668+
1669+
const result = await updateNpmInstalledPlugins({
1670+
config: createNpmInstallConfig({
1671+
pluginId: fixture.pluginId,
1672+
spec: `${fixture.packageName}@${fixture.version}`,
1673+
installPath,
1674+
resolvedName: fixture.packageName,
1675+
resolvedVersion: fixture.version,
1676+
resolvedSpec: `${fixture.packageName}@${fixture.version}`,
1677+
integrity: "sha512-same",
1678+
shasum: "same",
1679+
}),
1680+
pluginIds: [fixture.pluginId],
1681+
coreVersion: fixture.coreVersion,
1682+
});
1683+
1684+
expect(installPluginFromNpmSpecMock).not.toHaveBeenCalled();
1685+
expect(result.outcomes).toEqual([
1686+
{
1687+
pluginId: fixture.pluginId,
1688+
status: "unchanged",
1689+
currentVersion: fixture.version,
1690+
nextVersion: fixture.version,
1691+
message: `${fixture.pluginId} is up to date (${fixture.version}).`,
1692+
},
1693+
]);
1694+
});
1695+
16401696
it("repairs openclaw peer links after batch npm updates prune earlier plugin links", async () => {
16411697
const plugins = [
16421698
{ pluginId: "brave", packageName: "@openclaw/brave-plugin" },
@@ -2393,6 +2449,63 @@ describe("updateNpmInstalledPlugins", () => {
23932449
});
23942450
});
23952451

2452+
it.each([
2453+
{
2454+
caseName: "independently versioned official catalog plugins",
2455+
pluginId: "openclaw-plugin-yuanbao",
2456+
packageName: "openclaw-plugin-yuanbao",
2457+
version: "2.15.0",
2458+
coreVersion: "2026.7.1-beta.5",
2459+
},
2460+
{
2461+
caseName: "newer lockstep exact pins",
2462+
pluginId: "codex",
2463+
packageName: "@openclaw/codex",
2464+
version: "2026.8.1",
2465+
coreVersion: "2026.7.1-beta.5",
2466+
},
2467+
])("keeps the dry-run up-to-date message for $caseName", async (fixture) => {
2468+
const installPath = createInstalledPackageDir({
2469+
name: fixture.packageName,
2470+
version: fixture.version,
2471+
});
2472+
installPluginFromNpmSpecMock.mockResolvedValue(
2473+
createSuccessfulNpmUpdateResult({
2474+
pluginId: fixture.pluginId,
2475+
targetDir: installPath,
2476+
version: fixture.version,
2477+
npmResolution: {
2478+
name: fixture.packageName,
2479+
version: fixture.version,
2480+
resolvedSpec: `${fixture.packageName}@${fixture.version}`,
2481+
},
2482+
}),
2483+
);
2484+
2485+
const result = await updateNpmInstalledPlugins({
2486+
config: createNpmInstallConfig({
2487+
pluginId: fixture.pluginId,
2488+
spec: `${fixture.packageName}@${fixture.version}`,
2489+
installPath,
2490+
resolvedName: fixture.packageName,
2491+
resolvedSpec: `${fixture.packageName}@${fixture.version}`,
2492+
resolvedVersion: fixture.version,
2493+
}),
2494+
pluginIds: [fixture.pluginId],
2495+
dryRun: true,
2496+
coreVersion: fixture.coreVersion,
2497+
});
2498+
2499+
expect(runCommandWithTimeoutMock).toHaveBeenCalledTimes(1);
2500+
expectRecordFields(result.outcomes[0], {
2501+
pluginId: fixture.pluginId,
2502+
status: "unchanged",
2503+
currentVersion: fixture.version,
2504+
nextVersion: fixture.version,
2505+
message: `${fixture.pluginId} is up to date (${fixture.version}).`,
2506+
});
2507+
});
2508+
23962509
it("reinstalls missing exact official npm pins without official install sync", async () => {
23972510
const extensionsDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-missing-plugin-"));
23982511
tempDirs.push(extensionsDir);

‎src/plugins/update.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import {
6060
import { installPluginFromMarketplace } from "./marketplace.js";
6161
import { checkMinHostVersion } from "./min-host-version.js";
6262
import {
63+
isOfficialNpmSpecVersionLockstep,
6364
resolveTrustedSourceLinkedOfficialClawHubSpec,
6465
resolveTrustedSourceLinkedOfficialNpmSpec,
6566
} from "./official-external-install-records.js";
@@ -437,28 +438,36 @@ function resolveOfficialCoreVersionDriftMessage(params: {
437438
currentVersion: string | undefined;
438439
coreVersion: string | undefined;
439440
record: PluginInstallRecord;
440-
officialPackageName: string | undefined;
441+
trustedOfficialNpmSpec: string | undefined;
441442
specOverride: string | undefined;
442443
syncOfficialPluginInstalls: boolean | undefined;
443444
}): string | undefined {
444445
if (
445446
params.record.source !== "npm" ||
446447
params.specOverride ||
447448
params.syncOfficialPluginInstalls ||
448-
!params.officialPackageName
449+
!isOfficialNpmSpecVersionLockstep(params.trustedOfficialNpmSpec)
449450
) {
450451
return undefined;
451452
}
453+
const officialPackageName = resolveNpmSpecPackageName(params.trustedOfficialNpmSpec);
452454
const pinnedVersion = resolveExactNpmSpecVersion(params.record.spec);
453455
const currentVersion = normalizeExactNpmVersion(params.currentVersion);
454456
const coreVersion = normalizeExactNpmVersion(params.coreVersion);
455-
if (!pinnedVersion || !currentVersion || !coreVersion || currentVersion === coreVersion) {
457+
if (
458+
!officialPackageName ||
459+
!pinnedVersion ||
460+
!currentVersion ||
461+
!coreVersion ||
462+
pinnedVersion !== currentVersion ||
463+
compareNpmSemverForUpdate(pinnedVersion, coreVersion) >= 0
464+
) {
456465
return undefined;
457466
}
458-
if (resolveNpmSpecPackageName(params.record.spec) !== params.officialPackageName) {
467+
if (resolveNpmSpecPackageName(params.record.spec) !== officialPackageName) {
459468
return undefined;
460469
}
461-
const exactTarget = `${params.officialPackageName}@${coreVersion}`;
470+
const exactTarget = `${officialPackageName}@${coreVersion}`;
462471
if (parseRegistryNpmSpec(exactTarget)?.selectorKind !== "exact-version") {
463472
return undefined;
464473
}
@@ -1702,7 +1711,7 @@ export async function updateNpmInstalledPlugins(params: {
17021711
currentVersion,
17031712
coreVersion: params.coreVersion,
17041713
record,
1705-
officialPackageName: officialNpmPackageName,
1714+
trustedOfficialNpmSpec,
17061715
specOverride: params.specOverrides?.[pluginId],
17071716
syncOfficialPluginInstalls: params.syncOfficialPluginInstalls,
17081717
});

0 commit comments

Comments
 (0)