(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestExtractJSONMetrics(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | line string |
| 16 | verbose bool |
| 17 | expected LogMetrics |
| 18 | }{ |
| 19 | { |
| 20 | name: "Claude API format with tokens", |
| 21 | line: `{"usage": {"input_tokens": 100, "output_tokens": 50}}`, |
| 22 | expected: LogMetrics{ |
| 23 | TokenUsage: 150, |
| 24 | }, |
| 25 | }, |
| 26 | { |
| 27 | name: "Claude API format with cache tokens", |
| 28 | line: `{"usage": {"input_tokens": 100, "output_tokens": 50, "cache_creation_input_tokens": 200, "cache_read_input_tokens": 75}}`, |
| 29 | expected: LogMetrics{ |
| 30 | TokenUsage: 425, // 100 + 50 + 200 + 75 |
| 31 | }, |
| 32 | }, |
| 33 | { |
| 34 | name: "Simple token count", |
| 35 | line: `{"tokens": 250}`, |
| 36 | expected: LogMetrics{ |
| 37 | TokenUsage: 250, |
| 38 | }, |
| 39 | }, |
| 40 | { |
| 41 | name: "Cost information", |
| 42 | line: `{"cost": 0.05, "tokens": 1000}`, |
| 43 | expected: LogMetrics{ |
| 44 | TokenUsage: 1000, |
| 45 | EstimatedCost: 0.05, |
| 46 | }, |
| 47 | }, |
| 48 | { |
| 49 | name: "Delta streaming format", |
| 50 | line: `{"delta": {"usage": {"input_tokens": 10, "output_tokens": 15}}}`, |
| 51 | expected: LogMetrics{ |
| 52 | TokenUsage: 25, |
| 53 | }, |
| 54 | }, |
| 55 | { |
| 56 | name: "Billing information", |
| 57 | line: `{"billing": {"total_cost_usd": 0.12}, "tokens": 500}`, |
| 58 | expected: LogMetrics{ |
| 59 | TokenUsage: 500, |
| 60 | EstimatedCost: 0.12, |
| 61 | }, |
| 62 | }, |
| 63 | { |
| 64 | name: "Non-JSON line", |
| 65 | line: "This is not JSON", |
| 66 | expected: LogMetrics{}, |
| 67 | }, |
| 68 | { |
| 69 | name: "Empty JSON object", |
nothing calls this directly
no test coverage detected