diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index b1fdae6..07f39b7 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -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`. diff --git a/internal/engine/diagnostic.go b/internal/engine/diagnostic.go index ecf3283..b8fc953 100644 --- a/internal/engine/diagnostic.go +++ b/internal/engine/diagnostic.go @@ -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. diff --git a/internal/engine/independence_test.go b/internal/engine/independence_test.go index 185436a..424635e 100644 --- a/internal/engine/independence_test.go +++ b/internal/engine/independence_test.go @@ -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 diff --git a/internal/engine/inspection_view.go b/internal/engine/inspection_view.go index 7ad0624..e4f4eab 100644 --- a/internal/engine/inspection_view.go +++ b/internal/engine/inspection_view.go @@ -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") diff --git a/internal/engine/load.go b/internal/engine/load.go index d5b2da5..03a5419 100644 --- a/internal/engine/load.go +++ b/internal/engine/load.go @@ -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 diff --git a/internal/engine/load_result.go b/internal/engine/load_result.go index 3402e3d..ec463c1 100644 --- a/internal/engine/load_result.go +++ b/internal/engine/load_result.go @@ -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 {