






















@@ -378,4 +378,57 @@ describe("Matrix QA CLI runtime", () => {
378378await rm(root, { force: true, recursive: true });
379379}
380380});
381+382+it("kills ignored-stdio descendants after manual CLI session kill", async () => {
383+if (process.platform === "win32") {
384+return;
385+}
386+const root = await mkdtemp(
387+path.join(resolvePreferredOpenClawTmpDir(), "matrix-qa-cli-session-kill-ignored-stdio-"),
388+);
389+const childPidPath = path.join(root, "child.pid");
390+const grandchildPidPath = path.join(root, "grandchild.pid");
391+let childPid: number | undefined;
392+let grandchildPid: number | undefined;
393+try {
394+await mkdir(path.join(root, "dist"));
395+await writeFile(
396+path.join(root, "dist", "index.mjs"),
397+[
398+"import { spawn } from 'node:child_process';",
399+"import { writeFileSync } from 'node:fs';",
400+`writeFileSync(${JSON.stringify(childPidPath)}, String(process.pid));`,
401+"const grandchild = spawn(process.execPath, ['-e', 'process.on(\\'SIGTERM\\', () => {}); setInterval(() => {}, 1000);'], { stdio: 'ignore' });",
402+"grandchild.unref();",
403+`writeFileSync(${JSON.stringify(grandchildPidPath)}, String(grandchild.pid));`,
404+"process.on('SIGTERM', () => process.exit(0));",
405+"setInterval(() => {}, 1000);",
406+].join("\n"),
407+);
408+409+const session = startMatrixQaOpenClawCli({
410+args: ["matrix", "verify", "self"],
411+cwd: root,
412+env: process.env,
413+timeoutMs: 10_000,
414+});
415+await waitForFile(grandchildPidPath, 2_000);
416+await sleep(300);
417+418+session.kill();
419+await sleep(500);
420+421+childPid = Number(await readFile(childPidPath, "utf8"));
422+grandchildPid = Number(await readFile(grandchildPidPath, "utf8"));
423+expect(isProcessRunning(childPid)).toBe(false);
424+expect(isProcessRunning(grandchildPid)).toBe(false);
425+} finally {
426+for (const pid of [grandchildPid, childPid]) {
427+if (pid && isProcessRunning(pid)) {
428+process.kill(pid, "SIGKILL");
429+}
430+}
431+await rm(root, { force: true, recursive: true });
432+}
433+});
381434});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。