@@ -579,19 +579,76 @@ return 'late'
579579 ] )
580580 } )
581581
582+ it ( 'returns old-threshold-sized direct diffs inline' , async ( ) => {
583+ await withBrowserosDir ( async ( ) => {
584+ const fake = createFakeServer ( )
585+ const inlineDiff = Array . from (
586+ { length : 2001 } ,
587+ ( _ , i ) => `word-${ i } ` ,
588+ ) . join ( ' ' )
589+ const session = {
590+ observe : ( ) => ( {
591+ diff : async ( ) => ( {
592+ changed : true ,
593+ text : inlineDiff ,
594+ added : 2001 ,
595+ removed : 0 ,
596+ afterUrl : 'https://example.com/large' ,
597+ } ) ,
598+ } ) ,
599+ pages : {
600+ getInfo : ( ) => ( { url : 'https://example.com/large' } ) ,
601+ } ,
602+ } as unknown as BrowserSession
603+
604+ registerBrowserTools ( fake . server as never , session )
605+
606+ const result = await fake . handlers . get ( 'diff' ) ?.( { page : 1 } )
607+
608+ expect ( result ?. isError ) . toBeFalsy ( )
609+ const data = result ?. structuredContent as
610+ | {
611+ added : number
612+ removed : number
613+ wordCount : number
614+ }
615+ | undefined
616+ expect ( data ) . toMatchObject ( {
617+ added : 2001 ,
618+ removed : 0 ,
619+ } )
620+ expect ( JSON . stringify ( result ?. structuredContent ) ) . not . toContain ( 'path' )
621+ expect ( JSON . stringify ( result ?. structuredContent ) ) . not . toContain (
622+ 'writtenToFile' ,
623+ )
624+ expect ( result ?. content ) . toEqual ( [
625+ expect . objectContaining ( {
626+ type : 'text' ,
627+ text : expect . stringContaining ( 'word-2000' ) ,
628+ } ) ,
629+ ] )
630+ expect ( result ?. content ) . toEqual ( [
631+ expect . objectContaining ( {
632+ type : 'text' ,
633+ text : expect . stringContaining ( '[UNTRUSTED_PAGE_CONTENT' ) ,
634+ } ) ,
635+ ] )
636+ } )
637+ } )
638+
582639 it ( 'writes large direct diffs to a BrowserOS output markdown file' , async ( ) => {
583640 await withBrowserosDir ( async ( ) => {
584641 const fake = createFakeServer ( )
585642 const largeDiff = Array . from (
586- { length : 2001 } ,
643+ { length : 10001 } ,
587644 ( _ , i ) => `word-${ i } ` ,
588645 ) . join ( ' ' )
589646 const session = {
590647 observe : ( ) => ( {
591648 diff : async ( ) => ( {
592649 changed : true ,
593650 text : largeDiff ,
594- added : 2001 ,
651+ added : 10001 ,
595652 removed : 0 ,
596653 afterUrl : 'https://example.com/large' ,
597654 } ) ,
@@ -618,10 +675,10 @@ return 'late'
618675 }
619676 | undefined
620677 expect ( data ) . toMatchObject ( {
621- added : 2001 ,
678+ added : 10001 ,
622679 removed : 0 ,
623680 truncated : true ,
624- wordCount : 2001 ,
681+ wordCount : 10001 ,
625682 writtenToFile : true ,
626683 } )
627684 const savedPath = data ?. path
@@ -630,7 +687,7 @@ return 'late'
630687 expect ( result ?. content ) . toEqual ( [
631688 expect . objectContaining ( {
632689 type : 'text' ,
633- text : expect . stringContaining ( 'Diff is 2001 words' ) ,
690+ text : expect . stringContaining ( 'Diff is 10001 words' ) ,
634691 } ) ,
635692 ] )
636693 expect ( result ?. content ) . toEqual ( [
@@ -642,12 +699,12 @@ return 'late'
642699 expect ( result ?. content ) . toEqual ( [
643700 expect . objectContaining ( {
644701 type : 'text' ,
645- text : expect . not . stringContaining ( 'word-2000 ' ) ,
702+ text : expect . not . stringContaining ( 'word-10000 ' ) ,
646703 } ) ,
647704 ] )
648705 const savedContent = readFileSync ( savedPath ?? '' , 'utf8' )
649706 expect ( savedContent ) . toContain ( '[UNTRUSTED_PAGE_CONTENT' )
650- expect ( savedContent ) . toContain ( 'word-2000 ' )
707+ expect ( savedContent ) . toContain ( 'word-10000 ' )
651708 expect ( data ?. contentLength ) . toBe ( savedContent . length )
652709 } )
653710 } )
@@ -728,7 +785,7 @@ return 'late'
728785 await withBrowserosDir ( async ( ) => {
729786 const fake = createFakeServer ( )
730787 const largeSnapshot = Array . from (
731- { length : 2001 } ,
788+ { length : 10001 } ,
732789 ( _ , i ) => `destination-${ i } ` ,
733790 ) . join ( ' ' )
734791 const session = {
@@ -776,7 +833,7 @@ return 'late'
776833 expect . objectContaining ( {
777834 type : 'text' ,
778835 text : expect . stringContaining (
779- 'full current snapshot is 2001 words' ,
836+ 'full current snapshot is 10001 words' ,
780837 ) ,
781838 } ) ,
782839 expect . objectContaining ( {
@@ -789,7 +846,7 @@ return 'late'
789846 expect . arrayContaining ( [
790847 expect . objectContaining ( {
791848 type : 'text' ,
792- text : expect . not . stringContaining ( 'destination-2000 ' ) ,
849+ text : expect . not . stringContaining ( 'destination-10000 ' ) ,
793850 } ) ,
794851 ] ) ,
795852 )
@@ -1126,13 +1183,58 @@ return 'late'
11261183 expect ( JSON . stringify ( result ?. structuredContent ) ) . not . toContain ( 'path' )
11271184 } )
11281185
1129- it ( 'writes very large snapshots to a BrowserOS output markdown file ' , async ( ) => {
1186+ it ( 'returns old-threshold-sized snapshots inline ' , async ( ) => {
11301187 await withBrowserosDir ( async ( ) => {
11311188 const fake = createFakeServer ( )
1132- const largeSnapshot = Array . from (
1189+ const inlineSnapshot = Array . from (
11331190 { length : 5001 } ,
11341191 ( _ , i ) => `node-${ i } ` ,
11351192 ) . join ( ' ' )
1193+ const session = {
1194+ observe : ( ) => ( {
1195+ snapshot : async ( ) => ( { text : inlineSnapshot } ) ,
1196+ } ) ,
1197+ pages : {
1198+ getInfo : ( ) => ( { url : 'https://example.com/large' } ) ,
1199+ } ,
1200+ } as unknown as BrowserSession
1201+ registerBrowserTools ( fake . server as never , session )
1202+
1203+ const result = await fake . handlers . get ( 'snapshot' ) ?.( { page : 4 } )
1204+
1205+ expect ( result ?. isError ) . toBeFalsy ( )
1206+ const data = result ?. structuredContent as
1207+ | {
1208+ page : number
1209+ }
1210+ | undefined
1211+ expect ( data ) . toMatchObject ( {
1212+ page : 4 ,
1213+ } )
1214+ expect ( JSON . stringify ( result ?. structuredContent ) ) . not . toContain ( 'path' )
1215+ expect ( result ?. content ) . toEqual ( [
1216+ expect . objectContaining ( {
1217+ type : 'text' ,
1218+ text : expect . stringContaining ( 'node-5000' ) ,
1219+ } ) ,
1220+ ] )
1221+ expect ( result ?. content ) . toEqual ( [
1222+ expect . objectContaining ( {
1223+ type : 'text' ,
1224+ text : expect . stringContaining ( '[UNTRUSTED_PAGE_CONTENT' ) ,
1225+ } ) ,
1226+ ] )
1227+ } )
1228+ } )
1229+
1230+ it ( 'writes very large snapshots to a BrowserOS output markdown file' , async ( ) => {
1231+ await withBrowserosDir ( async ( ) => {
1232+ const fake = createFakeServer ( )
1233+ const largeSnapshot = [
1234+ ...Array . from ( { length : 15000 } , ( ) => 'x' ) ,
1235+ 'last-node' ,
1236+ ] . join ( ' ' )
1237+ expect ( largeSnapshot . length ) . toBeLessThan ( 50_000 )
11361238 const session = {
11371239 observe : ( ) => ( {
11381240 snapshot : async ( ) => ( { text : largeSnapshot } ) ,
@@ -1157,7 +1259,7 @@ return 'late'
11571259 | undefined
11581260 expect ( data ) . toMatchObject ( {
11591261 page : 4 ,
1160- wordCount : 5001 ,
1262+ wordCount : 15001 ,
11611263 writtenToFile : true ,
11621264 } )
11631265 const savedPath = data ?. path
@@ -1180,8 +1282,7 @@ return 'late'
11801282 const savedContent = readFileSync ( savedPath ?? '' , 'utf8' )
11811283 expect ( savedContent ) . toContain ( '[UNTRUSTED_PAGE_CONTENT' )
11821284 expect ( savedContent ) . toContain ( '[END_UNTRUSTED_PAGE_CONTENT' )
1183- expect ( savedContent ) . toContain ( 'node-0' )
1184- expect ( savedContent ) . toContain ( 'node-5000' )
1285+ expect ( savedContent ) . toContain ( 'last-node' )
11851286 expect ( data ?. contentLength ) . toBe ( savedContent . length )
11861287 } )
11871288 } )
0 commit comments