@@ -239,8 +239,8 @@ test('growth shared by two entries names the merge-base modules they already hav
239239
240240 const shared = describeSharedGrowthHomes (
241241 [
242- { id : 'entry-a.ts' , added : [ addedFile ] , baseGraph : graphA } ,
243- { id : 'entry-b.ts' , added : [ addedFile ] , baseGraph : graphB } ,
242+ { id : 'entry-a.ts' , added : [ addedFile ] , baseGraph : graphA , headClosureSize : graphA . size + 1 } ,
243+ { id : 'entry-b.ts' , added : [ addedFile ] , baseGraph : graphB , headClosureSize : graphB . size + 1 } ,
244244 ] ,
245245 '/repo' ,
246246 ) ;
@@ -257,13 +257,104 @@ test('growth that no other entry shares produces no shared-homes note', () => {
257257 const graphA = new Map < string , string | null > ( [ [ '/repo/entry-a.ts' , null ] ] ) ;
258258 expect (
259259 describeSharedGrowthHomes (
260- [ { id : 'entry-a.ts' , added : [ '/repo/new.ts' ] , baseGraph : graphA } ] ,
260+ [ { id : 'entry-a.ts' , added : [ '/repo/new.ts' ] , baseGraph : graphA , headClosureSize : 2 } ] ,
261261 '/repo' ,
262262 ) ,
263263 'nothing to aggregate when only one entry grew by this module' ,
264264 ) . toBeNull ( ) ;
265265} ) ;
266266
267+ test ( 'an equal-size replacement is not growth, so the aggregate stays silent' , ( ) => {
268+ // #2471's review: the aggregate used to take every entry with a newly evaluated module, which is
269+ // not the condition the per-entry rule applies. Both entries below swapped one module for
270+ // another -- same closure size, one module the merge-base did not evaluate, and the SAME one, so
271+ // the grouping would fire. `classifyGrowth` passes both, so this must print nothing at all.
272+ const addedFile = '/repo/packages/demo/src/new-thing.ts' ;
273+ const sharedHome = '/repo/packages/demo/src/shared-home.ts' ;
274+ const graphA = new Map < string , string | null > ( [
275+ [ '/repo/entry-a.ts' , null ] ,
276+ [ sharedHome , '/repo/entry-a.ts' ] ,
277+ [ '/repo/packages/demo/src/dropped-by-a.ts' , '/repo/entry-a.ts' ] ,
278+ ] ) ;
279+ const graphB = new Map < string , string | null > ( [
280+ [ '/repo/entry-b.ts' , null ] ,
281+ [ sharedHome , '/repo/entry-b.ts' ] ,
282+ [ '/repo/packages/demo/src/dropped-by-b.ts' , '/repo/entry-b.ts' ] ,
283+ ] ) ;
284+
285+ expect ( classifyGrowth ( 'entry-a.ts' , graphA . size , graphA . size ) ) . toBeNull ( ) ;
286+ expect ( classifyGrowth ( 'entry-b.ts' , graphB . size , graphB . size ) ) . toBeNull ( ) ;
287+ expect (
288+ describeSharedGrowthHomes (
289+ [
290+ { id : 'entry-a.ts' , added : [ addedFile ] , baseGraph : graphA , headClosureSize : graphA . size } ,
291+ { id : 'entry-b.ts' , added : [ addedFile ] , baseGraph : graphB , headClosureSize : graphB . size } ,
292+ ] ,
293+ '/repo' ,
294+ ) ,
295+ 'a swap at equal size is no violation: the aggregate may not fail where the rule passes' ,
296+ ) . toBeNull ( ) ;
297+ expect (
298+ describeSharedGrowthHomes (
299+ [
300+ { id : 'entry-a.ts' , added : [ addedFile ] , baseGraph : graphA , headClosureSize : graphA . size } ,
301+ {
302+ id : 'entry-b.ts' ,
303+ added : [ addedFile ] ,
304+ baseGraph : graphB ,
305+ headClosureSize : graphB . size - 1 ,
306+ } ,
307+ ] ,
308+ '/repo' ,
309+ ) ,
310+ 'a closure that shrank while adding a module is likewise not growth' ,
311+ ) . toBeNull ( ) ;
312+ } ) ;
313+
314+ test ( 'disjoint growth groups keep their own entries and homes in separate blocks' , ( ) => {
315+ // #2471's review: candidate homes from separate added-module groups were unioned into one list
316+ // labelled as common to every failing entry, which is false as soon as two groups exist. Both
317+ // added modules live in the same package here, so only the grouping -- not the package scope --
318+ // can keep them apart: new-x.ts grew a1/a2, new-y.ts grew b1/b2, and no closure is shared.
319+ const addedX = '/repo/packages/demo/src/new-x.ts' ;
320+ const addedY = '/repo/packages/demo/src/new-y.ts' ;
321+ const homeX = '/repo/packages/demo/src/home-x.ts' ;
322+ const homeY = '/repo/packages/demo/src/home-y.ts' ;
323+ const growth = ( id : string , added : string , home : string ) => {
324+ const entryPath = `/repo/${ id } ` ;
325+ const baseGraph = new Map < string , string | null > ( [
326+ [ entryPath , null ] ,
327+ [ home , entryPath ] ,
328+ ] ) ;
329+ return { id, added : [ added ] , baseGraph, headClosureSize : baseGraph . size + 1 } ;
330+ } ;
331+
332+ const shared = describeSharedGrowthHomes (
333+ [
334+ growth ( 'entry-a1.ts' , addedX , homeX ) ,
335+ growth ( 'entry-a2.ts' , addedX , homeX ) ,
336+ growth ( 'entry-b1.ts' , addedY , homeY ) ,
337+ growth ( 'entry-b2.ts' , addedY , homeY ) ,
338+ ] ,
339+ '/repo' ,
340+ ) ;
341+
342+ const blocks = ( shared ?? '' ) . split ( '\n\n' ) ;
343+ expect ( blocks , 'one block per added module, never one merged list' ) . toHaveLength ( 2 ) ;
344+ const blockX = blocks . find ( ( block ) => block . startsWith ( 'packages/demo/src/new-x.ts' ) ) ?? '' ;
345+ const blockY = blocks . find ( ( block ) => block . startsWith ( 'packages/demo/src/new-y.ts' ) ) ?? '' ;
346+
347+ expect ( blockX , 'each entry is named with how much it grew' ) . toContain ( 'entry-a1.ts (+1)' ) ;
348+ expect ( blockX ) . toContain ( 'entry-a2.ts (+1)' ) ;
349+ expect ( blockX ) . toContain ( 'packages/demo/src/home-x.ts' ) ;
350+ expect ( blockX , 'b1/b2 did not grow by new-x.ts' ) . not . toContain ( 'entry-b1.ts' ) ;
351+ expect ( blockX , 'no entry that grew by new-x.ts evaluates home-y.ts' ) . not . toContain ( 'home-y.ts' ) ;
352+ expect ( blockY ) . toContain ( 'entry-b1.ts (+1)' ) ;
353+ expect ( blockY ) . toContain ( 'packages/demo/src/home-y.ts' ) ;
354+ expect ( blockY , 'a1/a2 did not grow by new-y.ts' ) . not . toContain ( 'entry-a1.ts' ) ;
355+ expect ( blockY , 'no entry that grew by new-y.ts evaluates home-x.ts' ) . not . toContain ( 'home-x.ts' ) ;
356+ } ) ;
357+
267358/**
268359 * A committed fixture repository: one workspace package with a manifest export target, a
269360 * top-level façade, a nested façade, and a test source. Everything here is TRACKED, so anything a
@@ -516,11 +607,16 @@ test('entries that grow by the same new module report shared merge-base homes on
516607 // #2423's review: when several entries grow because they all reached the same new module, the
517608 // per-entry test above already fails once per entry -- this adds ONE more diagnostic naming the
518609 // modules they already have in common, instead of leaving a reader to notice the repetition
519- // across several separate failures by hand. It can only fail alongside at least two already-red
520- // entries above, so it never changes the gate's own pass/fail verdict.
521- const growths = carriedGrowth
522- . filter ( ( growth ) => growth . added . length > 0 )
523- . map ( ( growth ) => ( { id : growth . entry . id , added : growth . added , baseGraph : growth . baseGraph } ) ) ;
610+ // across several separate failures by hand. Every carried entry is handed over with its head
611+ // closure size, and the aggregation itself keeps only the ones the no-growth rule fails
612+ // (#2471 review) -- so it can only fail alongside at least two already-red entries above and
613+ // never changes the gate's own pass/fail verdict.
614+ const growths = carriedGrowth . map ( ( growth ) => ( {
615+ id : growth . entry . id ,
616+ added : growth . added ,
617+ baseGraph : growth . baseGraph ,
618+ headClosureSize : growth . graph . size ,
619+ } ) ) ;
524620 const shared = describeSharedGrowthHomes ( growths , repoRoot ) ;
525621 expect (
526622 shared ,
0 commit comments