Skip to content

Commit 554683d

Browse files
committed
test(mothership): await actual tool cancellation completion
1 parent dff1309 commit 554683d

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎apps/sim/lib/mothership/request/handlers/handlers.test.ts‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createDeferred } from '@sim/testing/helpers/deferred'
12
import {
23
mothershipAsyncRunsMock,
34
mothershipAsyncRunsMockFns,
@@ -1529,13 +1530,12 @@ describe('sse-handlers tool lifecycle', () => {
15291530
it('marks an in-flight tool as cancelled when aborted mid-execution', async () => {
15301531
const abortController = new AbortController()
15311532
execContext.abortSignal = abortController.signal
1532-
1533-
executeTool.mockImplementationOnce(
1534-
() =>
1535-
new Promise((resolve) => {
1536-
setTimeout(() => resolve({ success: true, output: { ok: true } }), 0)
1537-
})
1538-
)
1533+
const started = createDeferred<void>()
1534+
const result = createDeferred<{ success: boolean; output: { ok: boolean } }>()
1535+
executeTool.mockImplementationOnce(() => {
1536+
started.resolve()
1537+
return result.promise
1538+
})
15391539

15401540
await sseHandlers.tool(
15411541
{
@@ -1558,8 +1558,12 @@ describe('sse-handlers tool lifecycle', () => {
15581558
}
15591559
)
15601560

1561+
await started.promise
1562+
const pending = context.pendingToolPromises.get('tool-cancel')
1563+
expect(pending).toBeDefined()
15611564
abortController.abort()
1562-
await sleep(10)
1565+
result.resolve({ success: true, output: { ok: true } })
1566+
await pending
15631567

15641568
const updated = context.toolCalls.get('tool-cancel')
15651569
expect(updated?.status).toBe(MothershipStreamV1ToolOutcome.cancelled)

0 commit comments

Comments
 (0)