diff --git a/packages/paperclip-runner/src/live/private-host-control-wrapper.test.ts b/packages/paperclip-runner/src/live/private-host-control-wrapper.test.ts new file mode 100644 index 00000000000..1e930b296c0 --- /dev/null +++ b/packages/paperclip-runner/src/live/private-host-control-wrapper.test.ts @@ -0,0 +1,23 @@ +import { spawn } from "node:child_process"; +import { fileURLToPath } from "node:url"; +import { expect, it } from "vitest"; + +const wrapper = fileURLToPath(new URL("../../test/support/private-host-control.py", import.meta.url)); + +// The wrapper's forward thread stays blocked reading stdin after the native +// child exits. Normal interpreter shutdown then aborted with SIGABRT, which on +// macOS opened a "Python quit unexpectedly" dialog for every test run. +it.skipIf(process.platform === "win32")("exits cleanly while its stdin is still open", async () => { + const child = spawn("python3", [wrapper, "/bin/sh", "-c", "sleep 0.3"], { + detached: true, stdio: ["pipe", "pipe", "ignore"], + }); + let stdout = ""; + child.stdout.on("data", (chunk: Buffer) => { stdout += chunk.toString("utf8"); }); + const exit = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((resolve) => { + child.on("close", (code, signal) => resolve({ code, signal })); + }); + child.stdin.destroy(); + + expect(exit).toEqual({ code: 0, signal: null }); + expect(stdout).toContain('"fixture": "exited"'); +}, 15_000); diff --git a/packages/paperclip-runner/test/support/private-host-control.py b/packages/paperclip-runner/test/support/private-host-control.py index b24a4b3d763..5dac764d3d0 100644 --- a/packages/paperclip-runner/test/support/private-host-control.py +++ b/packages/paperclip-runner/test/support/private-host-control.py @@ -117,6 +117,7 @@ def main(): if __name__ == "__main__": + status = 0 try: if len(sys.argv) == 5 and sys.argv[1] == "--cleanup": cleanup() @@ -124,4 +125,9 @@ if __name__ == "__main__": main() except Exception: # Do not reflect subprocess arguments, ticket frames, or provider output. - sys.exit(1) + status = 1 + # The forward thread may still be blocked in stdin.readline holding the + # stdin buffer lock. Normal interpreter shutdown would then abort while + # closing stdin (SIGABRT plus a macOS crash dialog), so skip finalization. + # emit() already flushed every receipt. + os._exit(status)