Document and validate automatic usage reporting
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user