Cover focused configuration inspection behavior
This commit is contained in:
@@ -591,6 +591,9 @@ serialization, another load, or knowledge of internal types.
|
||||
|
||||
## Stage 14 — Add Focused Inspection Integration Coverage
|
||||
|
||||
Status: complete. Focused facade inspection tests passed under the race
|
||||
detector, including redaction, frozen history, diagnostics, and comparison.
|
||||
|
||||
Focus: the public configuration-inspection facade, reusing minimal fixtures.
|
||||
|
||||
1. Verify focused effective output, native redaction including ancestor and
|
||||
|
||||
204
focused_inspection_integration_test.go
Normal file
204
focused_inspection_integration_test.go
Normal file
@@ -0,0 +1,204 @@
|
||||
package promptkit_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
type focusedInspectionRoot struct {
|
||||
Sibling string `yaml:"sibling"`
|
||||
PromptKit *promptkit.Settings `yaml:"promptkit"`
|
||||
}
|
||||
|
||||
func TestFocusedInspectionReturnsDetachedDiagnostics(t *testing.T) {
|
||||
var resolves, validates atomic.Int64
|
||||
definition := integrationDefinition(&resolves, &validates)
|
||||
result, err := configkit.Load(configkit.Bytes("diagnostics", []byte(integrationDocument)), configkit.Options[integrationApplication]{Definition: definition})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
engine, err := promptkit.NewFromConfig(result, promptkit.RuntimeConfig{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
view, err := engine.InspectConfiguration()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
first := view.Diagnostics()
|
||||
if len(first) != 1 || first[0].Primary == nil {
|
||||
t.Fatalf("diagnostics = %+v", first)
|
||||
}
|
||||
original := first[0].Primary.SourceID
|
||||
first[0].Primary.SourceID = "changed"
|
||||
again := view.Diagnostics()
|
||||
if again[0].Primary.SourceID != original {
|
||||
t.Fatalf("diagnostics alias caller mutation: %+v", again)
|
||||
}
|
||||
}
|
||||
|
||||
func focusedInspection(t *testing.T, source string, sensitive func(configkit.Path) bool) (promptkit.ConfigurationInspection, *configkit.Result[focusedInspectionRoot]) {
|
||||
t.Helper()
|
||||
definition := promptkit.Configure(configkit.Definition[focusedInspectionRoot]{Sensitive: sensitive}, func(value *focusedInspectionRoot) *promptkit.Settings { return value.PromptKit })
|
||||
result, err := configkit.Load(configkit.Bytes("focused", []byte(source)), configkit.Options[focusedInspectionRoot]{Definition: definition})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
engine, err := promptkit.NewFromConfig(result, promptkit.RuntimeConfig{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
view, err := engine.InspectConfiguration()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return view, result
|
||||
}
|
||||
|
||||
func TestFocusedInspectionRetainsNativeEvidence(t *testing.T) {
|
||||
view, result := focusedInspection(t, "sibling: private\npromptkit:\n app_secret: hidden\n app_value: original\n", func(path configkit.Path) bool {
|
||||
return path.String() == "/sibling" || path.String() == "/promptkit/app_secret"
|
||||
})
|
||||
result.Config.PromptKit.Application["app_value"] = "mutated"
|
||||
var rendered bytes.Buffer
|
||||
if err := view.WriteEffective(&rendered); err != nil || !strings.Contains(rendered.String(), "original") || strings.Contains(rendered.String(), "hidden") || strings.Contains(rendered.String(), "mutated") || strings.Contains(rendered.String(), "sibling") {
|
||||
t.Fatalf("focused effective = %q, %v", rendered.String(), err)
|
||||
}
|
||||
if _, ok := view.Metadata().Lookup(configkit.Keys("sibling")); !ok {
|
||||
t.Fatal("unfiltered metadata omitted sibling")
|
||||
}
|
||||
sibling, ok := view.Explain(configkit.Keys("sibling"))
|
||||
if !ok || !sibling.Effective.Redacted {
|
||||
t.Fatalf("outside-focus explanation = %+v, %t", sibling, ok)
|
||||
}
|
||||
if _, ok := view.Explain(configkit.Keys("promptkit")); !ok {
|
||||
t.Fatal("focus explanation missing")
|
||||
}
|
||||
if _, ok := view.Explain(configkit.Path{}); !ok {
|
||||
t.Fatal("whole-application explanation missing")
|
||||
}
|
||||
if len(view.Sources()) == 0 {
|
||||
t.Fatal("native source catalog missing")
|
||||
}
|
||||
for _, path := range view.HistoricalPaths() {
|
||||
if path.String() != "/promptkit" && !strings.HasPrefix(path.String(), "/promptkit/") {
|
||||
t.Fatalf("out of scope history: %v", path)
|
||||
}
|
||||
}
|
||||
if len(view.HistoricalPaths()) == 0 {
|
||||
t.Fatal("focused history empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFocusedInspectionHonorsAncestorSensitivityAndHistory(t *testing.T) {
|
||||
redacted, _ := focusedInspection(t, "promptkit: {app_value: secret-value}\n", func(path configkit.Path) bool { return path.String() == "/promptkit" })
|
||||
var rendered bytes.Buffer
|
||||
if err := redacted.WriteEffective(&rendered); err != nil || strings.Contains(rendered.String(), "secret-value") || !strings.Contains(rendered.String(), "REDACTED") {
|
||||
t.Fatalf("ancestor redaction = %q, %v", rendered.String(), err)
|
||||
}
|
||||
definition := promptkit.Configure(configkit.Definition[focusedInspectionRoot]{}, func(value *focusedInspectionRoot) *promptkit.Settings { return value.PromptKit })
|
||||
lower := configkit.Input{Source: configkit.Bytes("lower", []byte("promptkit: {historical: old}\n"))}
|
||||
main := configkit.Input{Source: configkit.Bytes("main", []byte("promptkit: null\n"))}
|
||||
result, err := configkit.LoadLayered(main, configkit.LayeredOptions[focusedInspectionRoot]{Definition: definition, Underlays: []configkit.Underlay{{Inputs: []configkit.Input{lower}}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
engine, err := promptkit.NewFromConfig(result, promptkit.RuntimeConfig{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
view, err := engine.InspectConfiguration()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := configkit.Keys("promptkit", "historical")
|
||||
if len(view.Metadata().History(path)) == 0 {
|
||||
t.Fatal("historical-only field has no native history")
|
||||
}
|
||||
found := false
|
||||
for _, item := range view.HistoricalPaths() {
|
||||
if item.String() == path.String() {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("historical path missing: %+v", view.HistoricalPaths())
|
||||
}
|
||||
}
|
||||
|
||||
func TestFocusedInspectionAbsenceNullAndCrossTypeDiff(t *testing.T) {
|
||||
type noSection struct {
|
||||
Sibling string `yaml:"sibling"`
|
||||
}
|
||||
missing, err := configkit.Load[noSection](configkit.Bytes("absent", []byte("sibling: before\n")))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
missingEngine, err := promptkit.NewFromConfig(missing, promptkit.RuntimeConfig{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
absent, err := missingEngine.InspectConfiguration()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var output bytes.Buffer
|
||||
if err := absent.WriteEffective(&output); err == nil || output.Len() != 0 {
|
||||
t.Fatalf("absent output = %q, %v", output.String(), err)
|
||||
}
|
||||
nullView, _ := focusedInspection(t, "sibling: before\npromptkit: null\n", nil)
|
||||
if err := nullView.WriteEffective(&output); err != nil || strings.TrimSpace(output.String()) != "null" {
|
||||
t.Fatalf("null output = %q, %v", output.String(), err)
|
||||
}
|
||||
differences, err := absent.Diff(nullView)
|
||||
if err != nil || len(differences) == 0 {
|
||||
t.Fatalf("absent/null diff = %+v, %v", differences, err)
|
||||
}
|
||||
changed, _ := focusedInspection(t, "sibling: before\npromptkit: {label: one}\n", nil)
|
||||
if differences, err := absent.Diff(changed); err != nil || len(differences) == 0 {
|
||||
t.Fatalf("added scope diff = %+v, %v", differences, err)
|
||||
}
|
||||
if differences, err := changed.Diff(absent); err != nil || len(differences) == 0 {
|
||||
t.Fatalf("removed scope diff = %+v, %v", differences, err)
|
||||
}
|
||||
otherSibling, _ := focusedInspection(t, "sibling: after\npromptkit: {label: one}\n", nil)
|
||||
differences, err = changed.Diff(otherSibling)
|
||||
if err != nil || len(differences) != 0 {
|
||||
t.Fatalf("sibling-only diff = %+v, %v", differences, err)
|
||||
}
|
||||
type differentRoot struct {
|
||||
PromptKit promptkit.Settings `yaml:"promptkit"`
|
||||
Extra bool `yaml:"extra"`
|
||||
}
|
||||
definition := promptkit.Configure(configkit.Definition[differentRoot]{}, func(value *differentRoot) *promptkit.Settings { return &value.PromptKit })
|
||||
result, err := configkit.Load(configkit.Bytes("other", []byte("promptkit: {label: two}\n")), configkit.Options[differentRoot]{Definition: definition})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
engine, err := promptkit.NewFromConfig(result, promptkit.RuntimeConfig{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
other, err := engine.InspectConfiguration()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
differences, err = changed.Diff(other)
|
||||
if err != nil || len(differences) == 0 {
|
||||
t.Fatalf("cross-root diff = %+v, %v", differences, err)
|
||||
}
|
||||
var zero promptkit.ConfigurationInspection
|
||||
if _, err := zero.Diff(changed); !errors.Is(err, promptkit.ErrInvalidConfig) || zero.HistoricalPaths() != nil {
|
||||
t.Fatalf("zero view: %v", err)
|
||||
}
|
||||
writeErr := errors.New("writer failure")
|
||||
if err := changed.WriteEffective(failingInspectionWriter{err: writeErr}); !errors.Is(err, writeErr) {
|
||||
t.Fatalf("writer error = %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user