Move integration code into optional modules

This commit is contained in:
2026-10-11 01:06:21 +00:00
parent 0d23676144
commit 476e98a463
28 changed files with 348 additions and 285 deletions

View File

@@ -94,77 +94,3 @@ func TestExecutionRefreshesHelpMetadataAfterRegistration(t *testing.T) {
t.Fatalf("usage after registration = %q", got)
}
}
func TestBridgeTreeRefreshesAfterSuccessfulRegistration(t *testing.T) {
app, err := New(Identity{Name: "example"})
if err != nil {
t.Fatal(err)
}
var output bytes.Buffer
streams := Streams{Out: &output, Err: io.Discard}
renderRootHelp := func() string {
t.Helper()
output.Reset()
outcome := app.Execute(context.Background(), []string{"--help"}, streams)
if outcome.Kind != OutcomeSuccess {
t.Fatalf("root help outcome = %#v", outcome)
}
return output.String()
}
initial := renderRootHelp()
if strings.Contains(initial, "custom") || strings.Contains(initial, "config") || strings.Contains(initial, "promptkit") {
t.Fatalf("initial help unexpectedly lists future registrations: %q", initial)
}
custom, err := NewCommand(CommandSpec[struct{}]{Name: "custom", Run: func(Invocation, struct{}) Outcome { return Success() }})
if err != nil {
t.Fatal(err)
}
if err := app.Register(custom); err != nil {
t.Fatal(err)
}
providerCalls := 0
if err := RegisterConfig(app, ConfigSuite[struct{}]{Scopes: []ConfigScope[struct{}]{{
Name: "app",
Operations: []ConfigOperation{ConfigShow},
Acquire: func(context.Context, ConfigRequest, struct{}) (Acquired[ConfigView], error) {
providerCalls++
return Acquired[ConfigView]{}, nil
},
}}}); err != nil {
t.Fatal(err)
}
if err := RegisterPromptKit(app, PromptKitSuite[struct{}]{InspectPrompt: func(context.Context, Selection, struct{}, string, string) (Acquired[*promptkit.PromptInspection], error) {
providerCalls++
return Acquired[*promptkit.PromptInspection]{}, nil
}}); err != nil {
t.Fatal(err)
}
updated := renderRootHelp()
for _, name := range []string{"custom", "config", "promptkit"} {
if !strings.Contains(updated, name) {
t.Errorf("updated help omits %q: %q", name, updated)
}
}
if providerCalls != 0 {
t.Fatalf("help invoked inspection or configuration callbacks %d times", providerCalls)
}
late, err := NewCommand(CommandSpec[struct{}]{Name: "late"})
if err != nil {
t.Fatal(err)
}
if err := app.Register(late, custom); err == nil {
t.Fatal("Register accepted a batch with an existing-name collision")
}
if err := app.Register(); err != nil {
t.Fatalf("empty registration failed: %v", err)
}
final := renderRootHelp()
if !strings.Contains(final, "custom") || !strings.Contains(final, "config") || !strings.Contains(final, "promptkit") || strings.Contains(final, "late") {
t.Fatalf("help after failed and empty registration = %q", final)
}
if outcome := app.Execute(context.Background(), []string{"custom"}, streams); outcome.Kind != OutcomeSuccess {
t.Fatalf("new command did not parse after registration: %#v", outcome)
}
}