(t *testing.T)
| 271 | } |
| 272 | |
| 273 | func TestSumAICFromUsageJSONLFiles(t *testing.T) { |
| 274 | t.Run("returns error for missing file", func(t *testing.T) { |
| 275 | _, _, err := sumAICFromUsageJSONLFiles([]string{filepath.Join(t.TempDir(), "missing.jsonl")}) |
| 276 | require.Error(t, err) |
| 277 | }) |
| 278 | |
| 279 | t.Run("ignores malformed and non-aic records", func(t *testing.T) { |
| 280 | tmpDir := testutil.TempDir(t, "sum-usage-jsonl-empty") |
| 281 | filePath := filepath.Join(tmpDir, "usage.jsonl") |
| 282 | require.NoError(t, os.WriteFile(filePath, []byte("not-json\n{}\n"), 0o644)) |
| 283 | |
| 284 | total, found, err := sumAICFromUsageJSONLFiles([]string{filePath}) |
| 285 | require.NoError(t, err) |
| 286 | assert.False(t, found) |
| 287 | assert.Zero(t, total) |
| 288 | }) |
| 289 | |
| 290 | t.Run("sums explicit and computed aic across multiple files", func(t *testing.T) { |
| 291 | tmpDir := testutil.TempDir(t, "sum-usage-jsonl-mixed") |
| 292 | fileOne := filepath.Join(tmpDir, "agent_usage.jsonl") |
| 293 | fileTwo := filepath.Join(tmpDir, "detection_usage.jsonl") |
| 294 | require.NoError(t, os.WriteFile(fileOne, []byte(`{"ai_credits":1.25}`+"\n"), 0o644)) |
| 295 | require.NoError(t, os.WriteFile(fileTwo, []byte(`{"provider":"anthropic","model":"claude-sonnet-4-6","input_tokens":1000,"output_tokens":0,"cache_read_tokens":0,"cache_write_tokens":0,"reasoning_tokens":0}`+"\n"), 0o644)) |
| 296 | |
| 297 | total, found, err := sumAICFromUsageJSONLFiles([]string{fileOne, fileTwo}) |
| 298 | require.NoError(t, err) |
| 299 | assert.True(t, found) |
| 300 | assert.Greater(t, total, 1.25) |
| 301 | }) |
| 302 | } |
| 303 | |
| 304 | func TestTokenUsageSummaryMethods(t *testing.T) { |
| 305 | t.Run("TotalTokens", func(t *testing.T) { |
nothing calls this directly
no test coverage detected