





















@@ -359,12 +359,44 @@ describe("update-cli", () => {
359359return call;
360360};
361361362+const commandCall = (index = 0) => {
363+const calls = vi.mocked(runCommandWithTimeout).mock.calls as unknown as Array<
364+[string[], Record<string, unknown>]
365+>;
366+return calls[index];
367+};
368+369+const spawnCall = (index = 0) => {
370+const calls = spawn.mock.calls as unknown as Array<
371+[string, string[], { env?: NodeJS.ProcessEnv; stdio?: unknown }]
372+>;
373+return calls[index];
374+};
375+376+const spawnSyncCall = (index = 0) => {
377+const calls = vi.mocked(spawnSync).mock.calls as unknown as Array<
378+[string, string[], { env?: NodeJS.ProcessEnv; timeout?: number }]
379+>;
380+return calls[index];
381+};
382+362383const expectPackageInstallSpec = (spec: string) => {
363384expect(runGatewayUpdate).not.toHaveBeenCalled();
364-expect(runCommandWithTimeout).toHaveBeenCalledWith(
365-["npm", "i", "-g", spec, "--no-fund", "--no-audit", "--loglevel=error"],
366-expect.any(Object),
367-);
385+const call = (
386+vi.mocked(runCommandWithTimeout).mock.calls as unknown as Array<
387+[string[], Record<string, unknown>]
388+>
389+).find(([argv]) => argv[0] === "npm" && argv[1] === "i" && argv[2] === "-g");
390+expect(call?.[0]).toEqual([
391+"npm",
392+"i",
393+"-g",
394+spec,
395+"--no-fund",
396+"--no-audit",
397+"--loglevel=error",
398+]);
399+expect(call?.[1]).toBeDefined();
368400};
369401370402const statfsFixture = (params: {
@@ -616,16 +648,11 @@ describe("update-cli", () => {
616648617649await updateCliShared.tryWriteCompletionCache(root, false);
618650619-expect(spawnSync).toHaveBeenCalledWith(
620-expect.any(String),
621-[path.join(root, "openclaw.mjs"), "completion", "--write-state"],
622-expect.objectContaining({
623-env: expect.objectContaining({
624-OPENCLAW_COMPLETION_SKIP_PLUGIN_COMMANDS: "1",
625-}),
626-timeout: 30_000,
627-}),
628-);
651+const call = spawnSyncCall();
652+expect(typeof call?.[0]).toBe("string");
653+expect(call?.[1]).toEqual([path.join(root, "openclaw.mjs"), "completion", "--write-state"]);
654+expect(call?.[2]?.env?.OPENCLAW_COMPLETION_SKIP_PLUGIN_COMMANDS).toBe("1");
655+expect(call?.[2]?.timeout).toBe(30_000);
629656});
630657631658it("refuses mutating updates in Nix mode before update side effects", async () => {
@@ -658,30 +685,23 @@ describe("update-cli", () => {
658685await updateCliShared.tryWriteCompletionCache(root, false);
659686660687const logs = vi.mocked(runtimeCapture.log).mock.calls.map((call) => String(call[0]));
661-expect(logs).toEqual(expect.arrayContaining([expect.stringContaining("timed out after 30s")]));
662-expect(logs).toEqual(
663-expect.arrayContaining([expect.stringContaining("openclaw completion --write-state")]),
664-);
665-expect(logs).not.toEqual(expect.arrayContaining([expect.stringContaining("Error: spawnSync")]));
688+expect(logs.some((line) => line.includes("timed out after 30s"))).toBe(true);
689+expect(logs.some((line) => line.includes("openclaw completion --write-state"))).toBe(true);
690+expect(logs.some((line) => line.includes("Error: spawnSync"))).toBe(false);
666691});
667692668693it("respawns into the updated package root before running post-update tasks", async () => {
669694const { entrypoints } = setupUpdatedRootRefresh();
670695671696await updateCommand({ yes: true, timeout: "1800" });
672697673-expect(spawn).toHaveBeenCalledWith(
674-expect.stringMatching(/node/),
675-[entrypoints[0], "update", "--yes", "--timeout", "1800"],
676-expect.objectContaining({
677-stdio: "inherit",
678-env: expect.objectContaining({
679-NODE_DISABLE_COMPILE_CACHE: "1",
680-OPENCLAW_UPDATE_POST_CORE: "1",
681-OPENCLAW_UPDATE_POST_CORE_CHANNEL: "dev",
682-}),
683-}),
684-);
698+const call = spawnCall();
699+expect(call?.[0]).toMatch(/node/);
700+expect(call?.[1]).toEqual([entrypoints[0], "update", "--yes", "--timeout", "1800"]);
701+expect(call?.[2]?.stdio).toBe("inherit");
702+expect(call?.[2]?.env?.NODE_DISABLE_COMPILE_CACHE).toBe("1");
703+expect(call?.[2]?.env?.OPENCLAW_UPDATE_POST_CORE).toBe("1");
704+expect(call?.[2]?.env?.OPENCLAW_UPDATE_POST_CORE_CHANNEL).toBe("dev");
685705expect(updateNpmInstalledPlugins).not.toHaveBeenCalled();
686706expect(runDaemonInstall).not.toHaveBeenCalled();
687707expect(runDaemonRestart).not.toHaveBeenCalled();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。