Remove superseded history attribution paths

This commit is contained in:
2026-10-26 18:11:04 +00:00
parent 6a1447c327
commit 3ffaef7ede
18 changed files with 146 additions and 534 deletions

View File

@@ -211,47 +211,51 @@ func TestApplyResolutionMetadataPreservesOverlappingDeltaOrder(t *testing.T) {
oldOrigin := Origin{Layer: LayerBase}
parentOrigin := Origin{Layer: LayerResolution, Operation: ChangeNormalization}
childOrigin := Origin{Layer: LayerResolution, Operation: ChangeDerivedDefault}
leaf := &document.Node{Kind: document.String, Text: "value"}
final := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{
Key: "group",
Value: &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{
Key: "item",
Value: &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "leaf", Value: leaf}}},
}}},
}}}
beforeLeaf := &document.Node{Kind: document.String, Text: "before"}
afterLeaf := &document.Node{Kind: document.String, Text: "after"}
beforeItem := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "leaf", Value: beforeLeaf}}}
afterItem := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "leaf", Value: afterLeaf}}}
beforeGroup := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "item", Value: beforeItem}}}
afterGroup := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "item", Value: afterItem}}}
before := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "group", Value: beforeGroup}}}
final := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "group", Value: afterGroup}}}
path := Keys("group", "item", "leaf")
builder := newHistoryBuilder()
builder.setScratch(before)
snapshots := []resolutionSnapshot{
{change: Change{Path: Keys("group"), Origin: parentOrigin}, before: beforeGroup, after: afterGroup},
{change: Change{Path: Keys("group", "item"), Origin: childOrigin}, before: beforeItem, after: afterItem},
}
builder.observeResolutionEvidence(snapshots)
builder.model.final = final
metadata := &Metadata{
fields: map[string]FieldInfo{"/group/item/leaf": {Origin: oldOrigin}},
history: make(map[string][]Change),
fields: map[string]FieldInfo{path.String(): {Explicit: true, Origin: oldOrigin}},
historyBuilder: builder,
}
entry := resolutionInput{metadata: Metadata{
fields: map[string]FieldInfo{"/group/item/leaf": {Explicit: true, Origin: oldOrigin}},
effectivePaths: effectivePathIndex(final),
fields: map[string]FieldInfo{path.String(): {Explicit: true, Origin: oldOrigin}},
effectivePaths: effectivePathIndex(before),
}}
resolved := resolutionResult{
final: final,
deltas: []documentDelta{{path: Keys("group")}, {path: Keys("group", "item")}},
snapshots: []resolutionSnapshot{
{change: Change{Path: Keys("group"), Origin: parentOrigin}},
{change: Change{Path: Keys("group", "item"), Origin: childOrigin}},
},
snapshots: snapshots,
}
applyResolutionMetadata(metadata, resolved, entry)
metadata.effectivePaths = effectivePathIndex(final)
metadata.historyModel = builder.freeze()
metadata.historyBuilder = nil
field := metadata.fields["/group/item/leaf"]
field := metadata.fields[path.String()]
if field.Origin.Operation != childOrigin.Operation {
t.Fatalf("final leaf origin operation = %q, want %q", field.Origin.Operation, childOrigin.Operation)
}
changes := metadata.history["/group/item/leaf"]
changes := metadata.History(path)
if len(changes) != 2 {
t.Fatalf("leaf history has %d entries, want 2: %#v", len(changes), changes)
}
if changes[0].Origin.Operation != parentOrigin.Operation || changes[1].Origin.Operation != childOrigin.Operation {
t.Fatalf("leaf history operations = %q, %q; want %q, %q", changes[0].Origin.Operation, changes[1].Origin.Operation, parentOrigin.Operation, childOrigin.Operation)
}
for index, change := range changes {
if len(change.Previous) != 1 || change.Previous[0].Layer != oldOrigin.Layer {
t.Errorf("leaf history[%d] Previous = %#v, want original origin", index, change.Previous)
}
}
}