From fd731d7386a92d4bc3db943bf6f06cb3519e2722 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 24 Sep 2026 10:53:58 -0400 Subject: [PATCH] fix(e2e-harness): exit tui-snapshots with the host's exit code TuiCapture.exited resolved without the child's exit code, and tui-snapshots always exited 0, so a host crash or an aborted run still passed the sweep. `exited` now resolves with the exit code, or 128 + signal when a signal ended the host, and tui-snapshots exits with it. Part of #1333 Generated-By: PostHog Desktop Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589 --- e2e-harness/__tests__/tui-capture.test.ts | 20 ++++++++++++++++++++ e2e-harness/tui-capture.ts | 12 +++++++----- scripts/tui-snapshots.no-jest.ts | 6 +++--- 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 e2e-harness/__tests__/tui-capture.test.ts diff --git a/e2e-harness/__tests__/tui-capture.test.ts b/e2e-harness/__tests__/tui-capture.test.ts new file mode 100644 index 000000000..b67bf88b6 --- /dev/null +++ b/e2e-harness/__tests__/tui-capture.test.ts @@ -0,0 +1,20 @@ +import { captureTui } from '../tui-capture'; + +const run = (script: string) => + captureTui({ + cmd: process.execPath, + args: ['-e', script], + cwd: process.cwd(), + env: process.env, + }).exited; + +describe('captureTui', () => { + it('resolves exited with the child exit code', async () => { + expect(await run('process.exit(0)')).toBe(0); + expect(await run('process.exit(3)')).toBe(3); + }); + + it('resolves exited with 128 + signal when a signal ends the child', async () => { + expect(await run("process.kill(process.pid, 'SIGTERM')")).toBe(143); + }); +}); diff --git a/e2e-harness/tui-capture.ts b/e2e-harness/tui-capture.ts index 2df7bafd8..e252f9d52 100644 --- a/e2e-harness/tui-capture.ts +++ b/e2e-harness/tui-capture.ts @@ -43,8 +43,8 @@ export interface TuiCapture { /** Fires after each chunk of terminal output is applied. */ onData(cb: () => void): void; kill(): void; - /** Resolves when the child exits. */ - exited: Promise; + /** Resolves with the child's exit code, or 128 + signal, when it exits. */ + exited: Promise; } // Serialize one buffer row back to ANSI: re-emit SGR (colors + attributes) each @@ -118,9 +118,11 @@ export function captureTui(opts: { term.write(d); for (const cb of cbs) cb(); }); - let resolveExit!: () => void; - const exited = new Promise((r) => (resolveExit = r)); - child.onExit(() => resolveExit()); + let resolveExit!: (code: number) => void; + const exited = new Promise((r) => (resolveExit = r)); + child.onExit(({ exitCode, signal }) => + resolveExit(signal ? 128 + signal : exitCode), + ); return { frame() { diff --git a/scripts/tui-snapshots.no-jest.ts b/scripts/tui-snapshots.no-jest.ts index c306fd01e..6d771e85d 100644 --- a/scripts/tui-snapshots.no-jest.ts +++ b/scripts/tui-snapshots.no-jest.ts @@ -52,10 +52,10 @@ async function drainCtrl() { } const timer = setInterval(() => void drainCtrl(), 150); -void cap.exited.then(async () => { +void cap.exited.then(async (code) => { await drainCtrl(); clearInterval(timer); // eslint-disable-next-line no-console - console.log(`done; ${seq} snapshots in ${OUT}`); - process.exit(0); + console.log(`done; ${seq} snapshots in ${OUT}; host exited ${code}`); + process.exit(code); });