Skip to content

Commit a382549

Browse files
authored
Merge pull request #333 from modelstudioai/fix/update-registry-mismatch
fix(update): install from the official npm registry to match version detection
2 parents 84e54dc + 766f695 commit a382549

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎packages/commands/src/commands/update.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
fetchBinaryChannelVersion,
2020
isValidUpdateTargetVersion,
2121
normalizeBinaryVersion,
22+
NPM_REGISTRY,
2223
performBinaryUpdate,
2324
} from "bailian-cli-runtime";
2425

@@ -302,7 +303,9 @@ export default defineCommand({
302303
}
303304
} else {
304305
const npmSpec = pinnedVersion ? `${npmPackage}@${pinnedVersion}` : `${npmPackage}@latest`;
305-
const command = `npm install -g ${npmSpec}`;
306+
// Detection queries the official registry; install must match, or a stale
307+
// user-configured mirror silently reinstalls the current version.
308+
const command = `npm install -g ${npmSpec} --registry=${NPM_REGISTRY}`;
306309
ctx.output.progress({
307310
"en-US": `Updating ${npmPackage} via npm...`,
308311
"zh-CN": `正在通过 npm 更新 ${npmPackage}...`,

‎packages/commands/tests/update-binary-skill-sync.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,13 @@ test("npm bl update refreshes installed skills and does not run skill init", asy
165165
}) as never,
166166
);
167167

168-
expect(childProcessMocks.spawnSync).toHaveBeenCalledWith("npm install -g [email protected]", {
169-
shell: true,
170-
stdio: ["inherit", "pipe", "pipe"],
171-
});
168+
expect(childProcessMocks.spawnSync).toHaveBeenCalledWith(
169+
"npm install -g [email protected] --registry=https://registry.npmjs.org",
170+
{
171+
shell: true,
172+
stdio: ["inherit", "pipe", "pipe"],
173+
},
174+
);
172175
expectSkillUpdateNotInit();
173176
});
174177

‎packages/runtime/src/utils/update-checker.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ export async function performAutoUpdate(
248248
"en-US": `Auto-updating: ${currentVersion} → ${latestVersion}`,
249249
"zh-CN": `正在自动更新:${currentVersion} → ${latestVersion}`,
250250
});
251-
const command = `npm install -g ${npmPackage}@latest`;
251+
// Version detection reads the official registry; install from the same source
252+
// so a lagging user-configured mirror cannot silently reinstall the old version.
253+
const command = `npm install -g ${npmPackage}@latest --registry=${NPM_REGISTRY}`;
252254
try {
253255
let newVersion: string | null = null;
254256
if (method === "binary") {

‎packages/runtime/tests/update-checker.test.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,12 @@ test("npm auto-update refreshes installed skills and does not run skill init", a
224224
});
225225

226226
expect(updated).toBe(true);
227-
expect(childProcessMocks.execSync).toHaveBeenCalledWith("npm install -g bailian-cli@latest", {
228-
stdio: "pipe",
229-
});
227+
expect(childProcessMocks.execSync).toHaveBeenCalledWith(
228+
"npm install -g bailian-cli@latest --registry=https://registry.npmjs.org",
229+
{
230+
stdio: "pipe",
231+
},
232+
);
230233
expectSkillUpdateNotInit();
231234
});
232235

0 commit comments

Comments
 (0)