package engine import "go.maximumdirect.net/configkit/internal/document" func appendInheritanceExplanation(explanation *Explanation, working **document.Node, query Path, model *historyModel, selections historyReplaySelections, secrets map[string]bool) { if model == nil { return } for _, payload := range model.inheritancePayloads { for operationIndex, operation := range payload.operations { if operation.control != nil { ref := historyPayloadRef{phase: historyPhaseInheritance, id: 0, substep: operationIndex * 2} selection, selected := selections.byPayload[ref] if !selected { continue } before := valueSnapshot(*working, query, secrets) replaceHistoryPath(working, operation.control.path, nil) after := valueSnapshot(*working, query, secrets) appendInheritanceChange(explanation, selection, before, after) continue } if operation.transfer == nil { continue } parentRef := historyPayloadRef{phase: historyPhaseInheritance, id: 0, substep: operationIndex * 2} childRef := historyPayloadRef{phase: historyPhaseInheritance, id: 0, substep: operationIndex*2 + 1} parentSelection, hasParent := selections.byPayload[parentRef] childSelection, hasChild := selections.byPayload[childRef] before := valueSnapshot(*working, query, secrets) replaceHistoryPath(working, operation.transfer.to, operation.parent) // A record keeps its own identity throughout inheritance. Restore it // before taking enclosing snapshots as well as direct field snapshots. for _, field := range operation.identityFields { identity, _ := documentAtPath(operation.effective, Keys(field)) replaceHistoryPath(working, operation.transfer.to.Key(field), identity) } afterParent := valueSnapshot(*working, query, secrets) if hasParent { appendInheritanceChange(explanation, parentSelection, before, afterParent) } replaceHistoryPath(working, operation.transfer.to, operation.effective) afterChild := valueSnapshot(*working, query, secrets) if hasChild { appendInheritanceChange(explanation, childSelection, afterParent, afterChild) } } } } func appendInheritanceChange(explanation *Explanation, selection historySelection, before, after ValueSnapshot) { if !selection.hasAttribution { return } explanation.History = append(explanation.History, ValueChange{ Before: before, After: after, Origin: cloneOrigin(selection.attribution.origin), Reasons: append([]string(nil), selection.attribution.reasons...), Dependencies: clonePaths(selection.attribution.dependencies), }) }