@@ -714,17 +714,42 @@ describe('processContextsServer - browser and terminal selections', () => {
714714 }
715715 )
716716
717- it ( 'refuses more than three page snapshots before resolving context' , async ( ) => {
717+ it ( 'delivers ten short page snapshots without dropping their sources' , async ( ) => {
718+ const snapshots = Array . from ( { length : 10 } , ( _ , index ) => ( {
719+ ...snapshot ,
720+ id : `11111111-1111-4111-8111-11111111111${ index } ` ,
721+ url : `https://example.com/page-${ index } ` ,
722+ text : `Source ${ index } ` ,
723+ } ) )
724+ const result = await processContextsServer (
725+ snapshots . map ( ( page , index ) => ( {
726+ kind : 'browser_page' as const ,
727+ label : `Page (${ index + 1 } )` ,
728+ snapshot : page ,
729+ } ) ) ,
730+ 'user-1'
731+ )
732+ expect ( result ) . toHaveLength ( 10 )
733+ for ( const [ index , context ] of result . entries ( ) ) {
734+ const payload = context . content . split ( '\n' ) . find ( ( line ) => line . startsWith ( '{' ) )
735+ expect ( payload && JSON . parse ( payload ) ) . toEqual ( snapshots [ index ] )
736+ }
737+ } )
738+
739+ it . each ( [
740+ { name : 'combined text' , text : 'x' . repeat ( 37_501 ) } ,
741+ { name : 'combined serialized bytes' , text : '\u0000' . repeat ( 18_751 ) } ,
742+ ] ) ( 'refuses an oversized page batch before resolving context: $name' , async ( { text } ) => {
718743 await expect (
719744 processContextsServer (
720745 Array . from ( { length : 4 } , ( _ , index ) => ( {
721746 kind : 'browser_page' as const ,
722747 label : `Page ${ index } ` ,
723- snapshot : { ...snapshot , id : `11111111-1111-4111-8111-11111111111${ index } ` } ,
748+ snapshot : { ...snapshot , text , id : `11111111-1111-4111-8111-11111111111${ index } ` } ,
724749 } ) ) ,
725750 'user-1'
726751 )
727- ) . rejects . toThrow ( 'At most 3 page snapshots ' )
752+ ) . rejects . toThrow ( 'These pages contain too much text ' )
728753 } )
729754
730755 it ( 'points every browser and terminal mention at its exact tab' , async ( ) => {
0 commit comments