Use focused native configuration inspection
This commit is contained in:
@@ -52,6 +52,14 @@ func (v ConfigurationInspection) Metadata() configkit.Metadata {
|
|||||||
return v.source.Metadata()
|
return v.source.Metadata()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HistoricalPaths lists native historical paths within the PromptKit focus.
|
||||||
|
func (v ConfigurationInspection) HistoricalPaths() []configkit.Path {
|
||||||
|
if v.source == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return v.source.HistoricalPaths()
|
||||||
|
}
|
||||||
|
|
||||||
// Sources returns a detached list of loaded source descriptions.
|
// Sources returns a detached list of loaded source descriptions.
|
||||||
func (v ConfigurationInspection) Sources() []configkit.SourceInfo {
|
func (v ConfigurationInspection) Sources() []configkit.SourceInfo {
|
||||||
if v.source == nil {
|
if v.source == nil {
|
||||||
|
|||||||
@@ -395,6 +395,9 @@ application's root Go type and later mutation of its settings.
|
|||||||
|
|
||||||
## Stage 7 — Replace Generic Inspection Storage With The Focused View
|
## Stage 7 — Replace Generic Inspection Storage With The Focused View
|
||||||
|
|
||||||
|
Status: complete. Focused race-tested checks cover native cross-root comparison,
|
||||||
|
historical paths, and detached diagnostics; broader facade coverage follows.
|
||||||
|
|
||||||
Focus: `internal/configuration/inspection.go` and
|
Focus: `internal/configuration/inspection.go` and
|
||||||
`configuration_inspection.go`.
|
`configuration_inspection.go`.
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,50 @@ func TestCaptureUsesEffectiveSourceContexts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCapturedInspectionUsesNativeView(t *testing.T) {
|
||||||
|
type anotherApplication struct {
|
||||||
|
PromptKit promptkit.Settings `yaml:"promptkit"`
|
||||||
|
Sibling int `yaml:"sibling"`
|
||||||
|
}
|
||||||
|
definition := promptkit.Configure(configkit.Definition[application]{}, func(value *application) *promptkit.Settings { return &value.PromptKit })
|
||||||
|
first, err := configkit.Load(configkit.Bytes("first", []byte("promptkit: {application_field: first}\n")), configkit.Options[application]{Definition: definition})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
secondDefinition := promptkit.Configure(configkit.Definition[anotherApplication]{}, func(value *anotherApplication) *promptkit.Settings { return &value.PromptKit })
|
||||||
|
second, err := configkit.Load(configkit.Bytes("second", []byte("promptkit: {application_field: second}\n")), configkit.Options[anotherApplication]{Definition: secondDefinition})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
leftView, _ := first.InspectSubtree(configkit.Keys("promptkit"))
|
||||||
|
rightView, _ := second.InspectSubtree(configkit.Keys("promptkit"))
|
||||||
|
diagnostics := []configkit.Diagnostic{{Message: "warning", Primary: &configkit.Location{SourceID: "first"}, Related: []configkit.Location{{SourceID: "related"}}}}
|
||||||
|
left, err := configuration.Capture(&first.Config.PromptKit, leftView, diagnostics)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
right, err := configuration.Capture(&second.Config.PromptKit, rightView, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
diagnostics[0].Primary.SourceID = "changed"
|
||||||
|
diagnostics[0].Related[0].SourceID = "changed"
|
||||||
|
got := left.Inspection().Diagnostics()
|
||||||
|
if got[0].Primary.SourceID != "first" || got[0].Related[0].SourceID != "related" {
|
||||||
|
t.Fatalf("captured diagnostics = %+v", got)
|
||||||
|
}
|
||||||
|
got[0].Primary.SourceID = "again"
|
||||||
|
got[0].Related[0].SourceID = "again"
|
||||||
|
got = left.Inspection().Diagnostics()
|
||||||
|
if got[0].Primary.SourceID != "first" || got[0].Related[0].SourceID != "related" {
|
||||||
|
t.Fatalf("returned diagnostics aliased: %+v", got)
|
||||||
|
}
|
||||||
|
differences, err := configuration.Diff(left.Inspection(), right.Inspection())
|
||||||
|
if err != nil || len(differences) == 0 || len(left.Inspection().HistoricalPaths()) == 0 {
|
||||||
|
t.Fatalf("diff = %+v, %v", differences, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCaptureOwnsEffectiveResources(t *testing.T) {
|
func TestCaptureOwnsEffectiveResources(t *testing.T) {
|
||||||
definition := promptkit.Configure(configkit.Definition[application]{}, func(value *application) *promptkit.Settings { return &value.PromptKit })
|
definition := promptkit.Configure(configkit.Definition[application]{}, func(value *application) *promptkit.Settings { return &value.PromptKit })
|
||||||
result, err := configkit.Load(configkit.Bytes("application", []byte(`other: application
|
result, err := configkit.Load(configkit.Bytes("application", []byte(`other: application
|
||||||
|
|||||||
@@ -8,24 +8,30 @@ import (
|
|||||||
"go.maximumdirect.net/configkit"
|
"go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Inspection is the read-only subset of the retained ConfigKit result used by
|
// Inspection is the read-only subset of the native ConfigKit view used by
|
||||||
// the facade. It does not expose typed configuration or resource contexts.
|
// the facade. It does not expose typed configuration or resource contexts.
|
||||||
type Inspection interface {
|
type Inspection interface {
|
||||||
Metadata() configkit.Metadata
|
Metadata() configkit.Metadata
|
||||||
Sources() []configkit.SourceInfo
|
Sources() []configkit.SourceInfo
|
||||||
Diagnostics() []configkit.Diagnostic
|
Diagnostics() []configkit.Diagnostic
|
||||||
|
HistoricalPaths() []configkit.Path
|
||||||
Explain(configkit.Path) (configkit.Explanation, bool)
|
Explain(configkit.Path) (configkit.Explanation, bool)
|
||||||
WriteEffective(io.Writer) error
|
WriteEffective(io.Writer) error
|
||||||
WriteExplanation(io.Writer, configkit.Path) error
|
WriteExplanation(io.Writer, configkit.Path) error
|
||||||
capturedResult() *configkit.Result[document]
|
nativeView() configkit.Inspection
|
||||||
}
|
}
|
||||||
|
|
||||||
type inspectionResult struct {
|
type inspectionResult struct {
|
||||||
*configkit.Result[document]
|
configkit.Inspection
|
||||||
|
diagnostics []configkit.Diagnostic
|
||||||
}
|
}
|
||||||
|
|
||||||
func (inspection inspectionResult) capturedResult() *configkit.Result[document] {
|
func (inspection inspectionResult) nativeView() configkit.Inspection {
|
||||||
return inspection.Result
|
return inspection.Inspection
|
||||||
|
}
|
||||||
|
|
||||||
|
func (inspection inspectionResult) Diagnostics() []configkit.Diagnostic {
|
||||||
|
return ownDiagnostics(inspection.diagnostics)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inspection returns only the retained result's inspection operations.
|
// Inspection returns only the retained result's inspection operations.
|
||||||
@@ -33,19 +39,12 @@ func (state *loaded) Inspection() Inspection {
|
|||||||
if state == nil {
|
if state == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return inspectionResult{Result: state.result}
|
return inspectionResult{Inspection: state.view, diagnostics: state.diagnostics}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diff compares two captured ConfigKit results without reconstructing them.
|
// Diff compares two captured ConfigKit results without reconstructing them.
|
||||||
func Diff(left, right Inspection) ([]configkit.Difference, error) {
|
func Diff(left, right Inspection) ([]configkit.Difference, error) {
|
||||||
var leftResult, rightResult *configkit.Result[document]
|
return left.nativeView().Diff(right.nativeView())
|
||||||
if left != nil {
|
|
||||||
leftResult = left.capturedResult()
|
|
||||||
}
|
|
||||||
if right != nil {
|
|
||||||
rightResult = right.capturedResult()
|
|
||||||
}
|
|
||||||
return configkit.Diff(leftResult, rightResult)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sensitive marks credential-shaped provider values beneath PromptKit settings.
|
// Sensitive marks credential-shaped provider values beneath PromptKit settings.
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type loaded struct {
|
type loaded struct {
|
||||||
result *configkit.Result[document]
|
|
||||||
view configkit.Inspection
|
view configkit.Inspection
|
||||||
diagnostics []configkit.Diagnostic
|
diagnostics []configkit.Diagnostic
|
||||||
promptMetadata map[string][]promptInputPresence
|
promptMetadata map[string][]promptInputPresence
|
||||||
@@ -204,7 +203,6 @@ func load(main configkit.Input, underlays []configkit.Underlay) (*loaded, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("load configuration: %w", err)
|
return nil, fmt.Errorf("load configuration: %w", err)
|
||||||
}
|
}
|
||||||
state.result = result
|
|
||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user