Document and validate automatic usage reporting

This commit is contained in:
2026-11-22 21:06:39 +00:00
parent a0608a53ee
commit a0cdd3d7c5
13 changed files with 188 additions and 30 deletions

View File

@@ -1005,3 +1005,22 @@ func TestSmokeUsageIsSeparateAndAliasAware(t *testing.T) {
}
}
}
func TestNarrowSuiteReportsReturnedCancellation(t *testing.T) {
suite := ckprompt.Suite[struct{}, struct{}]{InspectPrompt: func(context.Context, ckprompt.PromptRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.PromptInspection], error) {
t.Fatal("unexpected acquisition")
return commandkit.Acquired[*promptkit.PromptInspection]{}, nil
}}
command := commandkit.NewCommand(commandkit.CommandSpec[struct{}]{Name: "run", Run: func(inv commandkit.Invocation, _ struct{}) commandkit.Outcome {
return commandkit.Failure("canceled").WithCause(context.Canceled)
}})
app, err := commandkit.New(commandkit.Identity{Name: "test"}, ckprompt.Command(suite), command)
if err != nil {
t.Fatal(err)
}
var diag bytes.Buffer
out := app.Execute(context.Background(), []string{"run", "--show-tokens"}, commandkit.Streams{Err: &diag})
if !errors.Is(out.Cause, context.Canceled) || !strings.Contains(diag.String(), "Prompts: 0") || !strings.Contains(diag.String(), "ERROR: canceled") {
t.Fatalf("%#v %q", out, diag.String())
}
}