diff --git a/packages/commands/src/commands/update.ts b/packages/commands/src/commands/update.ts index 732032e3..3b0d63a3 100644 --- a/packages/commands/src/commands/update.ts +++ b/packages/commands/src/commands/update.ts @@ -19,6 +19,7 @@ import { fetchBinaryChannelVersion, isValidUpdateTargetVersion, normalizeBinaryVersion, + NPM_REGISTRY, performBinaryUpdate, } from "bailian-cli-runtime"; @@ -302,7 +303,9 @@ export default defineCommand({ } } else { const npmSpec = pinnedVersion ? `${npmPackage}@${pinnedVersion}` : `${npmPackage}@latest`; - const command = `npm install -g ${npmSpec}`; + // Detection queries the official registry; install must match, or a stale + // user-configured mirror silently reinstalls the current version. + const command = `npm install -g ${npmSpec} --registry=${NPM_REGISTRY}`; ctx.output.progress({ "en-US": `Updating ${npmPackage} via npm...`, "zh-CN": `正在通过 npm 更新 ${npmPackage}...`, diff --git a/packages/commands/tests/update-binary-skill-sync.test.ts b/packages/commands/tests/update-binary-skill-sync.test.ts index f3dcb79b..aa377fef 100644 --- a/packages/commands/tests/update-binary-skill-sync.test.ts +++ b/packages/commands/tests/update-binary-skill-sync.test.ts @@ -165,10 +165,13 @@ test("npm bl update refreshes installed skills and does not run skill init", asy }) as never, ); - expect(childProcessMocks.spawnSync).toHaveBeenCalledWith("npm install -g bailian-cli@1.15.0", { - shell: true, - stdio: ["inherit", "pipe", "pipe"], - }); + expect(childProcessMocks.spawnSync).toHaveBeenCalledWith( + "npm install -g bailian-cli@1.15.0 --registry=https://registry.npmjs.org", + { + shell: true, + stdio: ["inherit", "pipe", "pipe"], + }, + ); expectSkillUpdateNotInit(); }); diff --git a/packages/runtime/src/utils/update-checker.ts b/packages/runtime/src/utils/update-checker.ts index c64da3f2..afeec02c 100644 --- a/packages/runtime/src/utils/update-checker.ts +++ b/packages/runtime/src/utils/update-checker.ts @@ -248,7 +248,9 @@ export async function performAutoUpdate( "en-US": `Auto-updating: ${currentVersion} → ${latestVersion}`, "zh-CN": `正在自动更新:${currentVersion} → ${latestVersion}`, }); - const command = `npm install -g ${npmPackage}@latest`; + // Version detection reads the official registry; install from the same source + // so a lagging user-configured mirror cannot silently reinstall the old version. + const command = `npm install -g ${npmPackage}@latest --registry=${NPM_REGISTRY}`; try { let newVersion: string | null = null; if (method === "binary") { diff --git a/packages/runtime/tests/update-checker.test.ts b/packages/runtime/tests/update-checker.test.ts index 357a0001..012cf548 100644 --- a/packages/runtime/tests/update-checker.test.ts +++ b/packages/runtime/tests/update-checker.test.ts @@ -224,9 +224,12 @@ test("npm auto-update refreshes installed skills and does not run skill init", a }); expect(updated).toBe(true); - expect(childProcessMocks.execSync).toHaveBeenCalledWith("npm install -g bailian-cli@latest", { - stdio: "pipe", - }); + expect(childProcessMocks.execSync).toHaveBeenCalledWith( + "npm install -g bailian-cli@latest --registry=https://registry.npmjs.org", + { + stdio: "pipe", + }, + ); expectSkillUpdateNotInit(); });