fix(e2b): fence teardown and terminal publication

This commit is contained in:
Tianyi Cui
2026-07-29 07:42:25 +08:00
parent e9bef2967d
commit 022841027f
9 changed files with 237 additions and 22 deletions

View File

@@ -599,6 +599,12 @@ describe('E2BSubprocessHandle', () => {
await expect(handle.waitForExit()).resolves.toBe(true)
expect(fake.commandsSeen).toContain('kill -TERM -- -4242')
expect(fake.commandsSeen).not.toContain('kill -KILL -- -4242')
const signals = fake.commandsSeen.filter(command => command.startsWith('kill -')).length
fake.alive = true
handle.terminate()
await flush()
expect(fake.alive).toBe(true)
expect(fake.commandsSeen.filter(command => command.startsWith('kill -'))).toHaveLength(signals)
})
it('escalates a TERM-trapping process group to KILL and uses the SDK kill as fallback', async () => {
@@ -1123,6 +1129,24 @@ describe('E2BSubprocessService', () => {
expect(fake.alive).toBe(false)
})
it('awaits SDK settlement after the remote process group becomes quiescent', async () => {
const fake = new FakeSandbox()
fake.trapsTerm = true
const { ctx, fiber } = await service(fake)
const handle = ctx.subprocess.spawn(spec())
await flush()
fake.alive = false
let disposed = false
const disposing = fiber.dispose().then(() => { disposed = true })
await flush()
expect(disposed).toBe(false)
fake.finish()
await disposing
await expect(handle.done).resolves.toEqual({ exitCode: 0, signal: null })
})
it('reports a failed termination transaction from disposal instead of waiting on done', async () => {
const fake = new FakeSandbox()
fake.signalErrors.push(new Error('TERM transport failed'), new Error('KILL transport failed'))
@@ -1178,6 +1202,7 @@ describe('E2BSubprocessService', () => {
const { ctx, fiber } = await service(fake)
const handle = ctx.subprocess.spawn(spec())
const disposing = fiber.dispose()
expect(() => ctx.subprocess.spawn(spec())).toThrow('service is disposing')
fake.releaseStart()
await expect(disposing).resolves.toBeUndefined()
await expect(handle.done).rejects.toThrow('start failed during disposal')