Verify catalog capability lifecycles

This commit is contained in:
2026-10-17 18:46:47 +00:00
parent 504ea03574
commit 7a91f722fd
2 changed files with 80 additions and 4 deletions

View File

@@ -78,7 +78,8 @@ func TestCommandBuildsIndependentOptionalTrees(t *testing.T) {
}
invalid := FromEngine[int, int](nil)
invalid.ListPrompts, invalid.ListProfiles = nil, nil
invalid.ListPrompts, invalid.ListProfiles, invalid.ListBackends = nil, nil, nil
invalid.ListNamespaces, invalid.ListCollections = nil, nil
invalid.InspectPrompt, invalid.InspectProfile = nil, nil
invalid.InspectRequirements = nil
if err := newPromptTestApp(t).Register(Command(invalid)); err == nil || !strings.Contains(err.Error(), "PromptKit engine loader is nil") {
@@ -275,6 +276,68 @@ func TestCatalogCommandTreesAreIndependentAndOmitShow(t *testing.T) {
}
}
func TestAdditionalCatalogsInstallIndependentlyAndCaptureCallbacks(t *testing.T) {
for _, name := range []string{"backends", "namespaces", "collections"} {
t.Run(name, func(t *testing.T) {
calls := 0
var namespaceRequest NamespaceRequest
suite := Suite[struct{}, struct{}]{}
args := []string{"promptkit", "list", name}
switch name {
case "backends":
suite.ListBackends = func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
calls++
return commandkit.Acquired[[]string]{Value: []string{"local"}}, nil
}
case "namespaces":
suite.ListNamespaces = func(_ context.Context, request NamespaceRequest, _, _ struct{}) (commandkit.Acquired[[]string], error) {
calls++
namespaceRequest = request
return commandkit.Acquired[[]string]{Value: []string{"team"}}, nil
}
case "collections":
suite.ListCollections = func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.CollectionInfo], error) {
calls++
return commandkit.Acquired[[]promptkit.CollectionInfo]{Value: []promptkit.CollectionInfo{}}, nil
}
}
app := newPromptTestApp(t, Command(suite))
switch name {
case "backends":
suite.ListBackends = nil
case "namespaces":
suite.ListNamespaces = nil
case "collections":
suite.ListCollections = nil
}
var help bytes.Buffer
outcome := app.Execute(context.Background(), []string{"help", "promptkit", "list"}, commandkit.Streams{Out: &help, Err: io.Discard})
if outcome.Kind != commandkit.OutcomeSuccess || !strings.Contains(help.String(), "\n "+name+" ") || calls != 0 {
t.Fatalf("independent list help = (%#v, %q), calls=%d", outcome, help.String(), calls)
}
var unavailableArgs []string
switch name {
case "namespaces":
unavailableArgs = append(append([]string(nil), args...), "--namespace", "team")
case "collections":
unavailableArgs = append(append([]string(nil), args...), "--kind", "prompt")
}
if len(unavailableArgs) != 0 {
if got := app.Execute(context.Background(), unavailableArgs, commandkit.Streams{Out: io.Discard, Err: io.Discard}); got.Kind != commandkit.OutcomeUsage || calls != 0 {
t.Fatalf("unavailable %s filter = %#v, calls=%d", name, got, calls)
}
}
if got := app.Execute(context.Background(), args, commandkit.Streams{Out: io.Discard, Err: io.Discard}); got.Kind != commandkit.OutcomeSuccess || calls != 1 {
t.Fatalf("captured %s callback = (%#v, calls=%d)", name, got, calls)
}
if name == "namespaces" && (namespaceRequest.Selection.Config.Set || len(namespaceRequest.Kinds) != 0) {
t.Fatalf("omitted namespace selection = %#v", namespaceRequest)
}
})
}
}
func TestDiscoveryCommandsForwardFiltersAndRenderCollections(t *testing.T) {
var promptRequest, profileRequest, backendRequest CatalogRequest
var namespaceRequest NamespaceRequest
@@ -332,6 +395,10 @@ func TestDiscoveryCommandsForwardFiltersAndRenderCollections(t *testing.T) {
if outcome.Kind != commandkit.OutcomeSuccess || profileRequest.Filter.Mode != promptkit.NamespaceUnqualified || profileRequest.Filter.Name != "" {
t.Fatalf("profile list outcome/filter = (%#v, %#v)", outcome, profileRequest.Filter)
}
outcome, _ = run("promptkit", "list", "backends", "--all-namespaces=false")
if outcome.Kind != commandkit.OutcomeSuccess || backendRequest.Filter.Mode != promptkit.NamespaceDefault {
t.Fatalf("explicit false backend filter = (%#v, %#v)", outcome, backendRequest.Filter)
}
outcome, _ = run("promptkit", "list", "backends", "--all-namespaces")
if outcome.Kind != commandkit.OutcomeSuccess || backendRequest.Filter.Mode != promptkit.NamespaceAll {
t.Fatalf("backend list outcome/filter = (%#v, %#v)", outcome, backendRequest.Filter)
@@ -358,8 +425,8 @@ func TestDiscoveryCommandsForwardFiltersAndRenderCollections(t *testing.T) {
if outcome.Kind != commandkit.OutcomeUsage || providers != beforeConflict {
t.Fatalf("conflicting namespace filters = %#v, provider calls %d -> %d", outcome, beforeConflict, providers)
}
if providers != 5 {
t.Fatalf("catalog providers called = %d, want five", providers)
if providers != 6 {
t.Fatalf("catalog providers called = %d, want six", providers)
}
}