Apply nested collection operations when copying mappings

This commit is contained in:
2026-10-24 00:11:21 +00:00
parent 8ecfedc91b
commit dcf0379e02
5 changed files with 156 additions and 29 deletions

View File

@@ -298,7 +298,7 @@ func TestAncestorReplacementRequiresIdentityWhenRetainedModeReturns(t *testing.T
collectionPolicies: scope, origins: make(map[string]Origin),
})
}
reintroduceAncestor := func(t *testing.T, assembly *assemblyAccumulator) {
removeAncestor := func(t *testing.T, assembly *assemblyAccumulator) {
t.Helper()
if diagnostics := assembly.applyOverlayWithCollectionPolicy(
parseItemPolicyDocument(t, "remove", "catalog: null\n"), nil, collectionPolicyScope{}, nil,
@@ -306,23 +306,17 @@ func TestAncestorReplacementRequiresIdentityWhenRetainedModeReturns(t *testing.T
); len(diagnostics) != 0 {
t.Fatalf("ancestor removal diagnostics = %#v", diagnostics)
}
if diagnostics := assembly.applyOverlayWithCollectionPolicy(
parseItemPolicyDocument(t, "reintroduction", "catalog:\n prompts: [{id: restored, name: restored}]\n"), nil,
collectionPolicyScope{}, nil, LayerBase, sequencePolicy{}, nil,
); len(diagnostics) != 0 {
t.Fatalf("ancestor reintroduction diagnostics = %#v", diagnostics)
}
}
t.Run("retained append mode requires a renewed identity", func(t *testing.T) {
assembly := newAssembly(t)
reintroduceAncestor(t, assembly)
removeAncestor(t, assembly)
policy, ok := assembly.current.collectionPolicies.at(path)
if !ok || policy.identityPresent || !policy.explicitModePresent || policy.explicitMode != sequenceModeAppend {
t.Fatalf("reintroduced policy = %#v, %v", policy, ok)
t.Fatalf("retired collection policy = %#v, %v", policy, ok)
}
diagnostics := assembly.applyOverlayWithCollectionPolicy(
parseItemPolicyDocument(t, "next", "catalog:\n prompts: [{value: next}]\n"), nil,
parseItemPolicyDocument(t, "reintroduction", "catalog:\n prompts: [{id: restored, name: restored}]\n"), nil,
collectionPolicyScope{}, nil, LayerBase, sequencePolicy{}, nil,
)
if len(diagnostics) != 1 || diagnostics[0].Code != CodeSequenceInvalid {
@@ -332,7 +326,7 @@ func TestAncestorReplacementRequiresIdentityWhenRetainedModeReturns(t *testing.T
t.Run("a renewed key restores the retained append mode", func(t *testing.T) {
assembly := newAssembly(t)
reintroduceAncestor(t, assembly)
removeAncestor(t, assembly)
declaration := sequenceDeclarationSpec{
destination: path, identityFields: []string{"name"}, identityPresent: true,
}