@@ -1163,7 +1163,7 @@ func TestRunAggregateDiff_ModifiedFileAcrossCheckpoints(t *testing.T) {
11631163 }
11641164 store .Reset ()
11651165
1166- patch , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" , "cp2" })
1166+ patch , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" , "cp2" }, nil )
11671167 if err != nil {
11681168 t .Fatalf ("RunAggregateDiff: %v" , err )
11691169 }
@@ -1206,7 +1206,7 @@ func TestRunAggregateDiff_CreatedFile(t *testing.T) {
12061206 }
12071207 store .Reset ()
12081208
1209- patch , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" })
1209+ patch , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" }, nil )
12101210 if err != nil {
12111211 t .Fatalf ("RunAggregateDiff: %v" , err )
12121212 }
@@ -1244,7 +1244,7 @@ func TestRunAggregateDiff_DeletedFile(t *testing.T) {
12441244 }
12451245 store .Reset ()
12461246
1247- patch , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" })
1247+ patch , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" }, nil )
12481248 if err != nil {
12491249 t .Fatalf ("RunAggregateDiff: %v" , err )
12501250 }
@@ -1305,7 +1305,7 @@ func TestRunAggregateDiff_CreatedThenDeleted(t *testing.T) {
13051305 }
13061306 store .Reset ()
13071307
1308- _ , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" , "cp2" })
1308+ _ , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" , "cp2" }, nil )
13091309 if err != nil {
13101310 t .Fatalf ("RunAggregateDiff: %v" , err )
13111311 }
@@ -1349,7 +1349,7 @@ func TestRunAggregateDiff_UnchangedFileOmitted(t *testing.T) {
13491349 }
13501350 store .Reset ()
13511351
1352- _ , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" , "cp2" })
1352+ _ , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" , "cp2" }, nil )
13531353 if err != nil {
13541354 t .Fatalf ("RunAggregateDiff: %v" , err )
13551355 }
@@ -1360,7 +1360,7 @@ func TestRunAggregateDiff_UnchangedFileOmitted(t *testing.T) {
13601360
13611361func TestRunAggregateDiff_EmptyCheckpointIDs (t * testing.T ) {
13621362 store , _ := newTestStore (t )
1363- patch , changes , err := store .RunAggregateDiff (context .Background (), nil )
1363+ patch , changes , err := store .RunAggregateDiff (context .Background (), nil , nil )
13641364 if err != nil {
13651365 t .Fatalf ("RunAggregateDiff with nil: %v" , err )
13661366 }
@@ -1374,7 +1374,7 @@ func TestRunAggregateDiff_EmptyCheckpointIDs(t *testing.T) {
13741374
13751375func TestRunAggregateDiff_NonexistentCheckpoint (t * testing.T ) {
13761376 store , _ := newTestStore (t )
1377- _ , _ , err := store .RunAggregateDiff (context .Background (), []string {"nonexistent_cp" })
1377+ _ , _ , err := store .RunAggregateDiff (context .Background (), []string {"nonexistent_cp" }, nil )
13781378 if err == nil {
13791379 t .Fatal ("expected error for nonexistent checkpoint" )
13801380 }
@@ -1407,7 +1407,7 @@ func TestRunAggregateDiff_MultipleFilesAggregated(t *testing.T) {
14071407 }
14081408 store .Reset ()
14091409
1410- patch , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" })
1410+ patch , changes , err := store .RunAggregateDiff (context .Background (), []string {"cp1" }, nil )
14111411 if err != nil {
14121412 t .Fatalf ("RunAggregateDiff: %v" , err )
14131413 }
@@ -1428,3 +1428,62 @@ func TestRunAggregateDiff_MultipleFilesAggregated(t *testing.T) {
14281428 t .Fatalf ("patch missing file headers:\n %s" , patch )
14291429 }
14301430}
1431+
1432+ func TestRunAggregateDiff_HistoricalFileFilteredByVersion (t * testing.T ) {
1433+ store , workdir := newTestStore (t )
1434+
1435+ // Simulate "previous run": capture file A, finalize prev_cp.
1436+ absA := writeWorkdirFile (t , workdir , "a.txt" , "from prev run\n " )
1437+ if _ , err := store .CapturePreWrite (absA ); err != nil {
1438+ t .Fatalf ("capture a: %v" , err )
1439+ }
1440+ if err := os .WriteFile (absA , []byte ("modified in prev run\n " ), 0o644 ); err != nil {
1441+ t .Fatalf ("write a: %v" , err )
1442+ }
1443+ if _ , err := store .Finalize ("prev_cp" ); err != nil {
1444+ t .Fatalf ("finalize prev_cp: %v" , err )
1445+ }
1446+ store .Reset ()
1447+
1448+ // Get prev run's FileVersions.
1449+ prevFV , err := store .GetCheckpointFileVersions ("prev_cp" )
1450+ if err != nil {
1451+ t .Fatalf ("get prev vers: %v" , err )
1452+ }
1453+
1454+ // "Current run": capture file B only, a.txt is NOT touched.
1455+ absB := writeWorkdirFile (t , workdir , "b.txt" , "old b\n " )
1456+ if _ , err := store .CapturePreWrite (absB ); err != nil {
1457+ t .Fatalf ("capture b: %v" , err )
1458+ }
1459+ if err := os .WriteFile (absB , []byte ("new b\n " ), 0o644 ); err != nil {
1460+ t .Fatalf ("write b: %v" , err )
1461+ }
1462+ if _ , err := store .Finalize ("cur_cp1" ); err != nil {
1463+ t .Fatalf ("finalize cur_cp1: %v" , err )
1464+ }
1465+ store .Reset ()
1466+
1467+ // Second checkpoint in current run (still no touch on a.txt).
1468+ if _ , err := store .Finalize ("cur_cp2" ); err != nil {
1469+ t .Fatalf ("finalize cur_cp2: %v" , err )
1470+ }
1471+ store .Reset ()
1472+
1473+ patch , changes , err := store .RunAggregateDiff (context .Background (),
1474+ []string {"cur_cp1" , "cur_cp2" }, prevFV )
1475+ if err != nil {
1476+ t .Fatalf ("RunAggregateDiff: %v" , err )
1477+ }
1478+ // a.txt should be filtered out: version unchanged from prev run.
1479+ // b.txt should appear.
1480+ if len (changes ) != 1 {
1481+ t .Fatalf ("expected 1 change (b.txt only), got %d: %+v" , len (changes ), changes )
1482+ }
1483+ if changes [0 ].Path != "b.txt" {
1484+ t .Fatalf ("expected b.txt, got %s" , changes [0 ].Path )
1485+ }
1486+ if strings .Contains (patch , "a.txt" ) {
1487+ t .Fatalf ("patch should NOT contain a.txt (filtered by version):\n %s" , patch )
1488+ }
1489+ }
0 commit comments