mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
test(agent-session): await the queued-operation results instead of polling a settled flag
The operation-order cases polled a settled flag and the compact spy with vi.waitFor's 1 s default. Under SQL worker contention the goal or rewind answers after more than a second, so the poll gave up while the operation was still on its way (CI: "expected false to be true", then "closed by quit" from the unhandled result). Await the result itself and a promise the compact stub resolves. With a 30 ms SQL reply delay injected locally plus CPU load, 3 repeats: the old file failed "releases a startup goal" (expected false to be true) and "answers a goal" (compact called 0 times); the awaited version passed all.
This commit is contained in:
+6
-13
@@ -17,8 +17,11 @@ it.each(['goal', 'rewind'] as const)(
|
||||
'answers a %s while an earlier message is queued behind compact',
|
||||
async (operation) => {
|
||||
const { host, dispatch } = hostTestState()
|
||||
const compact = vi.fn(async () => ({ state: 'accepted' as const, providerIdentity: null }))
|
||||
host.deps.adapter.compact = compact
|
||||
const compacting = Promise.withResolvers<void>()
|
||||
host.deps.adapter.compact = vi.fn(async () => {
|
||||
compacting.resolve()
|
||||
return { state: 'accepted' as const, providerIdentity: null }
|
||||
})
|
||||
host.deps.adapter.changeThreadGoal = vi.fn(async () => ({ ok: true as const }))
|
||||
host.deps.adapter.rewindSupport = () => ({ supported: true })
|
||||
await attach()
|
||||
@@ -26,7 +29,7 @@ it.each(['goal', 'rewind'] as const)(
|
||||
expect(
|
||||
await host.send(CALLER, { envelope: envelope('agentSession.send', { body }), body })
|
||||
).toMatchObject({ ok: true })
|
||||
await vi.waitFor(() => expect(compact).toHaveBeenCalledOnce())
|
||||
await compacting.promise
|
||||
const queued = hostTestMessage('After compact')
|
||||
const queuedEnvelope = envelope('agentSession.send', { body: queued })
|
||||
expect(
|
||||
@@ -49,11 +52,6 @@ it.each(['goal', 'rewind'] as const)(
|
||||
itemId,
|
||||
expectedEpoch
|
||||
})
|
||||
let settled = false
|
||||
void result.then(() => {
|
||||
settled = true
|
||||
})
|
||||
await vi.waitFor(() => expect(settled).toBe(true))
|
||||
expect(await result).toMatchObject(
|
||||
operation === 'goal' ? { ok: true } : { ok: false, refusal: { rewindReason: 'busy' } }
|
||||
)
|
||||
@@ -89,11 +87,6 @@ it('releases a startup goal when earlier delivery parks behind compact', async (
|
||||
})
|
||||
await host.collaboratorsForTests().serialize(SESSION, async () => {})
|
||||
opened.resolve({ reportedOptions: { model: '' } })
|
||||
let settled = false
|
||||
void result.then(() => {
|
||||
settled = true
|
||||
})
|
||||
await vi.waitFor(() => expect(settled).toBe(true))
|
||||
expect(await result).toMatchObject({ ok: true })
|
||||
expect(dispatch).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user