Expose configuration metadata and findings
This commit is contained in:
@@ -288,6 +288,9 @@ func TestConfigScopeUsesNativeInspectionFacetsAndInvocationValues(t *testing.T)
|
||||
if err != nil || loaderCalls != 1 {
|
||||
t.Fatalf("scope acquisition = (%#v, %v), calls=%d", acquired, err, loaderCalls)
|
||||
}
|
||||
if acquired.Value.Metadata == nil || acquired.Value.Findings == nil || !scope.Features.PathDiscovery || !scope.Features.PathShow {
|
||||
t.Fatalf("missing native metadata or findings: %#v", acquired.Value)
|
||||
}
|
||||
var effective bytes.Buffer
|
||||
if err := acquired.Value.Effective.WriteEffective(&effective); err != nil || !strings.Contains(effective.String(), "id: briefing") {
|
||||
t.Fatalf("native effective report = %q, %v", effective.String(), err)
|
||||
@@ -931,3 +934,25 @@ type failingDiagnosticWriter struct{ err error }
|
||||
func (writer failingDiagnosticWriter) Write([]byte) (int, error) { return 0, writer.err }
|
||||
|
||||
var _ io.Writer = failingDiagnosticWriter{}
|
||||
|
||||
func TestConfigScopeRetainsFailedLoadSnapshot(t *testing.T) {
|
||||
_, loadErr := configkit.Load[map[string]any](configkit.Bytes("broken", []byte("broken: [")))
|
||||
if loadErr == nil {
|
||||
t.Fatal("fixture unexpectedly loaded")
|
||||
}
|
||||
var snapshot *configkit.LoadError
|
||||
if !errors.As(loadErr, &snapshot) {
|
||||
t.Fatalf("unexpected load error: %v", loadErr)
|
||||
}
|
||||
wrapped := errors.Join(errors.New("loader context"), loadErr)
|
||||
scope := ConfigScope(func(context.Context, ckconfig.Selection, struct{}, struct{}) (*promptkit.Engine, error) {
|
||||
return nil, wrapped
|
||||
})
|
||||
got, err := scope.Acquire(context.Background(), ckconfig.Request{}, struct{}{}, struct{}{})
|
||||
if !errors.Is(err, loadErr) || got.Value.Sources == nil || got.Value.Findings == nil || got.Value.Effective != nil || got.Value.Metadata != nil || got.Value.Explanation != nil || len(got.Diagnostics) != 0 {
|
||||
t.Fatalf("failed acquisition = %#v, %v", got, err)
|
||||
}
|
||||
if !reflect.DeepEqual(got.Value.Sources.Sources(), snapshot.Sources()) || !reflect.DeepEqual(got.Value.Findings.Records, snapshot.Diagnostics()) {
|
||||
t.Fatalf("failed snapshot = %#v", got.Value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user