Adopt PromptKit usage and backend evidence
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package ckprompt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
commandkit "go.maximumdirect.net/commandkit"
|
||||
"strings"
|
||||
"testing"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
promptkit "go.maximumdirect.net/promptkit"
|
||||
@@ -215,3 +219,51 @@ func containsSmokeKey(value any, want string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestSmokeUsageReasoningAndCacheRatioRepresentations(t *testing.T) {
|
||||
known := func(n int) promptkit.ObservedTokenCount {
|
||||
return promptkit.ObservedTokenCount{Value: n, Known: true, Complete: true}
|
||||
}
|
||||
usage := promptkit.ObservedTokenUsage{PromptTokens: known(8), CachedTokens: known(1), ReasoningTokens: known(3)}
|
||||
projected := smokeUsageFromNative(usage)
|
||||
if projected.CacheHitRatio == nil || *projected.CacheHitRatio != 0.125 || projected.ReasoningTokens.Value != 3 {
|
||||
t.Fatalf("usage=%#v", projected)
|
||||
}
|
||||
usage.CachedTokens = known(0)
|
||||
zero := smokeUsageFromNative(usage)
|
||||
if zero.CacheHitRatio == nil || *zero.CacheHitRatio != 0 {
|
||||
t.Fatalf("zero ratio=%#v", zero)
|
||||
}
|
||||
usage.PromptTokens = promptkit.ObservedTokenCount{}
|
||||
if smokeUsageFromNative(usage).CacheHitRatio != nil {
|
||||
t.Fatal("unknown ratio is present")
|
||||
}
|
||||
report := smokeReportDTO{Kind: promptkit.SmokeTestAuthentication, Supported: true, Usage: projected, Attempts: []smokeAttemptDTO{{Usage: zero}}}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
value any
|
||||
tmpl *template.Template
|
||||
}{
|
||||
{"single", report, smokeTextTemplate},
|
||||
{"aggregate", smokeAggregateDTO{Tests: []smokeResultDTO{{Kind: promptkit.SmokeTestAuthentication, Report: &report}}}, smokeAggregateTextTemplate},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
for _, format := range []commandkit.Format{commandkit.FormatText, commandkit.FormatYAML, commandkit.FormatJSON} {
|
||||
var out bytes.Buffer
|
||||
if err := commandkit.RenderReport(&out, commandkit.Report{Value: tc.value, TextTemplate: tc.tmpl}, format); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
text := out.String()
|
||||
if !strings.Contains(text, "reasoning_tokens") || !strings.Contains(text, "cache_hit_ratio") || !strings.Contains(text, "attempts") || !strings.Contains(text, "supported") {
|
||||
t.Fatalf("missing evidence: %s", text)
|
||||
}
|
||||
if format == commandkit.FormatText && (!strings.Contains(text, "12.5%") || !strings.Contains(text, "0.0%")) {
|
||||
t.Fatalf("ratios: %s", text)
|
||||
}
|
||||
if format != commandkit.FormatText && !strings.Contains(text, "0.125") {
|
||||
t.Fatalf("raw ratio: %s", text)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user