Reuse adapter sessions during execution

This commit is contained in:
2026-10-09 01:42:03 +00:00
parent a852301801
commit a7960e5e94
6 changed files with 328 additions and 32 deletions

View File

@@ -53,6 +53,48 @@ func TestAppParseUsesRegisteredBindingsWithTheAdapter(t *testing.T) {
}
}
func TestExecutionRefreshesHelpMetadataAfterRegistration(t *testing.T) {
first, err := NewCommand(CommandSpec[struct{}]{
Name: "first",
Run: func(Invocation, struct{}) Outcome { return Success() },
})
if err != nil {
t.Fatal(err)
}
app, err := New(Identity{Name: "example"}, first)
if err != nil {
t.Fatal(err)
}
var output bytes.Buffer
current := newExecution(app, context.Background(), Streams{Out: &output, Err: io.Discard})
parsed := current.parse([]string{"first"})
if parsed.Failure != nil {
t.Fatalf("initial parse failed: %s", parsed.Failure.Message)
}
late, err := NewCommand(CommandSpec[struct{}]{
Name: "late",
Summary: "registered during execution",
Run: func(Invocation, struct{}) Outcome { return Success() },
})
if err != nil {
t.Fatal(err)
}
if err := app.Register(late); err != nil {
t.Fatal(err)
}
if got := current.renderHelp([]string{"late"}); got.Kind != OutcomeSuccess {
t.Fatalf("help after registration = %#v", got)
}
if !strings.Contains(output.String(), "registered during execution") {
t.Fatalf("help did not use registered metadata: %q", output.String())
}
if got := current.usageLine([]string{"late"}); !strings.HasPrefix(got, "Usage: example late") {
t.Fatalf("usage after registration = %q", got)
}
}
func TestBridgeTreeRefreshesAfterSuccessfulRegistration(t *testing.T) {
app, err := New(Identity{Name: "example"})
if err != nil {