@@ -67,6 +67,30 @@ describe('grep', () => {
6767 expect ( matches [ 1 ] ) . toMatchObject ( { path : 'a.txt' , line : 3 , content : 'hello' } )
6868 } )
6969
70+ it ( 'truncates oversized matched lines so a minified single-line file cannot return whole' , ( ) => {
71+ const giantLine = `{"status":"error"}${ 'x' . repeat ( 50_000 ) } `
72+ const files = vfsFromEntries ( [ [ 'internal/tool-results/run.json' , giantLine ] ] )
73+ const matches = grep ( files , 'status' , undefined , { outputMode : 'content' } ) as Array < {
74+ content : string
75+ } >
76+ expect ( matches ) . toHaveLength ( 1 )
77+ expect ( matches [ 0 ] . content . length ) . toBeLessThan ( 2_200 )
78+ expect ( matches [ 0 ] . content ) . toContain ( '[line truncated: 50018 chars total]' )
79+ } )
80+
81+ it ( 'truncates oversized context lines around a match' , ( ) => {
82+ const files = vfsFromEntries ( [ [ 'a.txt' , `before${ 'y' . repeat ( 10_000 ) } \nneedle\nafter` ] ] )
83+ const matches = grep ( files , 'needle' , undefined , {
84+ outputMode : 'content' ,
85+ context : 1 ,
86+ } ) as Array < {
87+ content : string
88+ } >
89+ expect ( matches ) . toHaveLength ( 3 )
90+ expect ( matches [ 0 ] . content . length ) . toBeLessThan ( 2_200 )
91+ expect ( matches [ 1 ] . content ) . toBe ( 'needle' )
92+ } )
93+
7094 it ( 'strips CR before end-of-line matching on CRLF content' , ( ) => {
7195 const files = vfsFromEntries ( [ [ 'x.txt' , 'foo\r\n' ] ] )
7296 const matches = grep ( files , 'foo$' , undefined , { outputMode : 'content' } )
0 commit comments