File tree Expand file tree Collapse file tree
apps/sim/lib/mothership/request/handlers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { createDeferred } from '@sim/testing/helpers/deferred'
12import {
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 )
You can’t perform that action at this time.
0 commit comments