From 7af8d1b239781584dc801202e3e2033db9d52885 Mon Sep 17 00:00:00 2001 From: mithil Date: Thu, 22 Oct 2026 16:32:15 +0100 Subject: [PATCH] fix: flush grouped output after spawn errors --- lib/output-writer.spec.ts | 18 ++++++++++++++++++ lib/output-writer.ts | 3 +-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/output-writer.spec.ts b/lib/output-writer.spec.ts index b2b27f6c..93b8dbc0 100644 --- a/lib/output-writer.spec.ts +++ b/lib/output-writer.spec.ts @@ -108,5 +108,23 @@ describe('#write()', () => { expect(outputStream.write).toHaveBeenCalledExactlyOnceWith('hello'); expect(writer.activeCommandIndex).toBe(2); }); + + it('flushes later commands after a buffered command failed to spawn', () => { + const writer = createWriter({ group: true }); + writer.write(commands[1], 'spawn error'); + writer.write(commands[2], 'later output'); + commands[1].state = 'errored'; + commands[1].close.next( + createFakeCloseEvent({ command: commands[1], index: 1, exitCode: -1 }), + ); + closeCommand(commands[2]); + + expect(outputStream.write).not.toHaveBeenCalled(); + closeCommand(commands[0]); + + expect(outputStream.write.mock.calls).toEqual([['spawn error'], ['later output']]); + expect(writer.buffers).toEqual([[], [], []]); + expect(writer.activeCommandIndex).toBe(2); + }); }); }); diff --git a/lib/output-writer.ts b/lib/output-writer.ts index 26c1b044..91e57785 100644 --- a/lib/output-writer.ts +++ b/lib/output-writer.ts @@ -43,8 +43,7 @@ export class OutputWriter { for (let i = command.index + 1; i < commands.length; i++) { this.activeCommandIndex = i; this.flushBuffer(i); - // TODO: Should errored commands also flush buffer? - if (commands[i].state !== 'exited') { + if (commands[i].state !== 'exited' && commands[i].state !== 'errored') { break; } }