fix(server): stop Windows terminal processes when closing (#10771)

This commit is contained in:
Dara Adedeji authored and GitHub committed 2026-09-08 21:20:48 +05:30
1 parent 061543e9e5
commit 47eed9face
2 files changed
+49 -11

No files matched your search

@@ -21,15 +21,50 @@ const spawn = vi.fn(() => ({
vi.mock("node-pty", () => ({ spawn }));
const testLayer = NodePtyAdapter.layer.pipe(
Layer.provide(
Layer.mergeAll(
NodeServices.layer,
Layer.succeed(HostProcessPlatform, "win32"),
Layer.succeed(HostProcessArchitecture, "x64"),
const makeTestLayer = (platform: NodeJS.Platform = "win32") =>
NodePtyAdapter.layer.pipe(
Layer.provide(
Layer.mergeAll(
NodeServices.layer,
Layer.succeed(HostProcessPlatform, platform),
Layer.succeed(HostProcessArchitecture, "x64"),
),
),
),
);
);
const testLayer = makeTestLayer();
for (const platform of ["win32", "linux", "darwin"] as const) {
it.effect(`terminates through node-pty using ${platform} semantics`, () =>
Effect.gen(function* () {
const adapter = yield* PtyAdapter.PtyAdapter;
const process = yield* adapter.spawn({
shell: "test-shell",
cwd: ".",
cols: 80,
rows: 24,
env: {},
});
const nativeProcess = spawn.mock.results.at(-1)!.value;
nativeProcess.kill.mockImplementation((signal?: string) => {
if (platform === "win32" && signal) {
throw new Error("Signals not supported on windows.");
}
});
process.kill("SIGTERM");
process.kill("SIGKILL");
process.kill();
assert.deepEqual(
nativeProcess.kill.mock.calls,
platform === "win32"
? [[undefined], [undefined], [undefined]]
: [["SIGTERM"], ["SIGKILL"], [undefined]],
);
}).pipe(Effect.provide(makeTestLayer(platform))),
);
}
it.effect("spawns through the public adapter with the provided host references", () =>
Effect.gen(function* () {
+6 -3
View File
@@ -69,9 +69,11 @@ const ensureNodePtySpawnHelperExecutable = Effect.fn(function* () {
class NodePtyProcess implements PtyAdapter.PtyProcess {
private readonly process: import("node-pty").IPty;
private readonly platform: NodeJS.Platform;
constructor(process: import("node-pty").IPty) {
constructor(process: import("node-pty").IPty, platform: NodeJS.Platform) {
this.process = process;
this.platform = platform;
}
get pid(): number {
@@ -87,7 +89,8 @@ class NodePtyProcess implements PtyAdapter.PtyProcess {
}
kill(signal?: string): void {
this.process.kill(signal);
// node-pty terminates the Windows process tree without a POSIX signal.
this.process.kill(this.platform === "win32" ? undefined : signal);
}
onData(callback: (data: string) => void): () => void {
@@ -164,7 +167,7 @@ export const make = Effect.fn("NodePtyAdapter.make")(function* (
cause,
}),
});
return new NodePtyProcess(ptyProcess);
return new NodePtyProcess(ptyProcess, platform);
}),
});
});