@@ -3,12 +3,13 @@ import { spawn, spawnSync, type ChildProcess } from "node:child_process";
|
3 | 3 | import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs"; |
4 | 4 | import { tmpdir } from "node:os"; |
5 | 5 | import path from "node:path"; |
6 | | -import { describe, expect, it } from "vitest"; |
| 6 | +import { describe, expect, it, vi } from "vitest"; |
7 | 7 | import { |
8 | 8 | isRunWithEnvHelpRequest, |
9 | 9 | parseRunWithEnvArgs, |
10 | 10 | resolveForceKillDelayMs, |
11 | 11 | resolveSpawnCommand, |
| 12 | +signalRunWithEnvChild, |
12 | 13 | } from "../../scripts/run-with-env.mjs"; |
13 | 14 | |
14 | 15 | async function waitFor(predicate: () => boolean, label: string, timeoutMs = 3_000): Promise<void> { |
@@ -158,6 +159,31 @@ describe("run-with-env", () => {
|
158 | 159 | ); |
159 | 160 | }); |
160 | 161 | |
| 162 | +it("signals Windows wrapped command trees with taskkill", () => { |
| 163 | +const child = { |
| 164 | +kill: vi.fn(), |
| 165 | +pid: 12345, |
| 166 | +}; |
| 167 | +const runTaskkill = vi.fn(() => ({ error: undefined, status: 0 })); |
| 168 | + |
| 169 | +signalRunWithEnvChild(child, "SIGTERM", { |
| 170 | +platform: "win32", |
| 171 | + runTaskkill, |
| 172 | +}); |
| 173 | +expect(runTaskkill).toHaveBeenNthCalledWith(1, "taskkill", ["/PID", "12345", "/T"], { |
| 174 | +stdio: "ignore", |
| 175 | +}); |
| 176 | + |
| 177 | +signalRunWithEnvChild(child, "SIGKILL", { |
| 178 | +platform: "win32", |
| 179 | + runTaskkill, |
| 180 | +}); |
| 181 | +expect(runTaskkill).toHaveBeenNthCalledWith(2, "taskkill", ["/PID", "12345", "/T", "/F"], { |
| 182 | +stdio: "ignore", |
| 183 | +}); |
| 184 | +expect(child.kill).not.toHaveBeenCalled(); |
| 185 | +}); |
| 186 | + |
161 | 187 | it.runIf(process.platform !== "win32").each(["SIGTERM", "SIGHUP", "SIGINT"] as const)( |
162 | 188 | "forwards parent %s to the wrapped command", |
163 | 189 | async (signal) => { |
|