Publish inspection through one frozen history model
This commit is contained in:
@@ -22,21 +22,33 @@ type historyBudgetLayeredConfig struct {
|
||||
|
||||
func retainedInspectionNodeCountForTest(inspection *Inspection) int {
|
||||
seen := make(map[*document.Node]struct{})
|
||||
stack := []*document.Node{inspection.baseline, inspection.input, inspection.final, inspection.preCLI}
|
||||
for _, application := range inspection.applications {
|
||||
stack = append(stack, application.value)
|
||||
model := inspection.history
|
||||
stack := []*document.Node{model.baseline, model.final}
|
||||
for _, payload := range model.sourcePayloads {
|
||||
if payload.kind == historySourceApplicationPayload {
|
||||
stack = append(stack, payload.application.value)
|
||||
}
|
||||
}
|
||||
for _, application := range inspection.postDecodeApps {
|
||||
stack = append(stack, application.value)
|
||||
for _, payload := range model.inheritancePayloads {
|
||||
for _, operation := range payload.operations {
|
||||
stack = append(stack, operation.parent, operation.effective)
|
||||
}
|
||||
}
|
||||
for _, snapshot := range inspection.resolution {
|
||||
stack = append(stack, snapshot.before, snapshot.after)
|
||||
for _, payload := range model.cliPayloads {
|
||||
if payload.kind == historySourceApplicationPayload {
|
||||
stack = append(stack, payload.application.value)
|
||||
}
|
||||
}
|
||||
for _, operation := range inspection.inheritance {
|
||||
stack = append(stack, operation.parent, operation.effective)
|
||||
if model.preCLICheckpoint != nil {
|
||||
stack = append(stack, model.preCLICheckpoint.root)
|
||||
}
|
||||
for _, operation := range inspection.metadata.inheritance {
|
||||
stack = append(stack, operation.parent, operation.effective)
|
||||
if model.postCLICheckpoint != nil {
|
||||
stack = append(stack, model.postCLICheckpoint.root)
|
||||
}
|
||||
if model.resolutionPayload != nil {
|
||||
for _, snapshot := range model.resolutionPayload.snapshots {
|
||||
stack = append(stack, snapshot.before, snapshot.after)
|
||||
}
|
||||
}
|
||||
|
||||
for len(stack) != 0 {
|
||||
@@ -144,8 +156,8 @@ func TestLayeredHistoryBudgetRejectsBeforeSecretsAndValidation(t *testing.T) {
|
||||
if want == 0 {
|
||||
t.Fatal("independent retained-tree count was empty")
|
||||
}
|
||||
if len(baseline.Inspection.inheritance) == 0 || len(baseline.Inspection.metadata.inheritance) == 0 {
|
||||
t.Fatal("layered load did not retain both inheritance evidence copies")
|
||||
if baseline.Inspection.history == nil || baseline.Inspection.metadata.historyModel != baseline.Inspection.history || len(baseline.Inspection.history.inheritancePayloads) == 0 {
|
||||
t.Fatal("layered load did not publish its shared inheritance evidence owner")
|
||||
}
|
||||
exactCounts := &callbackCounts{}
|
||||
loaded, err := loadGroupedWithSecretLookupLimit(makeRequest(exactCounts), testSecretBinding(), lookup(exactCounts), want)
|
||||
@@ -169,23 +181,46 @@ func TestLayeredHistoryBudgetRejectsBeforeSecretsAndValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreparedInheritanceEvidenceOwnsDistinctTrees(t *testing.T) {
|
||||
root := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "value", Value: &document.Node{Kind: document.String, Text: "shared"}}}}
|
||||
resolved := resolvedLoad[historyBudgetSimpleConfig]{
|
||||
inheritance: &inheritanceScope{operations: []inheritanceOperation{{parent: root, effective: root}}},
|
||||
func TestPreparedInheritanceEvidenceSharesOwnerAndDetachesPublicViews(t *testing.T) {
|
||||
input := parseCompositionDocument(t, "inheritance", "parent: {value: shared}\nchild: {extends: parent}\n")
|
||||
expanded, diagnostics := expandInheritanceWithOrigins(input, nil, defaultProjectionLimits())
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatal(diagnostics)
|
||||
}
|
||||
counter := newRetainedNodeCounter(8)
|
||||
baseline := &document.Node{Kind: document.Mapping}
|
||||
builder := newHistoryBuilder()
|
||||
builder.observeBaseline(baseline)
|
||||
builder.setScratch(input)
|
||||
builder.observeInheritanceEvidence(expanded.operations)
|
||||
metadata := Metadata{historyBuilder: builder}
|
||||
resolved := resolvedLoad[historyBudgetSimpleConfig]{
|
||||
metadata: metadata, historyBuilder: builder, final: expanded.root,
|
||||
decoded: decodedConfiguration{baseline: baseline}, structuralInput: input,
|
||||
inheritance: expanded,
|
||||
}
|
||||
counter := newRetainedNodeCounter(100)
|
||||
inspection, ok := prepareInspectionHistory(resolved, counter)
|
||||
if !ok {
|
||||
t.Fatal("preparation rejected the exact size of the distinct retained copies")
|
||||
t.Fatal("preparation rejected the shared evidence owner")
|
||||
}
|
||||
if len(inspection.inheritance) != 1 || len(inspection.metadata.inheritance) != 1 {
|
||||
t.Fatalf("inheritance copies = inspection %#v, metadata %#v", inspection.inheritance, inspection.metadata.inheritance)
|
||||
if inspection.history == nil || inspection.metadata.historyModel != inspection.history || len(inspection.history.inheritancePayloads) != 1 {
|
||||
t.Fatalf("history owners = inspection %p, metadata %p, inheritance payloads %d", inspection.history, inspection.metadata.historyModel, len(inspection.history.inheritancePayloads))
|
||||
}
|
||||
inspectionOperation := inspection.inheritance[0]
|
||||
metadataOperation := inspection.metadata.inheritance[0]
|
||||
if inspectionOperation.parent == metadataOperation.parent || inspectionOperation.effective == metadataOperation.effective || counter.count != 8 {
|
||||
t.Fatalf("separate inheritance copies were not counted independently: inspection=(%p, %p) metadata=(%p, %p) count=%d", inspectionOperation.parent, inspectionOperation.effective, metadataOperation.parent, metadataOperation.effective, counter.count)
|
||||
path := Keys("child", "value")
|
||||
first := inspection.Metadata().History(path)
|
||||
if len(first) == 0 {
|
||||
t.Fatal("metadata projection omitted inherited history")
|
||||
}
|
||||
first[0].Origin.Locations[0].SourceID = "mutated metadata result"
|
||||
first[0].Dependencies[0].segments[0].key = "mutated metadata dependency"
|
||||
if explanation, found := inspection.Explain(path); !found || len(explanation.History) == 0 || explanation.History[0].Origin.Locations[0].SourceID == "mutated metadata result" {
|
||||
t.Fatalf("metadata result mutation leaked into explanation: %#v, %v", explanation, found)
|
||||
}
|
||||
explanation, _ := inspection.Explain(path)
|
||||
explanation.History[0].Origin.Locations[0].SourceID = "mutated explanation result"
|
||||
second := inspection.Metadata().History(path)
|
||||
if second[0].Origin.Locations[0].SourceID == "mutated explanation result" || second[0].Dependencies[0].String() == "/mutated metadata dependency" {
|
||||
t.Fatalf("explanation mutation leaked into metadata: %#v", second)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user