TestParseEventsJSONLFile_RealArtifact validates the parser against known metrics from the actual artifact in run 23883588837 (accf8264 session). Expected: 2 turns, 811242 total tokens (799195+6148 from claude-sonnet + 5442+457 from claude-haiku).
(t *testing.T)
| 187 | // from the actual artifact in run 23883588837 (accf8264 session). |
| 188 | // Expected: 2 turns, 811242 total tokens (799195+6148 from claude-sonnet + 5442+457 from claude-haiku). |
| 189 | func TestParseEventsJSONLFile_RealArtifact(t *testing.T) { |
| 190 | content := realFormatEventsLine("session.start", `{"sessionId":"accf8264","copilotVersion":"1.0.15"}`) + "\n" + |
| 191 | realFormatEventsLine("user.message", `{"content":"task prompt"}`) + "\n" + |
| 192 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"t1","toolName":"report_intent","arguments":{}}`) + "\n" + |
| 193 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"t2","toolName":"github-list_pull_requests","arguments":{}}`) + "\n" + |
| 194 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"t3","toolName":"mcpscripts-gh","arguments":{}}`) + "\n" + |
| 195 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"t4","toolName":"web_fetch","arguments":{}}`) + "\n" + |
| 196 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"t5","toolName":"bash","arguments":{}}`) + "\n" + |
| 197 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"t6","toolName":"mcpscripts-github_discussion_query","arguments":{}}`) + "\n" + |
| 198 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"t7","toolName":"playwright-browser_navigate","arguments":{}}`) + "\n" + |
| 199 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"t8","toolName":"task","arguments":{}}`) + "\n" + |
| 200 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"t9","toolName":"safeoutputs-add_comment","arguments":{}}`) + "\n" + |
| 201 | realFormatEventsLine("user.message", `{"content":"second turn"}`) + "\n" + |
| 202 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"t10","toolName":"bash","arguments":{}}`) + "\n" + |
| 203 | realFormatEventsLine("session.shutdown", `{"shutdownType":"routine","modelMetrics":{"claude-sonnet-4.6":{"requests":{"count":14,"cost":2},"usage":{"inputTokens":799195,"outputTokens":6148,"cacheReadTokens":721116,"cacheWriteTokens":0}},"claude-haiku-4.5":{"requests":{"count":1,"cost":0},"usage":{"inputTokens":5442,"outputTokens":457,"cacheReadTokens":0,"cacheWriteTokens":0}}}}`) + "\n" |
| 204 | |
| 205 | dir := t.TempDir() |
| 206 | eventsPath := filepath.Join(dir, "events.jsonl") |
| 207 | require.NoError(t, os.WriteFile(eventsPath, []byte(content), 0644)) |
| 208 | |
| 209 | metrics, err := parseEventsJSONLMetrics(eventsPath, false) |
| 210 | require.NoError(t, err, "should parse without error") |
| 211 | |
| 212 | assert.Equal(t, 2, metrics.Turns, "should detect 2 turns") |
| 213 | // (799195+6148) + (5442+457) = 805343 + 5899 = 811242 |
| 214 | assert.Equal(t, 811242, metrics.TokenUsage, "should sum tokens from both models") |
| 215 | |
| 216 | // Should have 2 sequences (one per user.message) |
| 217 | assert.Len(t, metrics.ToolSequences, 2, "should have 2 tool sequences") |
| 218 | |
| 219 | // bash appears in both turns |
| 220 | toolCounts := make(map[string]int) |
| 221 | for _, tc := range metrics.ToolCalls { |
| 222 | toolCounts[tc.Name] = tc.CallCount |
| 223 | } |
| 224 | assert.Equal(t, 2, toolCounts["bash"], "bash should be called twice (once per turn)") |
| 225 | assert.Equal(t, 1, toolCounts["report_intent"], "report_intent called once") |
| 226 | } |
| 227 | |
| 228 | // TestExtractLogMetrics_EventsJSONLPriority verifies that extractLogMetrics uses |
| 229 | // events.jsonl as the primary source when it is present, and falls back to log |
nothing calls this directly
no test coverage detected