-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtracker_activity_agent_usage_test.go
More file actions
41 lines (38 loc) · 1.77 KB
/
Copy pathtracker_activity_agent_usage_test.go
File metadata and controls
41 lines (38 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// ABOUTME: Regression test for audit-finding-1 — per-turn agent usage must survive a round-trip through activity.jsonl.
// ABOUTME: A turn_metrics line with token_input/output/cache/estimated_cost set must decode with those values intact (E2).
package tracker
import (
"testing"
)
// TestParseActivityLine_AgentTurnUsageSurvives asserts that a turn_metrics
// activity.jsonl line carries its per-turn agent usage all the way to the
// exported ActivityEntry. Before the audit-finding-1 fix the writer never
// emitted these fields (and the reader could not decode the cache/cost
// extras), so replaying a run from the audit log reported zero usage per
// turn even though the live NDJSON wire carried it (#508). The per-turn
// economics now ride on the single converged key set (#520).
func TestParseActivityLine_AgentTurnUsageSurvives(t *testing.T) {
line := `{"ts":"2026-07-28T12:00:00.000Z","source":"agent","type":"turn_metrics",` +
`"node_id":"gen_code","provider":"anthropic","model":"claude-sonnet-4-6",` +
`"token_input":100,"token_output":40,` +
`"cache_read_tokens":900,"cache_write_tokens":12,"estimated_cost":0.0033}`
entry, ok := ParseActivityLine(line)
if !ok {
t.Fatalf("ParseActivityLine rejected a well-formed turn_metrics line: %s", line)
}
if entry.TokenInput != 100 {
t.Errorf("TokenInput = %d, want 100", entry.TokenInput)
}
if entry.TokenOutput != 40 {
t.Errorf("TokenOutput = %d, want 40", entry.TokenOutput)
}
if entry.CacheReadTokens != 900 {
t.Errorf("CacheReadTokens = %d, want 900", entry.CacheReadTokens)
}
if entry.CacheWriteTokens != 12 {
t.Errorf("CacheWriteTokens = %d, want 12", entry.CacheWriteTokens)
}
if entry.EstimatedCost < 0.00329 || entry.EstimatedCost > 0.00331 {
t.Errorf("EstimatedCost = %f, want 0.0033", entry.EstimatedCost)
}
}