@@ -1369,6 +1369,42 @@ describe("buildGuardedModelFetch", () => {
13691369 expect ( refreshTimeout ) . toHaveBeenCalledTimes ( 2 ) ;
13701370 } ) ;
13711371
1372+ it ( "handles a valid large SSE event split before its boundary" , async ( ) => {
1373+ const payload = { text : "x" . repeat ( 70 * 1024 ) } ;
1374+ const encoder = new TextEncoder ( ) ;
1375+ fetchWithSsrFGuardMock . mockResolvedValue ( {
1376+ response : new Response (
1377+ new ReadableStream ( {
1378+ start ( controller ) {
1379+ controller . enqueue ( encoder . encode ( `data: ${ JSON . stringify ( payload ) } ` ) ) ;
1380+ controller . enqueue ( encoder . encode ( "\n\n" ) ) ;
1381+ controller . close ( ) ;
1382+ } ,
1383+ } ) ,
1384+ { headers : { "content-type" : "text/event-stream" } } ,
1385+ ) ,
1386+ finalUrl : "https://openrouter.ai/api/v1/chat/completions" ,
1387+ release : vi . fn ( async ( ) => undefined ) ,
1388+ } ) ;
1389+ const model = {
1390+ id : "gpt-5.4" ,
1391+ provider : "openrouter" ,
1392+ api : "openai-completions" ,
1393+ baseUrl : "https://openrouter.ai/api/v1" ,
1394+ } as unknown as Model < "openai-completions" > ;
1395+
1396+ const response = await buildGuardedModelFetch ( model ) (
1397+ "https://openrouter.ai/api/v1/chat/completions" ,
1398+ { method : "POST" } ,
1399+ ) ;
1400+ const items = [ ] ;
1401+ for await ( const item of Stream . fromSSEResponse ( response , new AbortController ( ) ) ) {
1402+ items . push ( item ) ;
1403+ }
1404+
1405+ expect ( items ) . toEqual ( [ payload ] ) ;
1406+ } ) ;
1407+
13721408 it ( "errors on oversized SSE body without event boundary in sanitizer" , async ( ) => {
13731409 const oversized = "x" . repeat ( 16 * 1024 * 1024 + 1024 ) ;
13741410 const encoder = new TextEncoder ( ) ;
0 commit comments