Borrow lower collection policies during strict composition

This commit is contained in:
2026-10-25 22:59:03 +00:00
parent 68383f34de
commit 3a1b6ff355
5 changed files with 169 additions and 29 deletions

View File

@@ -313,14 +313,10 @@ func resolveStrictCollectionPolicies(
valuePresent := make(map[string]bool)
declarationsByPath := make(map[string][]sequenceDeclarationSpec, len(declarations))
for _, claim := range claims {
if len(lower.collections) != 0 {
valuePresent[claim.path.String()] = true
}
if claim.kind != document.Sequence {
continue
}
key := claim.path.String()
if !seen[key] {
valuePresent[key] = true
_, hasLower := lower.collections[key]
if (claim.kind == document.Sequence || hasLower) && !seen[key] {
seen[key] = true
paths = append(paths, claim.path.clone())
}
@@ -335,21 +331,18 @@ func resolveStrictCollectionPolicies(
}
identityFieldsByPath := make(map[string][]string)
effectiveLower := lower
if len(lower.collections) != 0 {
effectiveLower, _ = lowerCollectionPoliciesForClaims(lower, claims, declarationsByPath, applicationPolicy)
}
collectionPolicies := cloneCollectionPolicyScope(effectiveLower)
replacements := collectionReplacementPathsForClaims(lower, claims, declarationsByPath, applicationPolicy)
lowerView := lowerCollectionPolicyView{scope: lower, replacements: replacements}
var collectionPolicies collectionPolicyScope
var diagnostics []Diagnostic
for _, path := range paths {
key := path.String()
currentDeclarations := declarationsByPath[key]
lowerEntry, hasLower := effectiveLower.collections[key]
lowerPolicyValue, hasLower := lowerView.at(path)
var lowerPolicy *collectionPolicy
if hasLower {
copy := cloneCollectionPolicy(lowerEntry.policy)
lowerPolicy = &copy
lowerPolicy = &lowerPolicyValue
}
applicationIdentity, _ := applicationPolicy.identityFieldsAt(path)
@@ -366,7 +359,7 @@ func resolveStrictCollectionPolicies(
if hasLower && !valuePresent[key] {
// A declaration without a new value changes policy metadata but
// leaves retained record ownership untouched.
policyForPath = cloneCollectionPolicy(lowerEntry.policy)
policyForPath = cloneCollectionPolicy(lowerPolicyValue)
policyForPath.identityFields = cloneStrings(resolution.policy.identityFields)
policyForPath.identityPresent = resolution.policy.identityPresent
policyForPath.identityLocation = cloneLocation(resolution.policy.identityLocation)
@@ -375,7 +368,7 @@ func resolveStrictCollectionPolicies(
policyForPath.modeLocation = cloneLocation(resolution.policy.modeLocation)
}
if collectionPolicies.collections == nil {
collectionPolicies.collections = make(map[string]collectionPolicyEntry)
collectionPolicies.collections = make(map[string]collectionPolicyEntry, len(paths))
}
collectionPolicies.collections[key] = collectionPolicyEntry{destination: path.clone(), policy: policyForPath}
}