Add filtered PromptKit catalog commands
This commit is contained in:
@@ -275,6 +275,94 @@ func TestCatalogCommandTreesAreIndependentAndOmitShow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoveryCommandsForwardFiltersAndRenderCollections(t *testing.T) {
|
||||
var promptRequest, profileRequest, backendRequest CatalogRequest
|
||||
var namespaceRequest NamespaceRequest
|
||||
var collectionSelection ckconfig.Selection
|
||||
providers := 0
|
||||
suite := Suite[struct{}, struct{}]{
|
||||
ListPrompts: func(_ context.Context, request CatalogRequest, _, _ struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
providers++
|
||||
promptRequest = request
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "team/briefing", Version: testStringPointer("")}}}, nil
|
||||
},
|
||||
ListProfiles: func(_ context.Context, request CatalogRequest, _, _ struct{}) (commandkit.Acquired[[]string], error) {
|
||||
providers++
|
||||
profileRequest = request
|
||||
return commandkit.Acquired[[]string]{Value: []string{"default"}}, nil
|
||||
},
|
||||
ListBackends: func(_ context.Context, request CatalogRequest, _, _ struct{}) (commandkit.Acquired[[]string], error) {
|
||||
providers++
|
||||
backendRequest = request
|
||||
return commandkit.Acquired[[]string]{Value: []string{"local"}}, nil
|
||||
},
|
||||
ListNamespaces: func(_ context.Context, request NamespaceRequest, _, _ struct{}) (commandkit.Acquired[[]string], error) {
|
||||
providers++
|
||||
namespaceRequest = request
|
||||
return commandkit.Acquired[[]string]{Value: []string{"team", "root"}}, nil
|
||||
},
|
||||
ListCollections: func(_ context.Context, selection ckconfig.Selection, _, _ struct{}) (commandkit.Acquired[[]promptkit.CollectionInfo], error) {
|
||||
providers++
|
||||
collectionSelection = selection
|
||||
return commandkit.Acquired[[]promptkit.CollectionInfo]{Value: []promptkit.CollectionInfo{
|
||||
{Namespace: "team", ReleaseVersion: testStringPointer("v1")},
|
||||
{Namespace: "empty-version", ReleaseVersion: testStringPointer("")},
|
||||
{Namespace: "unversioned"},
|
||||
}}, nil
|
||||
},
|
||||
}
|
||||
app := newPromptTestApp(t, Command(suite))
|
||||
run := func(args ...string) (commandkit.Outcome, string) {
|
||||
t.Helper()
|
||||
var output bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &output, Err: io.Discard})
|
||||
return outcome, output.String()
|
||||
}
|
||||
|
||||
outcome, output := run("promptkit", "list", "prompts", "--namespace", "first", "--namespace", "team", "--all-namespaces=false", "--config", "selected.yml")
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || promptRequest.Filter != (promptkit.NamespaceFilter{Mode: promptkit.NamespaceNamed, Name: "team"}) || !promptRequest.Selection.Config.Set || promptRequest.Selection.Config.Value != "selected.yml" {
|
||||
t.Fatalf("prompt list outcome/request = (%#v, %#v), output=%q", outcome, promptRequest, output)
|
||||
}
|
||||
var promptRows []map[string]any
|
||||
if err := yaml.Unmarshal([]byte(output), &promptRows); err != nil || len(promptRows) != 1 || promptRows[0]["id"] != "team/briefing" || promptRows[0]["version"] != "" {
|
||||
t.Fatalf("prompt catalog YAML = %#v, error=%v, output=%q", promptRows, err, output)
|
||||
}
|
||||
|
||||
outcome, _ = run("promptkit", "list", "profiles", "--namespace", "")
|
||||
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")
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || backendRequest.Filter.Mode != promptkit.NamespaceAll {
|
||||
t.Fatalf("backend list outcome/filter = (%#v, %#v)", outcome, backendRequest.Filter)
|
||||
}
|
||||
outcome, output = run("promptkit", "list", "namespaces", "--kind", "prompt", "--kind", "backend")
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || !reflect.DeepEqual(namespaceRequest.Kinds, []promptkit.ResourceKind{promptkit.ResourcePrompt, promptkit.ResourceBackend}) {
|
||||
t.Fatalf("namespace list outcome/kinds = (%#v, %#v)", outcome, namespaceRequest.Kinds)
|
||||
}
|
||||
var namespaces []string
|
||||
if err := yaml.Unmarshal([]byte(output), &namespaces); err != nil || !reflect.DeepEqual(namespaces, []string{"team", "root"}) {
|
||||
t.Fatalf("namespace YAML = %#v, error=%v, output=%q", namespaces, err, output)
|
||||
}
|
||||
outcome, output = run("promptkit", "list", "collections", "--config", "collections.yml")
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || !collectionSelection.Config.Set || collectionSelection.Config.Value != "collections.yml" {
|
||||
t.Fatalf("collection list outcome/selection = (%#v, %#v)", outcome, collectionSelection)
|
||||
}
|
||||
var collections []map[string]any
|
||||
if err := yaml.Unmarshal([]byte(output), &collections); err != nil || len(collections) != 3 || collections[0]["namespace"] != "team" || collections[0]["version"] != "v1" || collections[1]["version"] != "" || collections[2]["version"] != nil {
|
||||
t.Fatalf("collection YAML = %#v, error=%v, output=%q", collections, err, output)
|
||||
}
|
||||
|
||||
beforeConflict := providers
|
||||
outcome, _ = run("promptkit", "list", "backends", "--namespace", "team", "--all-namespaces")
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalogListUsesPreparedInputAndPreflightsFormat(t *testing.T) {
|
||||
type input struct{ campaign commandkit.Supplied[string] }
|
||||
type state struct{ token int }
|
||||
|
||||
Reference in New Issue
Block a user