File tree Expand file tree Collapse file tree 2 files changed +11
-10
lines changed
Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -186,8 +186,8 @@ describe('getFiles', () => {
186186 } )
187187
188188 describe ( 'file too large' , ( ) => {
189- test ( 'should truncate files over 100k chars to 1k chars with message' , async ( ) => {
190- const largeContent = 'x' . repeat ( 101_000 ) // 101k chars - over limit
189+ test ( 'should truncate files over 100k chars to first 100k chars with message' , async ( ) => {
190+ const largeContent = 'x' . repeat ( 100_001 ) + 'y' . repeat ( 1000 ) // over limit
191191 const mockFs = createMockFs ( {
192192 files : {
193193 '/project/large.bin' : {
@@ -203,11 +203,13 @@ describe('getFiles', () => {
203203 fs : mockFs ,
204204 } )
205205
206- // Should contain first 1k chars
207- expect ( result [ 'large.bin' ] ) . toContain ( 'x' . repeat ( 1000 ) )
206+ // Should contain first 100k chars
207+ expect ( result [ 'large.bin' ] ) . toContain ( 'x' . repeat ( 100_000 ) )
208+ // Should NOT contain content beyond the limit
209+ expect ( result [ 'large.bin' ] ) . not . toContain ( 'y' )
208210 // Should contain truncation message
209211 expect ( result [ 'large.bin' ] ) . toContain ( 'FILE_TOO_LARGE' )
210- expect ( result [ 'large.bin' ] ) . toContain ( '101,000 chars' )
212+ expect ( result [ 'large.bin' ] ) . toContain ( '101,001 chars' )
211213 } )
212214
213215 test ( 'should read files at exactly 100k chars' , async ( ) => {
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ export async function getFiles(params: {
3030 const result : Record < string , string | null > = { }
3131 const MAX_FILE_BYTES = 10 * 1024 * 1024 // 10MB - skip reading entirely
3232 const MAX_CHARS = 100_000 // 100k characters threshold
33- const TRUNCATE_TO_CHARS = 1_000 // Show first 1k chars when over limit
3433 const numFmt = new Intl . NumberFormat ( 'en-US' )
3534 const fmtNum = ( n : number ) => numFmt . format ( n )
3635
@@ -84,14 +83,14 @@ export async function getFiles(params: {
8483 const content = await fs . readFile ( fullPath , 'utf8' )
8584
8685 if ( content . length > MAX_CHARS ) {
87- const truncated = content . slice ( 0 , TRUNCATE_TO_CHARS )
86+ const truncated = content . slice ( 0 , MAX_CHARS )
8887 result [ relativePath ] =
8988 truncated +
9089 '\n\n[FILE_TOO_LARGE: This file is ' +
9190 fmtNum ( content . length ) +
92- ' chars, exceeding the 100k char limit. Only the first ' +
93- fmtNum ( TRUNCATE_TO_CHARS ) +
94- ' chars are shown . Use other tools to read sections of the file.]'
91+ ' chars, exceeding the ' +
92+ fmtNum ( MAX_CHARS ) +
93+ ' char limit. The content above has been truncated . Use other tools to read other sections of the file.]'
9594 } else {
9695 // Prepend TEMPLATE marker for example files
9796 result [ relativePath ] = isExampleFile
You can’t perform that action at this time.
0 commit comments