Add PromptKit catalog commands

This commit is contained in:
2026-10-12 02:17:54 +00:00
parent c75d371ecd
commit e4cdedd6db
3 changed files with 222 additions and 9 deletions

View File

@@ -62,12 +62,89 @@ func TestCommandBuildsIndependentOptionalTrees(t *testing.T) {
}
invalid := FromEngine[int, int](nil)
invalid.ListPrompts, invalid.ListProfiles = nil, nil
invalid.InspectPrompt, invalid.InspectProfile = nil, nil
if err := newPromptTestApp(t).Register(Command(invalid)); err == nil || !strings.Contains(err.Error(), "PromptKit engine loader is nil") {
t.Fatalf("empty invalid adapter lost its construction issue: %v", err)
}
}
func TestCatalogCommandTreesAreIndependentAndOmitShow(t *testing.T) {
prompts := Command(Suite[struct{}, struct{}]{
ListPrompts: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
return commandkit.Acquired[[]promptkit.PromptIdentity]{}, nil
},
})
profiles := Command(Suite[struct{}, struct{}]{
ListProfiles: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
return commandkit.Acquired[[]string]{}, nil
},
})
for _, test := range []struct {
name string
cmd commandkit.Command
want string
omit string
}{
{name: "prompts", cmd: prompts, want: "prompts", omit: "profiles"},
{name: "profiles", cmd: profiles, want: "profiles", omit: "prompts"},
} {
t.Run(test.name, func(t *testing.T) {
app := newPromptTestApp(t, test.cmd)
var output bytes.Buffer
outcome := app.Execute(context.Background(), []string{"help", "promptkit", "list"}, commandkit.Streams{Out: &output, Err: io.Discard})
if outcome.Kind != commandkit.OutcomeSuccess || !strings.Contains(output.String(), "list") || !strings.Contains(output.String(), test.want) || strings.Contains(output.String(), test.omit) || strings.Contains(output.String(), "show") {
t.Fatalf("catalog-only help = (%#v, %q)", outcome, output.String())
}
})
}
}
func TestCatalogListUsesPreparedInputAndPreflightsFormat(t *testing.T) {
type input struct{ campaign commandkit.Supplied[string] }
type state struct{ token int }
flag := commandkit.ValueFlag(commandkit.FlagMeta{Name: "campaign"}, (*string)(nil),
func(value string) (string, error) { return value, nil },
func(target *input, value commandkit.Supplied[string]) { target.campaign = value })
newInputCalls, newStateCalls, providerCalls := 0, 0, 0
var received input
var receivedSelection ckconfig.Selection
var receivedState state
suite := Suite[input, state]{
NewInput: func() input { newInputCalls++; return input{} },
NewState: func() state { newStateCalls++; return state{token: newStateCalls} },
Selectors: []commandkit.Flag[input]{flag},
CheckInput: func(selection ckconfig.Selection, value input) error {
if !value.campaign.Set || value.campaign.Value != "spring" {
t.Errorf("checked campaign = %#v", value.campaign)
}
if !selection.Config.Set || selection.Config.Value != "" || !selection.Overlay.Set || selection.Overlay.Value != "base.yml" {
t.Errorf("checked selection = %#v", selection)
}
return nil
},
ListPrompts: func(_ context.Context, selection ckconfig.Selection, value input, gotState state) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
providerCalls++
received, receivedSelection, receivedState = value, selection, gotState
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "briefing", Version: "1"}}}, nil
},
}
app := newPromptTestApp(t, Command(suite))
var output bytes.Buffer
invalid := app.Execute(context.Background(), []string{"promptkit", "list", "prompts", "--format", "text"}, commandkit.Streams{Out: &output, Err: io.Discard})
if invalid.Kind != commandkit.OutcomeUsage || newInputCalls != 0 || newStateCalls != 0 || providerCalls != 0 || output.Len() != 0 {
t.Fatalf("invalid format preflight = %#v, factories/providers=%d/%d/%d output=%q", invalid, newInputCalls, newStateCalls, providerCalls, output.String())
}
outcome := app.Execute(context.Background(), []string{"promptkit", "list", "prompts", "--config", "", "--overlay", "base.yml", "--campaign", "spring"}, commandkit.Streams{Out: &output, Err: io.Discard})
if outcome.Kind != commandkit.OutcomeSuccess || newInputCalls != 1 || newStateCalls != 1 || providerCalls != 1 {
t.Fatalf("catalog invocation = %#v, factories/providers=%d/%d/%d output=%q", outcome, newInputCalls, newStateCalls, providerCalls, output.String())
}
if !received.campaign.Set || received.campaign.Value != "spring" || !receivedSelection.Config.Set || receivedSelection.Config.Value != "" || receivedState.token != 1 {
t.Fatalf("provider values = input %#v selection %#v state %#v", received, receivedSelection, receivedState)
}
}
func TestCommandUsesInstalledNamespaceCollisionChecks(t *testing.T) {
command := Command(Suite[struct{}, struct{}]{InspectPrompt: func(context.Context, PromptRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.PromptInspection], error) {
return commandkit.Acquired[*promptkit.PromptInspection]{}, nil