@@ -64,9 +64,16 @@ const IDENTITY = Object.freeze({
6464 clientInstanceId : 'desktop-client-secret' ,
6565} ) ;
6666
67- test ( 'cancels pending managed admission and retries with the canonical provider identity' , async ( ) => {
67+ test ( 'cancels managed approval owners and joiners with the canonical provider identity' , async ( ) => {
6868 await withStore ( async ( { store } ) => {
6969 const order : string [ ] = [ ] ;
70+ const toolCallByInvocation = new Map < string , string > ( ) ;
71+ const cancelledToolCalls : string [ ] = [ ] ;
72+ let acceptedCount = 0 ;
73+ let resolveThirdAccepted ! : ( ) => void ;
74+ const thirdAccepted = new Promise < void > ( ( resolve ) => {
75+ resolveThirdAccepted = resolve ;
76+ } ) ;
7077 const interactions = createInteractionCoordinator ( store ) ;
7178 const runOwner = interactions . bindRun ( RUN ) ;
7279 const capabilities = new HostClientCapabilityCoordinator ( {
@@ -79,7 +86,10 @@ test('cancels pending managed admission and retries with the canonical provider
7986 connection = capabilities . attachConnection ( IDENTITY , {
8087 send : async ( frame ) => {
8188 if ( frame . kind === 'client.capability.call' ) {
89+ toolCallByInvocation . set ( frame . invocationId , frame . toolCallId ) ;
8290 order . push ( 'accepted' ) ;
91+ acceptedCount += 1 ;
92+ if ( acceptedCount === 3 ) resolveThirdAccepted ( ) ;
8393 connection . accept ( {
8494 kind : 'client.capability.accepted' ,
8595 invocationId : frame . invocationId ,
@@ -88,6 +98,9 @@ test('cancels pending managed admission and retries with the canonical provider
8898 url : 'https://example.com/private?token=secret' ,
8999 } ,
90100 } ) ;
101+ } else if ( frame . kind === 'client.capability.cancel' ) {
102+ const toolCallId = toolCallByInvocation . get ( frame . invocationId ) ;
103+ if ( toolCallId ) cancelledToolCalls . push ( toolCallId ) ;
91104 } else if ( frame . kind === 'client.capability.admitted' ) {
92105 order . push ( 'admitted' ) ;
93106 connection . accept ( {
@@ -202,6 +215,31 @@ test('cancels pending managed admission and retries with the canonical provider
202215 assert . equal ( retryRequest . request . kind , 'client_capability' ) ;
203216 if ( retryRequest . request . kind !== 'client_capability' ) return ;
204217
218+ const joinedCaller = new AbortController ( ) ;
219+ const joined = runtime . settleToolCall ( {
220+ tool,
221+ turnId : RUN . turnId ,
222+ stepId : 'step-3' ,
223+ toolCallId : 'browser-call-3' ,
224+ input : { } ,
225+ abortSignal : joinedCaller . signal ,
226+ eventSink : {
227+ push : ( ) => undefined ,
228+ pushAndWaitUntilConsumed : async ( ) => undefined ,
229+ } ,
230+ } ) ;
231+ await thirdAccepted ;
232+ assert . deepEqual (
233+ ( await store . listSessionPending ( RUN . sessionId ) ) . map ( ( pending ) => pending . requestId ) ,
234+ [ retryRequest . requestId ] ,
235+ ) ;
236+
237+ joinedCaller . abort ( new DOMException ( 'Joined caller stopped' , 'AbortError' ) ) ;
238+ await joined ;
239+ assert . deepEqual ( cancelledToolCalls , [ 'browser-call-1' , 'browser-call-3' ] ) ;
240+ assert . deepEqual ( order , [ 'accepted' , 'accepted' , 'accepted' ] ) ;
241+ assert . equal ( ( await store . readInteraction ( retryRequest . requestId ) ) ?. outcome , undefined ) ;
242+
205243 const answered = await interactions . handlers [ 'interaction.answer' ] (
206244 {
207245 sessionId : RUN . sessionId ,
@@ -219,7 +257,7 @@ test('cancels pending managed admission and retries with the canonical provider
219257 } ) ;
220258 assert . equal ( grant ?. providerId , providerId ) ;
221259 assert . deepEqual ( settlement . result , { content : [ { type : 'text' , text : 'snapshot' } ] } ) ;
222- assert . deepEqual ( order , [ 'accepted' , 'accepted' , 'approved' , 'T1' , 'admitted' ] ) ;
260+ assert . deepEqual ( order , [ 'accepted' , 'accepted' , 'accepted' , ' approved', 'T1' , 'admitted' ] ) ;
223261 } finally {
224262 snapshot ?. release ( ) ;
225263 await connection . close ( ) ;
0 commit comments