@@ -293,6 +293,11 @@ describe("AcpMcpOverAcpBridge", () => {
293293 bridge . message ( { serverId : "t3-code" , requestId, method } ) ;
294294
295295 yield * message ( "initialize" , "mcp-1" ) ;
296+ yield * bridge . notification ( {
297+ serverId : "t3-code" ,
298+ requestId : "mcp-n" ,
299+ method : "notifications/initialized" ,
300+ } ) ;
296301 yield * message ( "tools/list" , "mcp-2" ) ;
297302 expect ( yield * message ( "initialize" , "mcp-3" ) ) . toEqual ( {
298303 result : { protocolVersion : "2025-06-18" } ,
@@ -302,6 +307,7 @@ describe("AcpMcpOverAcpBridge", () => {
302307
303308 expect ( requests ) . toEqual ( [
304309 { verb : "POST" , method : "initialize" , sessionId : null } ,
310+ { verb : "POST" , method : "notifications/initialized" , sessionId : "session-1" } ,
305311 { verb : "POST" , method : "tools/list" , sessionId : "session-1" } ,
306312 { verb : "DELETE" , method : undefined , sessionId : "session-1" } ,
307313 { verb : "POST" , method : "initialize" , sessionId : null } ,
@@ -444,95 +450,6 @@ describe("AcpMcpOverAcpBridge", () => {
444450 } ) . pipe ( Effect . scoped ) ,
445451 ) ;
446452
447- it . effect ( "closes the session of an initialize that a newer initialize replaced in flight" , ( ) =>
448- Effect . gen ( function * ( ) {
449- const firstStarted = Promise . withResolvers < void > ( ) ;
450- const firstResponse = Promise . withResolvers < void > ( ) ;
451- const deleted : Array < string | null > = [ ] ;
452- let sessions = 0 ;
453- const bridge = yield * makeAcpMcpOverAcpBridge ( {
454- endpoint : "http://127.0.0.1:1/mcp" ,
455- authorization : "Bearer bridge-test" ,
456- allocateConnectionId : Effect . succeed ( "connection-1" ) ,
457- fetchImplementation : async ( _url , init ) => {
458- if ( init ?. method === "DELETE" ) {
459- deleted . push ( new Headers ( init . headers ) . get ( "mcp-session-id" ) ) ;
460- return new Response ( null , { status : 204 } ) ;
461- }
462- const request = JSON . parse ( String ( init ?. body ) ) as { readonly id ?: unknown } ;
463- const sessionId = `session-${ ++ sessions } ` ;
464- if ( sessionId === "session-1" ) {
465- firstStarted . resolve ( ) ;
466- await firstResponse . promise ;
467- }
468- return new Response (
469- JSON . stringify ( {
470- jsonrpc : "2.0" ,
471- id : request . id ,
472- result : { protocolVersion : "2025-06-18" } ,
473- } ) ,
474- { headers : { "content-type" : "application/json" , "mcp-session-id" : sessionId } } ,
475- ) ;
476- } ,
477- } ) ;
478- const initialize = ( requestId : string ) =>
479- bridge . message ( { serverId : "t3-code" , requestId, method : "initialize" } ) ;
480-
481- const first = yield * initialize ( "mcp-1" ) . pipe ( Effect . forkChild ) ;
482- yield * Effect . promise ( ( ) => firstStarted . promise ) ;
483- yield * initialize ( "mcp-2" ) ;
484- firstResponse . resolve ( ) ;
485- yield * Fiber . join ( first ) ;
486- expect ( deleted ) . toEqual ( [ "session-1" ] ) ;
487-
488- yield * bridge . dispose ;
489- expect ( deleted ) . toEqual ( [ "session-1" , "session-2" ] ) ;
490- } ) . pipe ( Effect . scoped ) ,
491- ) ;
492-
493- it . effect ( "closes the current-draft session its notifications ride on when disposed" , ( ) =>
494- Effect . gen ( function * ( ) {
495- const requests : Array < { readonly method : string ; readonly headers : Headers } > = [ ] ;
496- const bridge = yield * makeAcpMcpOverAcpBridge ( {
497- endpoint : "http://127.0.0.1:1/mcp" ,
498- authorization : "Bearer bridge-test" ,
499- allocateConnectionId : Effect . succeed ( "connection-1" ) ,
500- fetchImplementation : ( _url , init ) => {
501- const method = init ?. method ?? "GET" ;
502- requests . push ( { method, headers : new Headers ( init ?. headers ) } ) ;
503- if ( method === "DELETE" ) return Promise . resolve ( new Response ( null , { status : 204 } ) ) ;
504- const request = JSON . parse ( String ( init ?. body ) ) as { readonly id ?: unknown } ;
505- return Promise . resolve (
506- request . id === undefined
507- ? new Response ( null , { status : 202 } )
508- : new Response (
509- JSON . stringify ( {
510- jsonrpc : "2.0" ,
511- id : request . id ,
512- result : { protocolVersion : "2025-06-18" } ,
513- } ) ,
514- {
515- headers : { "content-type" : "application/json" , "mcp-session-id" : "session-42" } ,
516- } ,
517- ) ,
518- ) ;
519- } ,
520- } ) ;
521-
522- yield * bridge . message ( { serverId : "t3-code" , requestId : "mcp-1" , method : "initialize" } ) ;
523- yield * bridge . notification ( {
524- serverId : "t3-code" ,
525- requestId : "mcp-2" ,
526- method : "notifications/initialized" ,
527- } ) ;
528- yield * bridge . dispose ;
529-
530- expect ( requests . map ( ( request ) => request . method ) ) . toEqual ( [ "POST" , "POST" , "DELETE" ] ) ;
531- expect ( requests [ 1 ] ?. headers . get ( "mcp-session-id" ) ) . toBe ( "session-42" ) ;
532- expect ( requests [ 2 ] ?. headers . get ( "mcp-session-id" ) ) . toBe ( "session-42" ) ;
533- } ) . pipe ( Effect . scoped ) ,
534- ) ;
535-
536453 it . effect (
537454 "rejects unknown servers, connections, endpoint rejections, and oversized messages" ,
538455 ( ) =>
0 commit comments