@@ -271,33 +271,35 @@ async fn test_resume_after_request_wise_channel_completed() -> anyhow::Result<()
271271 assert ! ( events[ 1 ] . contains( r#""id":2"# ) ) ;
272272
273273 // Resume with Last-Event-ID after the channel has completed.
274- // The cached events should be replayed and the stream should end .
274+ // The cached events should be replayed.
275275 let resume_response = client
276276 . get ( format ! ( "http://{addr}/mcp" ) )
277277 . header ( "Accept" , "text/event-stream" )
278278 . header ( "mcp-session-id" , session_id. to_string ( ) )
279279 . header ( "Mcp-Protocol-Version" , "2025-06-18" )
280280 . header ( "last-event-id" , "0/0" )
281- . timeout ( std:: time:: Duration :: from_secs ( 5 ) )
282281 . send ( )
283282 . await ?;
284283 assert_eq ! ( resume_response. status( ) , 200 ) ;
285284
286- let resume_body = resume_response. text ( ) . await ?;
287- let resume_events: Vec < & str > = resume_body
288- . split ( "\n \n " )
289- . filter ( |e| !e. is_empty ( ) )
290- . collect ( ) ;
291- assert ! (
292- !resume_events. is_empty( ) ,
293- "expected replayed events on resume, got empty"
294- ) ;
295-
296- // The replayed event should contain the original response
297- let replayed = resume_events[ 0 ] ;
285+ // Read incrementally — the resumed stream may stay open as a
286+ // standalone fallback, so we read just enough to verify replay.
287+ use futures:: StreamExt ;
288+ let mut stream = resume_response. bytes_stream ( ) ;
289+ let mut buf = String :: new ( ) ;
290+ let read_result = tokio:: time:: timeout ( Duration :: from_secs ( 10 ) , async {
291+ while let Some ( Ok ( chunk) ) = stream. next ( ) . await {
292+ buf. push_str ( & String :: from_utf8_lossy ( & chunk) ) ;
293+ if buf. contains ( r#""id":2"# ) {
294+ return true ;
295+ }
296+ }
297+ false
298+ } )
299+ . await ;
298300 assert ! (
299- replayed . contains ( r#""id":2"# ) ,
300- "replayed event should contain the tool response, got: {replayed }"
301+ read_result . unwrap_or ( false ) ,
302+ "expected replayed tool response on resume , got: {buf }"
301303 ) ;
302304
303305 ct. cancel ( ) ;
0 commit comments