

























@@ -1283,6 +1283,76 @@ describe("update-cli", () => {
12831283).not.toContain("already-current");
12841284});
128512851286+it("retries package updates without optional deps when npm global update fails", async () => {
1287+const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-update-optional-"));
1288+const nodeModules = path.join(tempDir, "node_modules");
1289+const pkgRoot = path.join(nodeModules, "openclaw");
1290+mockPackageInstallStatus(pkgRoot);
1291+await fs.mkdir(pkgRoot, { recursive: true });
1292+await fs.writeFile(
1293+path.join(pkgRoot, "package.json"),
1294+JSON.stringify({ name: "openclaw", version: "1.0.0" }),
1295+"utf-8",
1296+);
1297+1298+vi.mocked(runCommandWithTimeout).mockImplementation(async (argv) => {
1299+if (Array.isArray(argv) && argv[0] === "npm" && argv[1] === "root" && argv[2] === "-g") {
1300+return {
1301+stdout: `${nodeModules}\n`,
1302+stderr: "",
1303+code: 0,
1304+signal: null,
1305+killed: false,
1306+termination: "exit",
1307+};
1308+}
1309+if (
1310+Array.isArray(argv) &&
1311+argv[0] === "npm" &&
1312+argv.includes("-g") &&
1313+!argv.includes("--omit=optional")
1314+) {
1315+return {
1316+stdout: "",
1317+stderr: "node-gyp failed",
1318+code: 1,
1319+signal: null,
1320+killed: false,
1321+termination: "exit",
1322+};
1323+}
1324+return {
1325+stdout: "",
1326+stderr: "",
1327+code: 0,
1328+signal: null,
1329+killed: false,
1330+termination: "exit",
1331+};
1332+});
1333+1334+await updateCommand({ yes: true, restart: false });
1335+1336+expect(runCommandWithTimeout).toHaveBeenCalledWith(
1337+["npm", "i", "-g", "openclaw@latest", "--no-fund", "--no-audit", "--loglevel=error"],
1338+expect.any(Object),
1339+);
1340+expect(runCommandWithTimeout).toHaveBeenCalledWith(
1341+[
1342+"npm",
1343+"i",
1344+"-g",
1345+"openclaw@latest",
1346+"--omit=optional",
1347+"--no-fund",
1348+"--no-audit",
1349+"--loglevel=error",
1350+],
1351+expect.any(Object),
1352+);
1353+expect(defaultRuntime.exit).not.toHaveBeenCalledWith(1);
1354+});
1355+12861356it("uses the owning npm binary for package updates when PATH npm points elsewhere", async () => {
12871357const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("darwin");
12881358const brewPrefix = createCaseDir("brew-prefix");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。