Report observed PromptKit invocation usage
This commit is contained in:
47
integrations/ckprompt/usage_report_test.go
Normal file
47
integrations/ckprompt/usage_report_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package ckprompt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
commandkit "go.maximumdirect.net/commandkit"
|
||||
promptkit "go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func TestUsageSummaryPreservesNativeEvidence(t *testing.T) {
|
||||
count := func(n int, known, complete bool) promptkit.ObservedTokenCount {
|
||||
return promptkit.ObservedTokenCount{Value: n, Known: known, Complete: complete}
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
summary promptkit.ExecutionGroupSummary
|
||||
smoke bool
|
||||
want []string
|
||||
absent []string
|
||||
}{
|
||||
{name: "empty", summary: new(promptkit.ExecutionGroup).Snapshot(), want: []string{"Prompts: 0", "Prompt tokens: 0", "Cost: USD 0", "Terminal coverage: complete"}, absent: []string{"Repair calls:", "Cache hit ratio:", "[provider]"}},
|
||||
{name: "unknown", summary: promptkit.ExecutionGroupSummary{Members: []promptkit.ExecutionGroupMember{{RunID: "a"}}}, smoke: true, want: []string{"Prompts: 1", "Prompt tokens: unknown", "Cost: unknown", "Terminal coverage: incomplete", "Smoke-test usage is reported separately"}},
|
||||
{name: "known", summary: promptkit.ExecutionGroupSummary{Members: []promptkit.ExecutionGroupMember{{}, {}}, TerminalCoverageComplete: true, RepairCalls: 2, Usage: promptkit.ObservedTokenUsage{PromptTokens: count(8, true, true), CompletionTokens: count(9, true, false), ReasoningTokens: count(0, true, true), CachedTokens: count(1, true, true)}, CostUSD: promptkit.ObservedCost{Value: 0.012345678, Known: true, Source: promptkit.CostSource("mixed")}}, want: []string{"Prompts: 2", "Repair calls: 2", "Completion tokens: 9 (incomplete)", "Reasoning tokens: 0", "Cache hit ratio: 12.5%", "Cost: USD 0.0123457 (incomplete subtotal) [mixed]"}},
|
||||
{name: "configured zero", summary: promptkit.ExecutionGroupSummary{CostUSD: promptkit.ObservedCost{Known: true, Complete: true, Source: promptkit.CostSource("configured_zero")}}, want: []string{"Cost: USD 0 [configured_zero]"}},
|
||||
{name: "provider zero", summary: promptkit.ExecutionGroupSummary{CostUSD: promptkit.ObservedCost{Known: true, Complete: true, Source: promptkit.CostSource("provider")}}, want: []string{"Cost: USD 0 [provider]"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
report := usageReport(tc.summary, tc.smoke)
|
||||
var out bytes.Buffer
|
||||
if err := commandkit.RenderReport(&out, report, commandkit.FormatText); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range tc.want {
|
||||
if !strings.Contains(out.String(), want) {
|
||||
t.Errorf("missing %q in %q", want, out.String())
|
||||
}
|
||||
}
|
||||
for _, absent := range tc.absent {
|
||||
if strings.Contains(out.String(), absent) {
|
||||
t.Errorf("unexpected %q in %q", absent, out.String())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user