mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(cli): a failed run exits 1 when its output pipe closes early (#7158)
* fix(cli): a failed run exits 1 when its output pipe closes early * fix(cli): the EPIPE header comment no longer says it always exits 0
This commit is contained in:
@@ -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();
|
||||
|
||||
+7
-11
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user