@@ -357,6 +357,45 @@ describe("AcpMcpOverAcpBridge", () => {
357357 } ) . pipe ( Effect . scoped ) ,
358358 ) ;
359359
360+ it . effect ( "closes the session of an initialize still in flight when disposed" , ( ) =>
361+ Effect . gen ( function * ( ) {
362+ const started = Promise . withResolvers < void > ( ) ;
363+ const respond = Promise . withResolvers < void > ( ) ;
364+ const deleted : Array < string | null > = [ ] ;
365+ const bridge = yield * makeAcpMcpOverAcpBridge ( {
366+ endpoint : "http://127.0.0.1:1/mcp" ,
367+ authorization : "Bearer bridge-test" ,
368+ allocateConnectionId : Effect . succeed ( "connection-1" ) ,
369+ fetchImplementation : async ( _url , init ) => {
370+ if ( init ?. method === "DELETE" ) {
371+ deleted . push ( new Headers ( init . headers ) . get ( "mcp-session-id" ) ) ;
372+ return new Response ( null , { status : 204 } ) ;
373+ }
374+ const request = JSON . parse ( String ( init ?. body ) ) as { readonly id ?: unknown } ;
375+ started . resolve ( ) ;
376+ await respond . promise ;
377+ return new Response (
378+ JSON . stringify ( {
379+ jsonrpc : "2.0" ,
380+ id : request . id ,
381+ result : { protocolVersion : "2025-06-18" } ,
382+ } ) ,
383+ { headers : { "content-type" : "application/json" , "mcp-session-id" : "session-1" } } ,
384+ ) ;
385+ } ,
386+ } ) ;
387+
388+ const initialize = yield * bridge
389+ . message ( { serverId : "t3-code" , requestId : "mcp-1" , method : "initialize" } )
390+ . pipe ( Effect . forkChild ) ;
391+ yield * Effect . promise ( ( ) => started . promise ) ;
392+ yield * bridge . dispose ;
393+ respond . resolve ( ) ;
394+ yield * Fiber . join ( initialize ) ;
395+ expect ( deleted ) . toEqual ( [ "session-1" ] ) ;
396+ } ) . pipe ( Effect . scoped ) ,
397+ ) ;
398+
360399 it . effect ( "closes the session of a replaced initialize even when that initialize fails" , ( ) =>
361400 Effect . gen ( function * ( ) {
362401 const firstStarted = Promise . withResolvers < void > ( ) ;
0 commit comments