Project sequence evidence through item mappings

This commit is contained in:
2026-10-23 18:07:15 +00:00
parent 7b04dc6a50
commit f6b02dec03
10 changed files with 374 additions and 66 deletions

View File

@@ -357,6 +357,78 @@ escaped/~:
}
}
func TestProjectedCompositionOriginsUseNoncontiguousItemMappings(t *testing.T) {
lowerRoot := parseCompositionDocument(t, "lower", `records:
- id: first
label: equal
- id: middle
- id: last
nested: {old: lower}
`)
higherRoot := parseCompositionDocument(t, "higher", `records:
- id: last
nested: {new: higher}
- id: first
label: equal
- id: added
`)
lower, _ := documentAtPath(lowerRoot, Keys("records"))
higher, _ := documentAtPath(higherRoot, Keys("records"))
combined, diagnostics := combineSequence(
lower, higher, sequenceCombinationPolicy(sequenceModeUpsert, "id"),
sequenceCombinationContext{destination: Keys("records")},
)
if len(diagnostics) != 0 {
t.Fatalf("combine diagnostics = %#v", diagnostics)
}
inputs := []*document.Node{lowerRoot, higherRoot}
ranges := []sequenceRange{
{
sourceIndex: 0, path: Keys("records"), start: 0, end: 3,
items: combined.lowerItems,
}, {
sourceIndex: 1, path: Keys("records"), start: 0, end: 3,
items: combined.higherItems,
},
}
origins := projectedCompositionOrigins(inputs, ranges)
if got, want := sequenceIdentityValues(combined.value, "id"), []string{"first", "middle", "last", "added"}; !reflect.DeepEqual(got, want) {
t.Fatalf("combined IDs = %#v, want %#v", got, want)
}
for path, want := range map[string][]string{
"/records/0/label": {"higher"},
"/records/1/id": {"lower"},
"/records/2/nested/new": {"higher"},
"/records/3/id": {"higher"},
"/records/0/nested/new": nil,
"/records/2/nested/old": nil,
} {
origin := origins[path]
var got []string
for _, location := range origin.Locations {
got = append(got, location.SourceID)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("origin sources at %s = %#v, want %#v", path, got, want)
}
}
}
func TestCloneSequenceRangesPreservesPreparedProjection(t *testing.T) {
ranges := []sequenceRange{{
start: 0, end: 1,
projection: newSequenceItemProjectionIndex([]sequenceItemProjection{{inputIndex: 0, outputIndex: 4}}),
}}
cloned := cloneSequenceRanges(ranges)
if output, ok := cloned[0].outputForInput(0); !ok || output != 4 {
t.Fatalf("cloned projection = %d, %v; want output index 4", output, ok)
}
cloned[0].projection.outputByInput[0] = 9
if output, ok := ranges[0].outputForInput(0); !ok || output != 4 {
t.Fatalf("cloned projection aliases original: %d, %v", output, ok)
}
}
func TestComposeDocumentsValidatesRegisteredSequenceSingletons(t *testing.T) {
tests := []struct {
name string