fix(bash): classify signal-terminated background processes

This commit is contained in:
Yichen Jiang
2026-07-10 10:19:54 +08:00
parent f42cd49337
commit 712d481bdf
3 changed files with 23 additions and 4 deletions

View File

@@ -175,10 +175,12 @@ export class LocalBashExecutor extends BashExecutor {
exitCode: null,
signal: null,
done: running.done.then((outcome) => {
// Abort-killed processes report as killed, not completed. Background
// runs forward only the upstream signal (no timeout), so its aborted
// state is the authoritative "was this cancelled" signal.
if (proc.status === 'running') proc.status = spec.signal?.aborted === true ? 'killed' : 'completed'
// Caller-aborted and signal-terminated processes report as killed, not
// completed. The signal check also covers commands that terminate
// themselves without aborting the upstream signal.
if (proc.status === 'running') {
proc.status = spec.signal?.aborted === true || outcome.signal !== null ? 'killed' : 'completed'
}
proc.exitCode = outcome.exitCode
proc.signal = outcome.signal
this.live.delete(proc)

View File

@@ -249,6 +249,15 @@ describe('LocalBashExecutor.start (background process handles)', () => {
expect(proc.signal).toBe('SIGTERM')
})
it('a self-signal exit settles the handle as killed, not completed', async () => {
const { bash } = await setup()
const proc = bash.start(bash.resolve({ command: 'kill -TERM $$' }))
await proc.done
expect(proc.status).toBe('killed')
expect(proc.exitCode).toBeNull()
expect(proc.signal).toBe('SIGTERM')
})
it('a background spawn failure settles as killed with the error readable on stderr', async () => {
const { bash } = await setup()
const proc = bash.start(bash.resolve({ command: 'true', workdir: '/nonexistent-dsh' }))