Normalize original resolution history evidence

This commit is contained in:
2026-10-26 15:49:15 +00:00
parent 231ae66857
commit cacc558288
9 changed files with 270 additions and 34 deletions

View File

@@ -23,23 +23,26 @@ func TestCoalescedResolutionSnapshotsMatchOrderedScan(t *testing.T) {
want := coalescedResolutionSnapshotsByScan(snapshots)
got := coalescedResolutionSnapshots(snapshots)
if !reflect.DeepEqual(got, want) {
t.Fatalf("coalesced snapshots differ from ordered scan:\n got: %#v\nwant: %#v", got, want)
t.Fatalf("coalesced replay groups differ from ordered scan:\n got: %#v\nwant: %#v", got, want)
}
if len(got) != 4 || got[0].change.Origin.Operation != ChangeNormalization ||
!reflect.DeepEqual(got[0].change.Reasons, []string{"child", "shared", "child", "deep", "normalized"}) ||
len(got[0].change.Dependencies) != 2 || got[3].change.Path.String() != "" {
t.Fatalf("coalesced ordering or unions changed: %#v", got)
len(got[0].change.Dependencies) != 2 || got[3].change.Path.String() != "" ||
got[0].coveringRecordID != 0 || !reflect.DeepEqual(got[0].originalRecordIDs, []int{0, 3, 6}) ||
!reflect.DeepEqual(got[3].originalRecordIDs, []int{4, 5}) {
t.Fatalf("coalesced ordering, references, or unions changed: %#v", got)
}
}
func coalescedResolutionSnapshotsByScan(snapshots []resolutionSnapshot) []resolutionSnapshot {
groups := make([]resolutionSnapshot, 0, len(snapshots))
for _, snapshot := range snapshots {
func coalescedResolutionSnapshotsByScan(snapshots []resolutionSnapshot) []resolutionReplayGroup {
groups := make([]resolutionReplayGroup, 0, len(snapshots))
for recordID, snapshot := range snapshots {
merged := false
for i := range groups {
if !pathContainsByPointer(groups[i].change.Path, snapshot.change.Path) {
continue
}
groups[i].originalRecordIDs = append(groups[i].originalRecordIDs, recordID)
for _, reason := range snapshot.change.Reasons {
groups[i].change.Reasons = appendUniqueStringByScan(groups[i].change.Reasons, reason)
}
@@ -53,8 +56,11 @@ func coalescedResolutionSnapshotsByScan(snapshots []resolutionSnapshot) []resolu
break
}
if !merged {
snapshot.change = cloneChange(snapshot.change)
groups = append(groups, snapshot)
groups = append(groups, resolutionReplayGroup{
originalRecordIDs: []int{recordID},
coveringRecordID: recordID,
change: cloneChange(snapshot.change),
})
}
}
return groups