Record consumption of nested inheritance selectors
This commit is contained in:
@@ -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
|
||||
|
||||
75
facade_inheritance_selector_history_test.go
Normal file
75
facade_inheritance_selector_history_test.go
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user