@@ -238,61 +238,6 @@ describe("Git trees", () => {
238238 } ) ,
239239 )
240240
241- it . live ( "withholds patch text above the total byte budget and marks truncated" , ( ) =>
242- Effect . gen ( function * ( ) {
243- const root = yield * Effect . acquireRelease (
244- Effect . promise ( ( ) => tmpdir ( ) ) ,
245- ( dir ) => Effect . promise ( ( ) => dir [ Symbol . asyncDispose ] ( ) ) ,
246- )
247- yield * Effect . promise ( ( ) => initRepo ( root . path ) )
248- const git = yield * Git . Service
249- const repository = yield * git . repo . discover ( AbsolutePath . make ( root . path ) )
250- if ( ! repository ) throw new Error ( "Repository not found" )
251- const before = yield * git . tree . capture ( { repository, scopes : [ RelativePath . make ( "." ) ] } )
252- // Multi-byte content: byte size (not JS length) drives the budget.
253- yield * Effect . promise ( ( ) => Bun . write ( path . join ( root . path , "large-unicode.txt" ) , "🙂" . repeat ( 3_000_000 ) ) )
254- const after = yield * git . tree . capture ( { repository, scopes : [ RelativePath . make ( "." ) ] } )
255- const diffs = yield * git . tree . diff ( { repository, from : before , to : after , context : 0 } )
256- expect ( diffs ) . toHaveLength ( 1 )
257- expect ( diffs [ 0 ] ?. file ) . toBe ( "large-unicode.txt" )
258- expect ( diffs [ 0 ] ?. patch ) . toBe ( VcsPatch . emptyPatch ( "large-unicode.txt" ) )
259- expect ( diffs [ 0 ] ?. truncated ) . toBe ( true )
260- expect ( diffs [ 0 ] ?. additions ) . toBeGreaterThan ( 0 )
261- } ) ,
262- )
263-
264- it . live ( "limits total patch text across files, keeping the first under budget" , ( ) =>
265- Effect . gen ( function * ( ) {
266- const root = yield * Effect . acquireRelease (
267- Effect . promise ( ( ) => tmpdir ( ) ) ,
268- ( dir ) => Effect . promise ( ( ) => dir [ Symbol . asyncDispose ] ( ) ) ,
269- )
270- yield * Effect . promise ( ( ) => initRepo ( root . path ) )
271- const git = yield * Git . Service
272- const repository = yield * git . repo . discover ( AbsolutePath . make ( root . path ) )
273- if ( ! repository ) throw new Error ( "Repository not found" )
274- const before = yield * git . tree . capture ( { repository, scopes : [ RelativePath . make ( "." ) ] } )
275- yield * Effect . promise ( async ( ) => {
276- await Bun . write ( path . join ( root . path , "cap-a.txt" ) , `${ "a" . repeat ( 79 ) } \n` . repeat ( 80_000 ) )
277- await Bun . write ( path . join ( root . path , "cap-b.txt" ) , `${ "b" . repeat ( 79 ) } \n` . repeat ( 80_000 ) )
278- } )
279- const after = yield * git . tree . capture ( { repository, scopes : [ RelativePath . make ( "." ) ] } )
280- const diffs = yield * git . tree . diff ( { repository, from : before , to : after , context : 0 } )
281- const first = diffs . find ( ( item ) => item . file === "cap-a.txt" )
282- const second = diffs . find ( ( item ) => item . file === "cap-b.txt" )
283- // Either file may win the budget; exactly one must be withheld.
284- const kept = [ first , second ] . find ( ( item ) => item ?. truncated !== true )
285- const dropped = [ first , second ] . find ( ( item ) => item ?. truncated === true )
286- expect ( kept ?. patch ) . not . toBe ( "" )
287- expect ( kept ?. truncated ) . toBeUndefined ( )
288- expect ( dropped ?. patch ) . toBe ( VcsPatch . emptyPatch ( dropped ?. file ?? "" ) )
289- expect ( diffs . filter ( ( item ) => item . truncated === true ) ) . toHaveLength ( 1 )
290- expect (
291- diffs . reduce ( ( total , item ) => total + Buffer . byteLength ( item . patch ?? "" ) , 0 ) ,
292- ) . toBeLessThanOrEqual ( VcsPatch . MAX_TOTAL_PATCH_BYTES )
293- } ) ,
294- )
295-
296241 it . live (
297242 "diffs a path selection longer than any platform command line" ,
298243 ( ) =>
0 commit comments