Include available choices in unknown scope diagnostics

This commit is contained in:
2026-10-07 16:50:23 +00:00
parent d5f544d14d
commit c26d279b4f
3 changed files with 37 additions and 1 deletions

View File

@@ -255,3 +255,32 @@ func TestRequiredConfigSelectorOnlyAppliesToSelectedScopes(t *testing.T) {
}
}
}
func TestUnknownConfigScopeReportsChoicesWithoutRuntimeWork(t *testing.T) {
for _, tc := range []struct {
names []string
scope []string
choices string
}{
{[]string{"promptkit"}, nil, "available: promptkit"},
{[]string{"zeta", "alpha", "promptkit", "app"}, []string{"--scope", "unknown"}, "available: app, promptkit, alpha, zeta"},
} {
runtimeCalls := 0
suite := ConfigSuite[struct{}]{NewContext: func() struct{} { runtimeCalls++; return struct{}{} }}
for _, name := range tc.names {
suite.Scopes = append(suite.Scopes, ConfigScope[struct{}]{Name: name, Operations: []ConfigOperation{ConfigValidate}, Acquire: func(context.Context, ConfigRequest, struct{}) (Acquired[ConfigView], error) {
runtimeCalls++
return Acquired[ConfigView]{}, nil
}})
}
app, _ := New(Identity{Name: "example"})
if err := RegisterConfig(app, suite); err != nil {
t.Fatal(err)
}
var out, diagnostics bytes.Buffer
result := app.Execute(context.Background(), append([]string{"config", "validate"}, tc.scope...), Streams{Out: &out, Err: &diagnostics})
if result.Kind != OutcomeUsage || runtimeCalls != 0 || out.Len() != 0 || !strings.Contains(diagnostics.String(), tc.choices) {
t.Fatalf("result=%#v calls=%d out=%q diagnostics=%q", result, runtimeCalls, out.String(), diagnostics.String())
}
}
}