Separate engine loading from inspection state

This commit is contained in:
2026-09-12 16:12:01 +00:00
parent 05812a6ad3
commit b8935e77bd
11 changed files with 120 additions and 25 deletions

View File

@@ -66,10 +66,15 @@ type Version struct {
Text string
}
// Result is a successful independently owned configuration load.
type Result[T any] struct {
Config T
// Loaded is a short-lived generic carrier for a successful configuration load.
// Inspection is frozen independently of Config and does not retain application values.
type Loaded[T any] struct {
Config T
Inspection *Inspection
}
// Inspection owns frozen load snapshots and detached query state.
type Inspection struct {
metadata Metadata
sources []SourceInfo
diagnostics []Diagnostic
@@ -84,7 +89,7 @@ type Result[T any] struct {
}
// Metadata returns detached effective presence, origin, and history records.
func (r *Result[T]) Metadata() Metadata {
func (r *Inspection) Metadata() Metadata {
if r == nil {
return Metadata{}
}
@@ -92,7 +97,7 @@ func (r *Result[T]) Metadata() Metadata {
}
// Sources returns a detached list of sources used by the load.
func (r *Result[T]) Sources() []SourceInfo {
func (r *Inspection) Sources() []SourceInfo {
if r == nil {
return nil
}
@@ -100,7 +105,7 @@ func (r *Result[T]) Sources() []SourceInfo {
}
// Diagnostics returns detached nonfatal diagnostics from the load.
func (r *Result[T]) Diagnostics() []Diagnostic {
func (r *Inspection) Diagnostics() []Diagnostic {
if r == nil {
return nil
}
@@ -110,11 +115,11 @@ func (r *Result[T]) Diagnostics() []Diagnostic {
// Load parses and strictly decodes zero or one selected source, explicitly enabled
// imports, and one selected profile. It accepts at most one Options value and
// returns no result when any error is reported.
func Load[T any](source Source, secrets SecretBinding, supplied ...Options[T]) (*Result[T], error) {
func Load[T any](source Source, secrets SecretBinding, supplied ...Options[T]) (*Loaded[T], error) {
return loadWithSecretLookup(source, secrets, os.LookupEnv, supplied...)
}
func loadWithSecretLookup[T any](source Source, secrets SecretBinding, lookup secretLookup, supplied ...Options[T]) (*Result[T], error) {
func loadWithSecretLookup[T any](source Source, secrets SecretBinding, lookup secretLookup, supplied ...Options[T]) (*Loaded[T], error) {
accumulator := diagnosticAccumulator{}
options, diagnostics := selectOptions(source, supplied)
accumulator.add(diagnostics...)