fix(test): kill SDK package command trees · openclaw/openclaw@7c850bd
vincentkoc
·
2026-06-20
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -47,13 +47,14 @@ function runCommand(
|
47 | 47 | const stderr: string[] = []; |
48 | 48 | const child = spawn(command, args, { |
49 | 49 | cwd: options.cwd, |
| 50 | +detached: process.platform !== "win32", |
50 | 51 | env: options.env ?? createCommandEnv(), |
51 | 52 | shell: options.shell, |
52 | 53 | stdio: ["ignore", "pipe", "pipe"], |
53 | 54 | windowsVerbatimArguments: options.windowsVerbatimArguments, |
54 | 55 | }); |
55 | 56 | const timer = setTimeout(() => { |
56 | | -child.kill("SIGKILL"); |
| 57 | +signalCommandProcess(child, "SIGKILL"); |
57 | 58 | reject( |
58 | 59 | new Error( |
59 | 60 | `command timed out after ${options.timeoutMs ?? COMMAND_TIMEOUT_MS}ms: ${[ |
@@ -88,6 +89,20 @@ function runCommand(
|
88 | 89 | }); |
89 | 90 | } |
90 | 91 | |
| 92 | +function signalCommandProcess(child: ReturnType<typeof spawn>, signal: NodeJS.Signals): void { |
| 93 | +if (process.platform !== "win32" && typeof child.pid === "number") { |
| 94 | +try { |
| 95 | +process.kill(-child.pid, signal); |
| 96 | +return; |
| 97 | +} catch (error) { |
| 98 | +if ((error as NodeJS.ErrnoException).code === "ESRCH") { |
| 99 | +return; |
| 100 | +} |
| 101 | +} |
| 102 | +} |
| 103 | +child.kill(signal); |
| 104 | +} |
| 105 | + |
91 | 106 | function createCommandEnv(): NodeJS.ProcessEnv { |
92 | 107 | return { |
93 | 108 | ...process.env, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。