@@ -67,6 +67,71 @@ describe("AcpMcpOverAcpBridge", () => {
6767 } ) ,
6868 ) ;
6969
70+ it . effect ( "discards the disconnect response body before checking HTTP status" , ( ) =>
71+ Effect . gen ( function * ( ) {
72+ const cases = [
73+ { status : 500 , expectError : true } ,
74+ { status : 404 , expectError : false } ,
75+ { status : 200 , expectError : false } ,
76+ ] as const ;
77+
78+ for ( const [ index , testCase ] of cases . entries ( ) ) {
79+ let cancelled = false ;
80+ const bridge = yield * makeAcpMcpOverAcpBridge ( {
81+ endpoint : "http://127.0.0.1:1/mcp" ,
82+ authorization : "Bearer bridge-test" ,
83+ allocateConnectionId : Effect . succeed ( `connection-disconnect-${ index } ` ) ,
84+ fetchImplementation : async ( _url , init ) => {
85+ const method = init ?. method ?? "GET" ;
86+ if ( method === "DELETE" ) {
87+ return new Response (
88+ new ReadableStream ( {
89+ cancel ( ) {
90+ cancelled = true ;
91+ } ,
92+ } ) ,
93+ { status : testCase . status } ,
94+ ) ;
95+ }
96+ const body = init ?. body === undefined ? null : JSON . parse ( String ( init . body ) ) ;
97+ const request = body as { readonly id ?: unknown } ;
98+ return new Response (
99+ JSON . stringify ( {
100+ jsonrpc : "2.0" ,
101+ id : request . id ,
102+ result : { protocolVersion : "2025-06-18" , capabilities : { } , serverInfo : { } } ,
103+ } ) ,
104+ {
105+ headers : { "content-type" : "application/json" , "mcp-session-id" : "session-42" } ,
106+ } ,
107+ ) ;
108+ } ,
109+ } ) ;
110+
111+ const connected = yield * bridge . connect ( { serverId : "t3-code" } ) ;
112+ yield * bridge . message ( {
113+ connectionId : connected . connectionId ,
114+ method : "initialize" ,
115+ } ) ;
116+ const disconnect = bridge . disconnect ( { connectionId : connected . connectionId } ) ;
117+ if ( testCase . expectError ) {
118+ expect ( yield * disconnect . pipe ( Effect . flip ) ) . toMatchObject ( {
119+ _tag : "AcpMcpOverAcpError" ,
120+ message : `T3 Code MCP endpoint rejected disconnect with HTTP ${ testCase . status } .` ,
121+ } ) ;
122+ } else {
123+ expect ( yield * disconnect ) . toEqual ( { } ) ;
124+ }
125+ expect ( cancelled ) . toBe ( true ) ;
126+ expect (
127+ yield * bridge
128+ . message ( { connectionId : connected . connectionId , method : "tools/list" } )
129+ . pipe ( Effect . flip ) ,
130+ ) . toMatchObject ( { _tag : "AcpMcpOverAcpError" } ) ;
131+ }
132+ } ) ,
133+ ) ;
134+
70135 it . effect ( "aborts an in-flight HTTP request when the ACP call is interrupted" , ( ) =>
71136 Effect . gen ( function * ( ) {
72137 const started = Promise . withResolvers < AbortSignal > ( ) ;
0 commit comments