

























@@ -13,6 +13,25 @@ vi.mock("node:child_process", async () => {
13131414import { scheduleDetachedLaunchdRestartHandoff } from "./launchd-restart-handoff.js";
151516+type SpawnCall = [string, string[], { env: Record<string, string | undefined> }];
17+18+function requireSpawnCall(callIndex = 0): SpawnCall {
19+const call = spawnMock.mock.calls.at(callIndex);
20+if (!call) {
21+throw new Error(`expected spawn call ${callIndex}`);
22+}
23+const [command, args, options] = call;
24+if (
25+typeof command !== "string" ||
26+!Array.isArray(args) ||
27+!options ||
28+typeof options !== "object"
29+) {
30+throw new Error(`expected spawn call ${callIndex} with command, args, and options`);
31+}
32+return [command, args as string[], options as SpawnCall[2]];
33+}
34+1635afterEach(() => {
1736spawnMock.mockReset();
1837unrefMock.mockReset();
@@ -35,7 +54,7 @@ describe("scheduleDetachedLaunchdRestartHandoff", () => {
35543655expect(result).toEqual({ ok: true, pid: 4242 });
3756expect(spawnMock).toHaveBeenCalledTimes(1);
38-const [, args] = spawnMock.mock.calls[0] as [string, string[]];
57+const [, args] = requireSpawnCall();
3958expect(args[0]).toBe("-c");
4059expect(args[2]).toBe("openclaw-launchd-restart-handoff");
4160expect(args[6]).toBe("9876");
@@ -64,7 +83,7 @@ describe("scheduleDetachedLaunchdRestartHandoff", () => {
6483mode: "start-after-exit",
6584});
668567-const [, args] = spawnMock.mock.calls[0] as [string, string[]];
86+const [, args] = requireSpawnCall();
6887expect(args[7]).toBe("ai.openclaw.gateway");
6988expect(args[1]).toContain('if launchctl print "$service_target" >/dev/null 2>&1; then');
7089expect(args[1]).toContain("reason=launchd-auto-reload");
@@ -89,11 +108,7 @@ describe("scheduleDetachedLaunchdRestartHandoff", () => {
89108mode: "kickstart",
90109});
9111092-const [, args, options] = spawnMock.mock.calls[0] as [
93-string,
94-string[],
95-{ env: Record<string, string | undefined> },
96-];
111+const [, args, options] = requireSpawnCall();
97112expect(args[1]).toContain("exec >>'/Users/test/.openclaw/logs/gateway-restart.log' 2>&1");
98113expect(args[1]).not.toContain("/tmp/evil-bin");
99114expect(args[1]).not.toContain("/tmp/evil.dylib");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。