Complete historical inventory and query services

This commit is contained in:
2026-10-26 16:09:32 +00:00
parent cacc558288
commit 76521f7cd8
13 changed files with 311 additions and 78 deletions

View File

@@ -92,3 +92,59 @@ func TestHistoryResolutionRetainsOriginalShapeAttributionBehindReplayGroup(t *te
t.Fatal("original resolution subtree sensitivity was omitted from observations")
}
}
func TestMetadataFinalizationRegistersResolutionInventoryAndRoots(t *testing.T) {
t.Parallel()
beforeShape := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{
Key: "0", Value: &document.Node{Kind: document.String, Text: "old"},
}}}
afterShape := &document.Node{Kind: document.Sequence, Sequence: []*document.Node{{
Kind: document.String, Text: "new", Sensitive: true,
}}}
before := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "shape", Value: beforeShape}}}
final := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "shape", Value: afterShape}}}
changePath := parseOverrideTestPath(t, "/shape/0")
snapshot := resolutionSnapshot{
change: Change{
Path: changePath, Origin: Origin{Layer: LayerResolution, Operation: ChangeNormalization},
Reasons: []string{"changed dynamic shape"}, Dependencies: []Path{Keys("source")},
},
before: beforeShape.Mapping[0].Value,
after: afterShape.Sequence[0],
}
parentSnapshot := resolutionSnapshot{
change: Change{
Path: Keys("shape"), Origin: Origin{Layer: LayerResolution, Operation: ChangeNormalization},
Reasons: []string{"replaced container"},
},
before: beforeShape,
after: afterShape,
}
var metadata Metadata
snapshots := []resolutionSnapshot{parentSnapshot, snapshot}
finalizeMetadataPathsWithResolution(&metadata, final, nil, snapshots, before, before)
if got := metadata.HistoricalPaths(); len(got) != 3 || got[0].String() != "" || got[1].String() != "/shape" || got[2].String() != "/shape/0" {
t.Fatalf("historical paths = %#v", got)
}
keyPath := Keys("shape", "0")
indexPath := Keys("shape").Index(0)
if !metadata.hasHistoricalPath(keyPath) || !metadata.hasHistoricalPath(indexPath) {
t.Fatalf("resolution shape inventory omitted key or index: %#v", metadata.HistoricalPaths())
}
if got := metadata.historyModel.selectHistory(keyPath); len(got) != 2 || !got[0].before || got[0].after || !got[1].before || got[1].after {
t.Fatalf("removed mapping-key resolution selection = %#v", got)
}
if got := metadata.historyModel.selectHistory(indexPath); len(got) != 2 || got[0].before || !got[0].after || got[1].before || !got[1].after {
t.Fatalf("introduced sequence-index resolution selection = %#v", got)
}
var retainedBefore, retainedAfter bool
for _, root := range metadata.historyModel.documentRoots() {
retainedBefore = retainedBefore || root == snapshot.before
retainedAfter = retainedAfter || root == snapshot.after
}
if !retainedBefore || !retainedAfter {
t.Fatalf("resolution roots not enumerated: before=%v after=%v", retainedBefore, retainedAfter)
}
}