fix(pty): drain public signals during close

This commit is contained in:
Tianyi Cui
2026-07-29 13:00:12 +08:00
parent 727546ce6d
commit 045e8462ee
8 changed files with 36 additions and 12 deletions
@@ -952,6 +952,26 @@ describe('LocalPtySession bounds, signals, and teardown', () => {
await expect(session.signal('SIGTERM')).rejects.toThrow('cannot resolve')
})
it('drains an in-flight public signal and rejects signals after close starts', async () => {
const terminal = new FakeTerminal()
const session = new LocalPtySession(terminal, config())
const signal = Promise.withResolvers<number>()
terminal.signalForeground = async () => await signal.promise
const signaling = session.signal('SIGINT')
const closing = session.close('public signal')
let closed = false
void closing.then(() => { closed = true })
await Promise.resolve()
expect(closed).toBe(false)
await expect(session.signal('SIGTERM')).rejects.toThrow('closing')
signal.resolve(456)
await expect(signaling).resolves.toEqual({ delivered: true, targetPgid: 456 })
await closing
expect(closed).toBe(true)
})
it('closes idempotently, contains signal races, and reports survivors', async () => {
const terminal = new FakeTerminal()
terminal.quiescent = false