Remove unused combination evidence and helpers

This commit is contained in:
2026-10-25 21:49:52 +00:00
parent 119b42c810
commit 247a12bc50
12 changed files with 22 additions and 75 deletions

View File

@@ -347,6 +347,13 @@ Findings: **D04, F05**.
Owners: `internal/engine/sequence_combine.go`, `inheritance*.go`, `compose.go`, Owners: `internal/engine/sequence_combine.go`, `inheritance*.go`, `compose.go`,
`history.go`, `secret.go`, `destination.go`, and associated tests. `history.go`, `secret.go`, `destination.go`, and associated tests.
Status: **complete** (D04, F05). Prior completed commits: `2736ddf`,
`deb9aa5`, `ae3408a`, `ea27f17`, `08a8c25`, `877c497`, `8aba43d`,
`7bf2f0c`, `0f9ecf1`, `119b42c`. Validation passed:
`env GOTOOLCHAIN=local GOPROXY=off GOTELEMETRY=off go test ./internal/engine -run 'Sequence|Collection|Inheritance|History|Secret|Destination' -count=1`,
`env GOTOOLCHAIN=local GOPROXY=off GOTELEMETRY=off go test ./internal/engine -count=1`,
and `git diff --check`.
Remove unread `discardedLower` and `inheritanceReplacement.path`, `previous`, and Remove unread `discardedLower` and `inheritanceReplacement.path`, `previous`, and
`effective`, plus calculations solely producing them. Keep replacement `before` `effective`, plus calculations solely producing them. Keep replacement `before`
and `after` trees for accounting, projections, active origins/history, and append's and `after` trees for accounting, projections, active origins/history, and append's

View File

@@ -483,21 +483,6 @@ func allMappingClaims(claims []compositionClaim) bool {
return true return true
} }
func mergeDisjointMappings(target, incoming *document.Node, index *mappingIndex) {
for _, incomingEntry := range incoming.Mapping {
position := index.find(target, incomingEntry.Key)
if position < 0 {
cloned := incomingEntry
cloned.Value = document.Clone(incomingEntry.Value)
index.append(target, cloned)
continue
}
// Claim validation guarantees that the only remaining overlap is a
// mapping pair. Empty mappings naturally contribute no child entries.
mergeDisjointMappings(target.Mapping[position].Value, incomingEntry.Value, index)
}
}
func documentEntryIndex(entries []document.Entry, key string) int { func documentEntryIndex(entries []document.Entry, key string) int {
for index := range entries { for index := range entries {
if entries[index].Key == key { if entries[index].Key == key {

View File

@@ -18,13 +18,6 @@ const (
placementModeSequenceItem placementModeSequenceItem
) )
// PlacementModeFromFacade preserves root-owned numeric values until preflight
// can reject unsupported modes.
func PlacementModeFromFacade(value uint8) placementMode { return placementMode(value) }
// PlacementModeForFacade converts private source evidence to the root-owned mode.
func PlacementModeForFacade(value placementMode) uint8 { return uint8(value) }
// InputWithPlacement copies the root-owned mode into a private engine input. // InputWithPlacement copies the root-owned mode into a private engine input.
func InputWithPlacement(input Input, value uint8) Input { func InputWithPlacement(input Input, value uint8) Input {
input.placementMode = placementMode(value) input.placementMode = placementMode(value)

View File

@@ -237,10 +237,6 @@ func applyHistoryApplication(root **document.Node, application historyApplicatio
mergeHistoryAtPath(root, application.path, application.value, index, application.sequencesByPath) mergeHistoryAtPath(root, application.path, application.value, index, application.sequencesByPath)
} }
func mergeHistoryDocument(target **document.Node, incoming *document.Node, index *mappingIndex) {
mergeHistoryDocumentAtPath(target, incoming, Path{}, index, nil)
}
func mergeHistoryDocumentAtPath(target **document.Node, incoming *document.Node, path Path, index *mappingIndex, sequences map[string]sequenceHistoryContributionIndex) { func mergeHistoryDocumentAtPath(target **document.Node, incoming *document.Node, path Path, index *mappingIndex, sequences map[string]sequenceHistoryContributionIndex) {
if incoming == nil { if incoming == nil {
return return

View File

@@ -129,15 +129,11 @@ func projectInheritancePolicyTemplates(templates []collectionPolicyScope, prefix
return projected return projected
} }
// A replacement retains the displaced source/derivation record while the // A replacement retains the before and after values for history accounting.
// effective origin belongs to the child. Value trees are borrowed immutable // The trees are borrowed immutable inputs or detached templates.
// inputs or detached templates and are budgeted with retained history later.
type inheritanceReplacement struct { type inheritanceReplacement struct {
path Path before *document.Node
before *document.Node after *document.Node
after *document.Node
previous []displacedDefinition
effective Origin
} }
// A link represents one shared relationship edge. Each contributor retains // A link represents one shared relationship edge. Each contributor retains
@@ -173,11 +169,6 @@ func inheritanceDirective(node *document.Node) (document.Entry, bool) {
return document.Entry{}, false return document.Entry{}, false
} }
func inheritanceDirectiveLocation(node *document.Node) Location {
entry, _ := inheritanceDirective(node)
return publicLocation(entry.Value.Location)
}
func withoutInheritanceDirective(node *document.Node) *document.Node { func withoutInheritanceDirective(node *document.Node) *document.Node {
payload := *node payload := *node
payload.Mapping = make([]document.Entry, 0, len(node.Mapping)) payload.Mapping = make([]document.Entry, 0, len(node.Mapping))

View File

@@ -237,10 +237,8 @@ func applyInheritanceSequenceOrigins(
var replacements []inheritanceReplacement var replacements []inheritanceReplacement
if operation == sequenceModeReplace { if operation == sequenceModeReplace {
if lower != nil { if lower != nil {
displaced := displacedOrigins(lower, origins, path)
replacements = append(replacements, inheritanceReplacement{ replacements = append(replacements, inheritanceReplacement{
path: path.clone(), before: lower, after: higher, before: lower, after: higher,
previous: displaced, effective: cloneOrigin(incomingOrigins[path.String()]),
}) })
deleteOriginSubtree(origins, path, lower) deleteOriginSubtree(origins, path, lower)
} }
@@ -265,12 +263,10 @@ func applyInheritanceSequenceOrigins(
lowerPath := path.Index(replacement.lowerIndex) lowerPath := path.Index(replacement.lowerIndex)
higherPath := path.Index(replacement.higherIndex) higherPath := path.Index(replacement.higherIndex)
outputPath := path.Index(replacement.outputIndex) outputPath := path.Index(replacement.outputIndex)
previous := displacedOrigins(lower.Sequence[replacement.lowerIndex], origins, lowerPath)
deleteOriginSubtree(origins, lowerPath, lower.Sequence[replacement.lowerIndex]) deleteOriginSubtree(origins, lowerPath, lower.Sequence[replacement.lowerIndex])
copyInheritanceSubtreeAt(origins, incomingOrigins, higher.Sequence[replacement.higherIndex], higherPath, outputPath) copyInheritanceSubtreeAt(origins, incomingOrigins, higher.Sequence[replacement.higherIndex], higherPath, outputPath)
replacements = append(replacements, inheritanceReplacement{ replacements = append(replacements, inheritanceReplacement{
path: outputPath, before: lower.Sequence[replacement.lowerIndex], after: higher.Sequence[replacement.higherIndex], before: lower.Sequence[replacement.lowerIndex], after: higher.Sequence[replacement.higherIndex],
previous: previous, effective: cloneOrigin(incomingOrigins[higherPath.String()]),
}) })
} }
for _, projection := range combined.higherItems { for _, projection := range combined.higherItems {

View File

@@ -55,10 +55,8 @@ func combineInheritanceTemplate(
mergeInheritanceOrigin(mergedOrigins, childPath, child.origins[childPath.String()]) mergeInheritanceOrigin(mergedOrigins, childPath, child.origins[childPath.String()])
}, },
replaced: func(childPath Path, existing, incoming *document.Node) { replaced: func(childPath Path, existing, incoming *document.Node) {
previous := displacedOrigins(existing, mergedOrigins, childPath)
result.replacements = append(result.replacements, inheritanceReplacement{ result.replacements = append(result.replacements, inheritanceReplacement{
path: childPath.clone(), before: existing, after: incoming, before: existing, after: incoming,
previous: previous, effective: cloneOrigin(child.origins[childPath.String()]),
}) })
deleteOriginSubtree(mergedOrigins, childPath, existing) deleteOriginSubtree(mergedOrigins, childPath, existing)
copyInheritanceSubtree(mergedOrigins, child.origins, incoming, childPath) copyInheritanceSubtree(mergedOrigins, child.origins, incoming, childPath)

View File

@@ -198,11 +198,6 @@ func TestIdentifiedInheritanceResolvesNestedCollectionsAtEachDestination(t *test
if _, found := expanded.origins["/jobs/0/steps/1/value"]; !found { if _, found := expanded.origins["/jobs/0/steps/1/value"]; !found {
t.Fatal("nested inherited value did not retain its destination origin") t.Fatal("nested inherited value did not retain its destination origin")
} }
for _, replacement := range expanded.replacements {
if replacement.path.String() == "/jobs/0/id" {
t.Fatal("parent identity was treated as payload replaced by the child's identity")
}
}
} }
func TestIdentifiedInheritanceRespectsOutputNodeBudget(t *testing.T) { func TestIdentifiedInheritanceRespectsOutputNodeBudget(t *testing.T) {

View File

@@ -44,11 +44,8 @@ func TestInheritedOriginsKeepSourcePathsPresenceAndIndependentReplacement(t *tes
if len(count.Locations) != 1 || count.Locations[0].SourceID != "source-2" || len(projectInheritanceSteps(count)) != 0 { if len(count.Locations) != 1 || count.Locations[0].SourceID != "source-2" || len(projectInheritanceSteps(count)) != 0 {
t.Fatalf("direct replacement origin = %#v", count) t.Fatalf("direct replacement origin = %#v", count)
} }
if len(result.replacements) != 1 || result.replacements[0].path.String() != "/child/count" || if len(result.replacements) != 1 || result.replacements[0].before.Text != "0" || result.replacements[0].after.Text != "3" {
result.replacements[0].before.Text != "0" || result.replacements[0].after.Text != "3" || t.Fatalf("replacement accounting values = %#v", result.replacements)
len(result.replacements[0].previous) != 1 ||
len(projectInheritanceSteps(result.replacements[0].previous[0].origin)) != 1 {
t.Fatalf("displaced inheritance = %#v", result.replacements)
} }
settings := result.origins["/child/settings"] settings := result.origins["/child/settings"]
if len(settings.Locations) != 2 || settings.Locations[0].SourceID != "source-1" || if len(settings.Locations) != 2 || settings.Locations[0].SourceID != "source-1" ||

View File

@@ -134,12 +134,6 @@ func classifySecretPathsWithEvidence(schema *schemaDescriptor, predicate func(Pa
return closeSecretDependencies(paths, secret, dependencies, inherited) return closeSecretDependencies(paths, secret, dependencies, inherited)
} }
func addSecretEvidencePath(paths map[string]Path, destination, local Path) Path {
path := appendDestination(destination, local)
addSecretPath(paths, path.String())
return path
}
func addSecretPath(paths map[string]Path, pointer string) { func addSecretPath(paths map[string]Path, pointer string) {
if existing, found := paths[pointer]; found && existing.valid() { if existing, found := paths[pointer]; found && existing.valid() {
// Accumulator keys already match their paths' canonical spelling. History // Accumulator keys already match their paths' canonical spelling. History

View File

@@ -23,7 +23,6 @@ type sequenceCombinationResult struct {
higherItems []sequenceItemProjection higherItems []sequenceItemProjection
replacements []sequenceItemReplacement replacements []sequenceItemReplacement
appendedHigher []int appendedHigher []int
discardedLower []int
} }
func combineSequence( func combineSequence(
@@ -36,7 +35,7 @@ func combineSequence(
} }
switch policy.operation { switch policy.operation {
case sequenceModeReplace: case sequenceModeReplace:
return replaceSequence(lower, higher, policy.effectiveIdentityFields, context) return replaceSequence(higher, policy.effectiveIdentityFields, context)
case sequenceModeAppend, sequenceModeUpsert: case sequenceModeAppend, sequenceModeUpsert:
return combineIdentifiedSequences(lower, higher, policy.operation, policy.effectiveIdentityFields, context) return combineIdentifiedSequences(lower, higher, policy.operation, policy.effectiveIdentityFields, context)
default: default:
@@ -55,7 +54,7 @@ func unchangedSequenceValue(lower *document.Node) sequenceCombinationResult {
} }
func replaceSequence( func replaceSequence(
lower, higher *document.Node, higher *document.Node,
identityFields []string, identityFields []string,
context sequenceCombinationContext, context sequenceCombinationContext,
) (sequenceCombinationResult, []Diagnostic) { ) (sequenceCombinationResult, []Diagnostic) {
@@ -68,9 +67,6 @@ func replaceSequence(
if higher.Kind == document.Sequence { if higher.Kind == document.Sequence {
result.higherItems = sequenceItemProjections(len(higher.Sequence), 0) result.higherItems = sequenceItemProjections(len(higher.Sequence), 0)
} }
if lower != nil && lower.Kind == document.Sequence {
result.discardedLower = sequenceIndexes(len(lower.Sequence))
}
return result, nil return result, nil
} }

View File

@@ -19,13 +19,12 @@ func TestCombineSequenceOperationsAndItemEvidence(t *testing.T) {
wantHigher []sequenceItemProjection wantHigher []sequenceItemProjection
wantReplacements []sequenceItemReplacement wantReplacements []sequenceItemReplacement
wantAppended []int wantAppended []int
wantDiscarded []int
}{ }{
{ {
name: "replace uses only higher records", name: "replace uses only higher records",
lower: "items: [{id: a}, {id: b}]\n", higher: "items: [{id: b, text: revised}]\n", lower: "items: [{id: a}, {id: b}]\n", higher: "items: [{id: b, text: revised}]\n",
operation: sequenceModeReplace, want: []string{"b"}, operation: sequenceModeReplace, want: []string{"b"},
wantHigher: []sequenceItemProjection{{inputIndex: 0, outputIndex: 0}}, wantDiscarded: []int{0, 1}, wantHigher: []sequenceItemProjection{{inputIndex: 0, outputIndex: 0}},
}, },
{ {
name: "append retains then appends", name: "append retains then appends",
@@ -57,7 +56,7 @@ func TestCombineSequenceOperationsAndItemEvidence(t *testing.T) {
if got := sequenceIdentityValues(result.value, "id"); !reflect.DeepEqual(got, test.want) { if got := sequenceIdentityValues(result.value, "id"); !reflect.DeepEqual(got, test.want) {
t.Fatalf("combined IDs = %#v, want %#v", got, test.want) t.Fatalf("combined IDs = %#v, want %#v", got, test.want)
} }
if !reflect.DeepEqual(result.lowerItems, test.wantLower) || !reflect.DeepEqual(result.higherItems, test.wantHigher) || !reflect.DeepEqual(result.replacements, test.wantReplacements) || !reflect.DeepEqual(result.appendedHigher, test.wantAppended) || !reflect.DeepEqual(result.discardedLower, test.wantDiscarded) { if !reflect.DeepEqual(result.lowerItems, test.wantLower) || !reflect.DeepEqual(result.higherItems, test.wantHigher) || !reflect.DeepEqual(result.replacements, test.wantReplacements) || !reflect.DeepEqual(result.appendedHigher, test.wantAppended) {
t.Fatalf("item evidence = %#v", result) t.Fatalf("item evidence = %#v", result)
} }
}) })
@@ -112,7 +111,7 @@ func TestReplaceSequenceAllowsNullAndNonSequenceValues(t *testing.T) {
lower := sequenceFromYAML(t, "items: [{id: lower}]\n") lower := sequenceFromYAML(t, "items: [{id: lower}]\n")
higher := sequenceFromYAML(t, test.higher) higher := sequenceFromYAML(t, test.higher)
result, diagnostics := combineSequence(lower, higher, sequenceCombinationPolicy(sequenceModeReplace), sequenceCombinationContext{destination: Keys("items")}) result, diagnostics := combineSequence(lower, higher, sequenceCombinationPolicy(sequenceModeReplace), sequenceCombinationContext{destination: Keys("items")})
if len(diagnostics) != 0 || result.value == nil || result.value.Kind != test.wantKind || !reflect.DeepEqual(result.discardedLower, []int{0}) { if len(diagnostics) != 0 || result.value == nil || result.value.Kind != test.wantKind {
t.Fatalf("replacement result = %#v, %#v", result, diagnostics) t.Fatalf("replacement result = %#v, %#v", result, diagnostics)
} }
}) })
@@ -172,7 +171,7 @@ func TestCombineSequenceReplacementResetsLowerIdentity(t *testing.T) {
higher := sequenceFromYAML(t, "items: [{name: new}]\n") higher := sequenceFromYAML(t, "items: [{name: new}]\n")
policy := sequenceCombinationPolicy(sequenceModeReplace, "name") policy := sequenceCombinationPolicy(sequenceModeReplace, "name")
result, diagnostics := combineSequence(lower, higher, policy, sequenceCombinationContext{destination: Keys("items")}) result, diagnostics := combineSequence(lower, higher, policy, sequenceCombinationContext{destination: Keys("items")})
if len(diagnostics) != 0 || !reflect.DeepEqual(sequenceIdentityValues(result.value, "name"), []string{"new"}) || !reflect.DeepEqual(result.discardedLower, []int{0}) { if len(diagnostics) != 0 || !reflect.DeepEqual(sequenceIdentityValues(result.value, "name"), []string{"new"}) {
t.Fatalf("replacement applied obsolete identity: %#v, %#v", result, diagnostics) t.Fatalf("replacement applied obsolete identity: %#v, %#v", result, diagnostics)
} }
} }