(t *testing.T)
| 161 | } |
| 162 | |
| 163 | func TestFindTokenUsageFile(t *testing.T) { |
| 164 | t.Run("finds in sandbox/firewall/logs path", func(t *testing.T) { |
| 165 | tmpDir := testutil.TempDir(t, "find-token-usage") |
| 166 | logsDir := filepath.Join(tmpDir, "sandbox", "firewall", "logs", "api-proxy-logs") |
| 167 | require.NoError(t, os.MkdirAll(logsDir, 0o755)) |
| 168 | tokenFile := filepath.Join(logsDir, "token-usage.jsonl") |
| 169 | require.NoError(t, os.WriteFile(tokenFile, []byte(`{"input_tokens":1}`+"\n"), 0o644)) |
| 170 | |
| 171 | result := findTokenUsageFile(tmpDir) |
| 172 | assert.Equal(t, tokenFile, result, "should find file in primary path") |
| 173 | }) |
| 174 | |
| 175 | t.Run("finds in firewall-audit-logs directory", func(t *testing.T) { |
| 176 | tmpDir := testutil.TempDir(t, "find-token-usage") |
| 177 | logsDir := filepath.Join(tmpDir, "firewall-audit-logs", "api-proxy-logs") |
| 178 | require.NoError(t, os.MkdirAll(logsDir, 0o755)) |
| 179 | tokenFile := filepath.Join(logsDir, "token-usage.jsonl") |
| 180 | require.NoError(t, os.WriteFile(tokenFile, []byte(`{"input_tokens":1}`+"\n"), 0o644)) |
| 181 | |
| 182 | result := findTokenUsageFile(tmpDir) |
| 183 | assert.Equal(t, tokenFile, result, "should find file in firewall-audit-logs") |
| 184 | }) |
| 185 | |
| 186 | t.Run("finds usage artifact token_usage.jsonl", func(t *testing.T) { |
| 187 | tmpDir := testutil.TempDir(t, "find-token-usage") |
| 188 | usageDir := filepath.Join(tmpDir, "usage", "agent") |
| 189 | require.NoError(t, os.MkdirAll(usageDir, 0o755)) |
| 190 | tokenFile := filepath.Join(usageDir, "token_usage.jsonl") |
| 191 | require.NoError(t, os.WriteFile(tokenFile, []byte(`{"input_tokens":1}`+"\n"), 0o644)) |
| 192 | |
| 193 | result := findTokenUsageFile(tmpDir) |
| 194 | assert.Equal(t, tokenFile, result, "should prefer usage artifact token usage file") |
| 195 | }) |
| 196 | |
| 197 | t.Run("returns empty string when not found", func(t *testing.T) { |
| 198 | tmpDir := testutil.TempDir(t, "find-token-usage") |
| 199 | result := findTokenUsageFile(tmpDir) |
| 200 | assert.Empty(t, result, "should return empty string when file not found") |
| 201 | }) |
| 202 | } |
| 203 | |
| 204 | func TestAnalyzeTokenUsageAICOnly(t *testing.T) { |
| 205 | t.Run("sums agent and detection usage artifact jsonl files", func(t *testing.T) { |
nothing calls this directly
no test coverage detected