

















@@ -6,6 +6,7 @@ import { OpenClawStdioClientTransport } from "./mcp-stdio-transport.js";
6677const spawnMock = vi.hoisted(() => vi.fn());
88const killProcessTreeMock = vi.hoisted(() => vi.fn());
9+const signalProcessTreeMock = vi.hoisted(() => vi.fn());
9101011vi.mock("node:child_process", async () => ({
1112 ...(await vi.importActual<typeof import("node:child_process")>("node:child_process")),
@@ -14,6 +15,7 @@ vi.mock("node:child_process", async () => ({
14151516vi.mock("../process/kill-tree.js", () => ({
1617killProcessTree: killProcessTreeMock,
18+signalProcessTree: signalProcessTreeMock,
1719}));
18201921class MockChildProcess extends EventEmitter {
@@ -29,6 +31,7 @@ describe("OpenClawStdioClientTransport", () => {
2931vi.useRealTimers();
3032spawnMock.mockReset();
3133killProcessTreeMock.mockReset();
34+signalProcessTreeMock.mockReset();
3235});
33363437it("starts stdio MCP servers in a disposable process group on POSIX", async () => {
@@ -88,6 +91,30 @@ describe("OpenClawStdioClientTransport", () => {
8891await closing;
8992});
909394+it("force-SIGKILLs synchronously when killProcessTree's grace expires (#86412)", async () => {
95+vi.useFakeTimers();
96+const child = new MockChildProcess();
97+spawnMock.mockReturnValue(child);
98+99+const transport = new OpenClawStdioClientTransport({ command: "npx" });
100+const started = transport.start();
101+child.emit("spawn");
102+await started;
103+104+const closing = transport.close();
105+await vi.advanceTimersByTimeAsync(2000);
106+expect(killProcessTreeMock).toHaveBeenCalledWith(4321);
107+expect(signalProcessTreeMock).not.toHaveBeenCalled();
108+109+// killProcessTree's SIGKILL is .unref()'d (#86412); close() force-SIGKILLs synchronously instead.
110+await vi.advanceTimersByTimeAsync(2000);
111+expect(signalProcessTreeMock).toHaveBeenCalledWith(4321, "SIGKILL");
112+113+child.exitCode = 0;
114+child.emit("close", 0);
115+await closing;
116+});
117+91118it("does not kill the process tree when graceful stdio close exits", async () => {
92119vi.useFakeTimers();
93120const child = new MockChildProcess();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。