Share inspection finalization for load outcomes

This commit is contained in:
2026-12-05 15:55:28 +00:00
parent 34bf78de83
commit de50550eea
6 changed files with 57 additions and 5 deletions

View File

@@ -114,6 +114,8 @@ requiring approval again, execution sequencing, or unrelated safety guarantees.
## Stage 2 — Add checkpoint state and share inspection finalization
**Complete.**
Read `internal/engine/load.go`, `load_result.go`, `diagnostic.go`, `secret.go`,
`inspection_view.go`, and the retained-node counter in `history.go`.

View File

@@ -15,6 +15,15 @@ import (
type LoadError struct {
diagnostics []Diagnostic
sources []SourceInfo
inspection *Inspection
}
// Inspection returns the frozen reporting snapshot retained by the failed load.
func (e *LoadError) Inspection() *Inspection {
if e == nil {
return nil
}
return e.inspection
}
// Error implements error without rendering diagnostic messages or input values.

View File

@@ -85,6 +85,13 @@ func TestLoadedConfigurationIsSeparateFromInspection(t *testing.T) {
if loaded.Inspection == nil {
t.Fatal("inspection is nil")
}
view, ok := NewInspectionView(loaded.Inspection, Path{})
if !ok || view.Stage() != InspectionStageValidated {
t.Fatalf("successful inspection checkpoint = %q, available = %v", view.Stage(), ok)
}
if (InspectionView{}).Stage() != "" || (*LoadError)(nil).Inspection() != nil {
t.Fatal("unavailable inspection unexpectedly has a checkpoint")
}
loaded.Config.Value = "mutated"
var effective bytes.Buffer

View File

@@ -26,6 +26,13 @@ func NewInspectionView(inspection *Inspection, scope Path) (InspectionView, bool
func (v InspectionView) Inspection() *Inspection { return v.inspection }
func (v InspectionView) Stage() InspectionStage {
if v.inspection == nil {
return ""
}
return v.inspection.stage
}
func (v InspectionView) Diff(other InspectionView) ([]Difference, error) {
if v.inspection == nil || other.inspection == nil || v.scope.String() != other.scope.String() {
return nil, errors.New("configkit: diff inspection scope unavailable or mismatched")

View File

@@ -84,8 +84,22 @@ type Loaded[T any] struct {
Inspection *Inspection
}
// InspectionStage identifies the completed processing represented by a snapshot.
type InspectionStage string
const (
InspectionStageMain InspectionStage = "main"
InspectionStageComposed InspectionStage = "composed"
InspectionStageInherited InspectionStage = "inherited"
InspectionStageDecoded InspectionStage = "decoded"
InspectionStageOverridden InspectionStage = "overridden"
InspectionStageResolved InspectionStage = "resolved"
InspectionStageValidated InspectionStage = "validated"
)
// Inspection owns frozen load snapshots and detached query state.
type Inspection struct {
stage InspectionStage
metadata Metadata
history *historyModel
sources []SourceInfo

View File

@@ -115,18 +115,31 @@ func publishLoadResult[T any](schema *schemaDescriptor, definition Definition[T]
configuration, issue := detachLoadConfiguration(schema, resolved.configuration, cloneValidatedSecrets)
if issue != nil {
accumulator.add(*issue)
return nil, accumulator.loadError()
failure := accumulator.loadError()
finishInspection(schema, definition.Secret, resolved.versionEvidence, resolved.contexts, inspection, references, accumulator, failure, InspectionStageResolved)
failure.inspection = inspection
return nil, failure
}
finishInspection(schema, definition.Secret, resolved.versionEvidence, resolved.contexts, inspection, references, accumulator, nil, InspectionStageValidated)
return &Loaded[T]{Config: configuration, Inspection: inspection}, nil
}
func finishInspection(schema *schemaDescriptor, predicate func(Path) bool, evidence []*sourceVersionEvidence, contexts map[string]ResourceContext, inspection *Inspection, references map[string]string, accumulator *diagnosticAccumulator, failure *LoadError, checkpoint InspectionStage) {
metadata := inspection.metadata
secrets := classifySecretPathsWithEvidence(schema, definition.Secret, metadata, resolved.versionEvidence)
sources := sourceInfosWithVersionEvidence(accumulator.sources, resolved.versionEvidence, secrets, false)
secrets := classifySecretPathsWithEvidence(schema, predicate, metadata, evidence)
var sources []SourceInfo
if failure != nil {
sources = failure.sources
} else {
sources = sourceInfosWithVersionEvidence(accumulator.sources, evidence, secrets, false)
}
inspection.stage = checkpoint
inspection.metadata = metadata
inspection.sources = sources
inspection.contexts = cloneResourceContexts(resolved.contexts)
inspection.contexts = cloneResourceContexts(contexts)
inspection.diagnostics = canonicalDiagnostics(accumulator.diagnostics)
inspection.secrets = secrets
inspection.secretReferences = cloneSecretReferences(references)
return &Loaded[T]{Config: configuration, Inspection: inspection}, nil
}
func diagnosticFromSchemaIssue(issue *schemaIssue) Diagnostic {