MCPcopy Create free account
hub / github.com/Quorinex/Kiro-Go / TestPromptCacheTrackerComputeAndUpdate

Function TestPromptCacheTrackerComputeAndUpdate

proxy/cache_tracker_test.go:9–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestPromptCacheTrackerComputeAndUpdate(t *testing.T) {
10 tracker := newPromptCacheTracker(time.Hour)
11 longSystem := strings.Repeat("You are a helpful coding assistant with deep knowledge of Go, Rust, Python, and TypeScript. ", 80)
12 req := &ClaudeRequest{
13 Model: "claude-sonnet-4.5",
14 System: []interface{}{
15 map[string]interface{}{
16 "type": "text",
17 "text": longSystem,
18 "cache_control": map[string]interface{}{
19 "type": "ephemeral",
20 },
21 },
22 },
23 Messages: []ClaudeMessage{{Role: "user", Content: "hello world"}},
24 }
25
26 profile := tracker.BuildClaudeProfile(req, 120)
27 if profile == nil {
28 t.Fatalf("expected cache profile to be built")
29 }
30
31 first := tracker.Compute("acct-1", profile)
32 if first.CacheCreationInputTokens <= 0 {
33 t.Fatalf("expected first request to create cache tokens, got %+v", first)
34 }
35 if first.CacheReadInputTokens != 0 {
36 t.Fatalf("expected first request to have zero cache reads, got %+v", first)
37 }
38
39 tracker.Update("acct-1", profile)
40 second := tracker.Compute("acct-1", profile)
41 if second.CacheReadInputTokens <= 0 {
42 t.Fatalf("expected repeated request to read cache tokens, got %+v", second)
43 }
44 if second.CacheCreationInputTokens != 0 {
45 t.Fatalf("expected repeated request to avoid cache creation, got %+v", second)
46 }
47}
48
49func TestBuildClaudeUsageMapIncludesCacheFields(t *testing.T) {
50 usage := promptCacheUsage{

Callers

nothing calls this directly

Calls 4

newPromptCacheTrackerFunction · 0.85
BuildClaudeProfileMethod · 0.80
ComputeMethod · 0.80
UpdateMethod · 0.80

Tested by

no test coverage detected