Index collection prefixes for path correspondence

This commit is contained in:
2026-11-02 17:36:55 +00:00
parent ebf98ffc62
commit e878ce51ff
4 changed files with 108 additions and 50 deletions

View File

@@ -143,3 +143,45 @@ func TestCyclicMatchingProtectsRemovedAndDerivedValues(t *testing.T) {
t.Fatal("effective rendering leaked")
}
}
func TestCorrespondenceIndexPreservesPathShapes(t *testing.T) {
destination := Keys("groups", "0", "a/b~")
policy, diagnostics := compileSequenceIdentityPolicy([]sequenceIdentityRegistration{{
selector: sequenceIdentitySelector{
literalSequenceSelector("groups"), literalSequenceSelector("0"), literalSequenceSelector("a/b~"),
},
identityFields: []string{"id"},
}})
if len(diagnostics) != 0 {
t.Fatal(diagnostics)
}
before := parseCompositionDocument(t, "before", "groups: {'0': {'a/b~': [{id: a}, {id: b}]}}")
after := parseCompositionDocument(t, "after", "groups: {'0': {'a/b~': [{id: b}, {id: a}, {id: new}]}}")
matching := buildResolutionCorrespondence(before, after, policy)
parsed, err := ParsePath("/groups/0/a~1b~0/0/field")
if err != nil {
t.Fatal(err)
}
for _, path := range []Path{destination.Index(0).Key("field"), parsed} {
entry, found := matching.entryPath(path)
if !found || entry.String() != destination.Index(1).Key("field").String() {
t.Fatalf("entry = %s, %t", entry.String(), found)
}
final, found := matching.finalPath(entry)
if !found || final.String() != path.String() {
t.Fatalf("round trip = %s, %t", final.String(), found)
}
}
for _, path := range []Path{
Keys("groups").Index(0).Key("a/b~").Index(0),
destination.Key("0"), destination.Index(8), destination,
} {
entry, found := matching.entryPath(path)
if !found || entry.String() != path.String() {
t.Fatalf("positional path %s became %s, %t", path.String(), entry.String(), found)
}
}
if _, found := matching.entryPath(destination.Index(2)); found {
t.Fatal("new identity acquired entry evidence")
}
}