test(windows): eliminate final coverage races
This commit is contained in:
@@ -911,16 +911,17 @@ describe('E2B subprocess terminal service', () => {
|
||||
|
||||
it('contains a failed automatic terminal release until service disposal retries it', async () => {
|
||||
const { fiber, fake } = await service()
|
||||
fake.clearOnTerm = false
|
||||
fake.clearOnKill = false
|
||||
const terminal = await (fiber.ctx).subprocess.spawnTerminal(spec({ graceMs: 1 }))
|
||||
fake.groups = []
|
||||
const terminal = await (fiber.ctx).subprocess.spawnTerminal(spec())
|
||||
const terminate = vi.spyOn(terminal, 'terminate')
|
||||
.mockRejectedValueOnce(new Error('automatic release failed'))
|
||||
fake.handle.succeed(0)
|
||||
await terminal.done
|
||||
await new Promise(resolve => setTimeout(resolve, 10))
|
||||
expect(fake.commands).toContain('kill -KILL -- -123')
|
||||
await vi.waitFor(() => { expect(terminate).toHaveBeenCalledTimes(1) })
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
fake.groups = []
|
||||
await fiber.dispose()
|
||||
await expect(terminal.terminate()).resolves.toBeUndefined()
|
||||
expect(terminate).toHaveBeenCalledTimes(2)
|
||||
expect(fake.handle.disconnects).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -275,10 +275,28 @@ describe('draft-provider model discovery', () => {
|
||||
it('reports cancellation during the body read as an abort, not a raw reason', async () => {
|
||||
const ctx = await harness()
|
||||
const controller = new AbortController()
|
||||
// Chunked, so the headers arrive and the cancellation lands mid-body.
|
||||
const slow = await listingServer({ chunks: ['{"data":[', '{"id":"a"}'], holdOpenMs: 400 })
|
||||
const probe = ctx.llm.discoverModels('llm-pi-ai', { baseURL: slow.url, signal: controller.signal })
|
||||
setTimeout(() => { controller.abort('test cancellation') }, 40)
|
||||
const bodyRead = Promise.withResolvers<undefined>()
|
||||
vi.stubGlobal('fetch', async (_url: string | URL, init?: RequestInit) => {
|
||||
const signal = init?.signal
|
||||
if (signal === undefined || signal === null) throw new Error('expected a discovery signal')
|
||||
return new Response(new ReadableStream<Uint8Array>({
|
||||
pull(stream) {
|
||||
bodyRead.resolve(undefined)
|
||||
return new Promise<void>((resolve) => {
|
||||
signal.addEventListener('abort', () => {
|
||||
stream.error(signal.reason)
|
||||
resolve()
|
||||
}, { once: true })
|
||||
})
|
||||
},
|
||||
}))
|
||||
})
|
||||
const probe = ctx.llm.discoverModels('llm-pi-ai', {
|
||||
baseURL: 'https://slow.example/v1',
|
||||
signal: controller.signal,
|
||||
})
|
||||
await bodyRead.promise
|
||||
controller.abort('test cancellation')
|
||||
|
||||
await expect(probe).rejects.toMatchObject({ code: 'ABORTED' })
|
||||
})
|
||||
|
||||
@@ -95,6 +95,7 @@ type StubMode =
|
||||
| 'spawn-error'
|
||||
| 'send-error'
|
||||
| 'prompt-after-idle'
|
||||
| 'incremental-fallback'
|
||||
| 'empty-page-after-latest'
|
||||
| 'paged-scrollback'
|
||||
|
||||
@@ -166,6 +167,10 @@ class StubPtySession implements PtyBackendSession {
|
||||
this.pendingText = ''
|
||||
const start = /__DSH_PERSISTENT_BASH_START_[^_]+(?:-[^_]+)*__/.exec(sent)?.[0]
|
||||
const end = /__DSH_PERSISTENT_BASH_END_[^:]+:/.exec(sent)?.[0]
|
||||
if (this.mode === 'incremental-fallback') {
|
||||
const incremental = `${start ?? ''}\nincrement\n${this.motd}`
|
||||
return this.operation(Promise.resolve(this.result(this.motd, 'stdin_read')), incremental)
|
||||
}
|
||||
if (this.mode === 'torn-status') {
|
||||
const output = `${start ?? ''}\nhello from stub\n${end ?? ''}`
|
||||
this.scrollback += output
|
||||
@@ -251,10 +256,10 @@ class StubPtySession implements PtyBackendSession {
|
||||
return { viewport, waitReason, sessionStatus: this.statusValue, truncated: false }
|
||||
}
|
||||
|
||||
private operation(done: Promise<ReturnType<StubPtySession['result']>>): PtySendOperation {
|
||||
private operation(done: Promise<ReturnType<StubPtySession['result']>>, delta = ''): PtySendOperation {
|
||||
return {
|
||||
done,
|
||||
readOutput: () => ({ delta: '', truncated: false }),
|
||||
readOutput: () => ({ delta, truncated: false }),
|
||||
cancel: () => false,
|
||||
}
|
||||
}
|
||||
@@ -331,6 +336,10 @@ describe('tool-bash-persistent', () => {
|
||||
session.mode = 'idle-then-normal'
|
||||
expect(text(await call(ctx, owner, 'silent then complete'))).toContain('hello from')
|
||||
|
||||
session.mode = 'incremental-fallback'
|
||||
session.scrollback = ''
|
||||
expect(text(await call(ctx, owner, 'incremental fallback'))).toBe('increment')
|
||||
|
||||
session.mode = 'prompt-only'
|
||||
const promptFallback = text(await call(ctx, owner, 'bad {'))
|
||||
expect(promptFallback).toContain('bash: synt')
|
||||
|
||||
Reference in New Issue
Block a user