diff --git a/packages/cli/src/cli.lifecycle.test.ts b/packages/cli/src/cli.lifecycle.test.ts index ac38f55ce1..a89f3242f9 100644 --- a/packages/cli/src/cli.lifecycle.test.ts +++ b/packages/cli/src/cli.lifecycle.test.ts @@ -366,7 +366,7 @@ describe("CLI lifecycle", () => { } }); - it("still scores an EPIPE before the artifact is validated as a failure", async () => { + it("exits 1 and scores a failure when the pipe closes before the run delivered", async () => { const trackCommandResult = vi.fn(); const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => undefined) as never); try { @@ -376,7 +376,8 @@ describe("CLI lifecycle", () => { process.argv = ["node", "cli.ts", "init", "--json"]; await import("./cli.js"); - expect(exitSpy).toHaveBeenCalledWith(0); + // `hyperframes render … | head -1` on a refused render exited 0 (CLI 0.9.11) + expect(exitSpy).toHaveBeenCalledWith(1); expect(trackCommandResult).toHaveBeenCalledWith(expect.objectContaining({ success: false })); } finally { exitSpy.mockRestore(); diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 437c705e07..32c4271768 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -7,7 +7,7 @@ // the process. This is a normal lifecycle event — suppress it. // // commandFailed must be declared here (before the handlers) so the EPIPE -// stream-error path can set it before process.exit(0). The telemetry exit +// stream-error path can set it before it exits. The telemetry exit // handler reads this flag to determine success/failure — an EPIPE that // interrupts a command should NOT score as success:true, but one that // arrives after the render artifact was validated is the normal agent-pipe @@ -461,17 +461,13 @@ function exitAfterPostRenderTermination( process.exit(0); } -// A closed pipe (EPIPE) is the NORMAL teardown when the CLI runs under a -// piped agent (Claude Code, Codex, …) — the reader may stop consuming as -// soon as it has what it needs. Exit cleanly, but only score the run as a -// failure when the pipe died BEFORE the render artifact was validated: -// unconditionally setting `commandFailed = true` here marked every piped -// successful render as success:false (0.7.65–0.7.90). Delivery of anything -// still queued (render_complete's eager flush() dies with the process) is -// owned by the unconditional flushSync() in the `exit` handler below. +// A closed pipe (EPIPE) is the normal teardown under a piped agent: exit without a crash. A run that had not delivered +// (a refused or interrupted render) still exits 1, so `| head` cannot turn a failure into success. +// The `exit` handler's flushSync() delivers anything still queued. function handleStreamEpipe(): never { - if (!isRunDelivered()) commandFailed = true; - process.exit(0); + const delivered = isRunDelivered(); + if (!delivered) commandFailed = true; + process.exit(delivered ? 0 : 1); } // Success gate for the cli_command_result telemetry field. `commandFailed`