test(daemon): preserve pre-ready crash output

This commit is contained in:
Brennan Benson
2026-08-27 14:52:54 -07:00
parent 7ed70293ee
commit fa80a13d32
2 changed files with 14 additions and 1 deletions
@@ -44,6 +44,20 @@ describe('observeDaemonChildExit', () => {
observer.stop()
})
it('retains fatal stderr that arrives before the independent ready IPC callback', () => {
const child = createChild()
const onExit = vi.fn()
const observer = observeDaemonChildExit(child, onExit)
child.stderr.write('FATAL ERROR before ready dispatch')
observer.markReady()
child.emit('close', 134, null)
expect(onExit).toHaveBeenCalledWith(
expect.objectContaining({ stderrTail: 'FATAL ERROR before ready dispatch' })
)
})
it('stops observing and destroys the startup pipe on launch failure', () => {
const child = createChild()
const destroy = vi.spyOn(child.stderr, 'destroy')
@@ -72,7 +72,6 @@ export function observeDaemonChildExit(
return
}
ready = true
stderrTail = Buffer.alloc(0)
child.stderr?.on('error', onStderrError)
child.stderr?.unref?.()
child.on('close', onClose)