From 447868e285220d2289f3ed2b89dc9bcfac79dcdf Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sat, 5 Dec 2026 17:11:20 +0000 Subject: [PATCH] Record consumption of nested inheritance selectors --- docs/roadmap/remediation.md | 7 +- facade_inheritance_selector_history_test.go | 75 +++++++++++++++++++++ internal/engine/history_inheritance.go | 24 ++++--- 3 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 facade_inheritance_selector_history_test.go diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index a12ac97..3bfdb3f 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -101,7 +101,12 @@ limit is needed. ## Finding 2 — Record consumption of descendants inside an inheritance selector -**Status:** Open. **Priority:** P2. **Affected stages:** 3 and 8, integrating +**Status:** Complete. The control producer now records every consumed selector +descendant. Public regression coverage verifies explanations, metadata history and +historical paths after decode failure, validation failure and success. Focused +inheritance tests and `./scripts/check.sh` passed. + +**Priority:** P2. **Affected stages:** 3 and 8, integrating the shared inheritance-history producer with failed-load inspection. ### Relevant code diff --git a/facade_inheritance_selector_history_test.go b/facade_inheritance_selector_history_test.go new file mode 100644 index 0000000..7ebd74b --- /dev/null +++ b/facade_inheritance_selector_history_test.go @@ -0,0 +1,75 @@ +package configkit_test + +import ( + "errors" + "testing" + + ck "go.maximumdirect.net/configkit" +) + +func TestInheritanceSelectorConsumptionAcrossOutcomes(t *testing.T) { + type settings struct { + Count int `yaml:"count"` + Items []map[string]any `yaml:"items"` + } + for _, outcome := range []struct { + name, count string + stage ck.InspectionStage + }{ + {"decode failure", "invalid", ck.InspectionStageInherited}, + {"validation failure", "0", ck.InspectionStageResolved}, + {"success", "0", ck.InspectionStageValidated}, + } { + t.Run(outcome.name, func(t *testing.T) { + input := "config:\n sequences: [{destination: [items], key: id}]\ncount: " + outcome.count + "\nitems:\n - {id: parent, width: 5}\n - {id: child, extends: {id: parent}, width: 20}\n" + definition := ck.Definition[settings]{} + if outcome.name == "validation failure" { + definition.Validate = func(_ *settings, v *ck.Validation) { v.Error(ck.Keys("count"), "rejected") } + } + result, err := ck.Load(ck.Bytes("selector", []byte(input)), ck.Options[settings]{Definition: definition}) + var provider inspectionProvider + if outcome.name == "success" { + if err != nil { + t.Fatal(err) + } + provider = result + } else { + var failure *ck.LoadError + if result != nil || !errors.As(err, &failure) { + t.Fatalf("result=%v error=%v", result, err) + } + provider = failure + } + view, ok := provider.InspectSubtree(ck.Path{}) + if !ok || view.Stage() != outcome.stage { + t.Fatalf("view available=%v stage=%s", ok, view.Stage()) + } + control := ck.Keys("items").Index(1).Key("extends") + for _, query := range []ck.Path{control, control.Key("id")} { + explanation, found := view.Explain(query) + if !found || explanation.Effective.Present || len(explanation.History) < 2 { + t.Fatalf("missing removal at %s: %#v", query, explanation) + } + last := explanation.History[len(explanation.History)-1] + if !last.Before.Present || last.After.Present || last.Origin.Operation != ck.ChangeInheritance { + t.Fatalf("wrong removal: %#v", last) + } + history := view.Metadata().History(query) + if len(history) == 0 { + t.Fatal("missing metadata history") + } + change := history[len(history)-1] + if change.Path.String() != control.String() || change.Origin.Operation != ck.ChangeInheritance { + t.Fatalf("wrong operation: %#v", change) + } + observed := false + for _, path := range view.HistoricalPaths() { + observed = observed || path.String() == query.String() + } + if !observed { + t.Fatalf("historical path missing: %s", query) + } + } + }) + } +} diff --git a/internal/engine/history_inheritance.go b/internal/engine/history_inheritance.go index c5e69ac..d392568 100644 --- a/internal/engine/history_inheritance.go +++ b/internal/engine/history_inheritance.go @@ -65,22 +65,26 @@ func (builder *historyBuilder) observeInheritanceControl(payload historyPayloadR node, before := builder.scratchAt(control.path) selections := resolveInheritanceAttribution(operation, control.path) var attributionRef historyAttributionRef = noHistoryAttribution - var sensitive bool - if before && node != nil { - sensitive = node.Sensitive - } if len(selections) != 0 { selection := selections[0] attributionRef = builder.addAttribution(selection.origin, nil, selection.dependencies) } ref := payload ref.substep = operationIndex * 2 - builder.addObservation(historyObservation{ - path: control.path, phase: historyPhaseInheritance, payload: ref, - reportedPath: control.path, role: historyRoleControl, - beforePresent: before, sensitive: sensitive, - attributionRef: attributionRef, - }) + observe := func(path Path, value *document.Node) { + builder.addObservation(historyObservation{ + path: path, phase: historyPhaseInheritance, payload: ref, + reportedPath: control.path, role: historyRoleControl, + beforePresent: before, sensitive: value != nil && value.Sensitive, + attributionRef: attributionRef, + }) + } + if before { + walkDocument(node, control.path, observe) + } else { + observe(control.path, nil) + } + replaceHistoryPath(&builder.scratch, control.path, nil) }