TestParseEventsJSONLFile verifies that parseEventsJSONLMetrics correctly extracts turns, tool calls, tool sequences, and token counts from events.jsonl using the real Copilot CLI format (nested data object, tool.execution_start events).
(t *testing.T)
| 83 | // turns, tool calls, tool sequences, and token counts from events.jsonl using |
| 84 | // the real Copilot CLI format (nested data object, tool.execution_start events). |
| 85 | func TestParseEventsJSONLFile(t *testing.T) { |
| 86 | tests := []struct { |
| 87 | name string |
| 88 | content string |
| 89 | wantTurns int |
| 90 | wantToolCalls []string // tool names that must appear in ToolCalls |
| 91 | wantTokens int // expected TokenUsage |
| 92 | wantSequences int // number of tool sequences expected |
| 93 | wantErr bool |
| 94 | }{ |
| 95 | { |
| 96 | name: "full session with real format", |
| 97 | content: realFormatEventsLine("session.start", `{"sessionId":"accf8264","copilotVersion":"1.0.15"}`) + "\n" + |
| 98 | realFormatEventsLine("session.model_change", `{"newModel":"claude-sonnet-4.6"}`) + "\n" + |
| 99 | realFormatEventsLine("user.message", `{"content":"Do the task","agentMode":"autopilot"}`) + "\n" + |
| 100 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"tc1","toolName":"bash","arguments":{"command":"ls"}}`) + "\n" + |
| 101 | realFormatEventsLine("tool.execution_complete", `{"toolCallId":"tc1","success":true,"model":"claude-sonnet-4.6"}`) + "\n" + |
| 102 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"tc2","toolName":"read_file","arguments":{"path":"main.go"}}`) + "\n" + |
| 103 | realFormatEventsLine("tool.execution_complete", `{"toolCallId":"tc2","success":true,"model":"claude-sonnet-4.6"}`) + "\n" + |
| 104 | realFormatEventsLine("user.message", `{"content":"Now verify","agentMode":"autopilot"}`) + "\n" + |
| 105 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"tc3","toolName":"bash","arguments":{"command":"go test"}}`) + "\n" + |
| 106 | realFormatEventsLine("session.shutdown", `{"shutdownType":"routine","modelMetrics":{"claude-sonnet-4.6":{"requests":{"count":14,"cost":2},"usage":{"inputTokens":799195,"outputTokens":6148,"cacheReadTokens":721116,"cacheWriteTokens":0}}}}`) + "\n", |
| 107 | wantTurns: 2, |
| 108 | wantToolCalls: []string{"bash", "read_file"}, |
| 109 | wantTokens: 805343, // 799195 + 6148 |
| 110 | wantSequences: 2, |
| 111 | }, |
| 112 | { |
| 113 | name: "session with one turn and shutdown with modelMetrics", |
| 114 | content: realFormatEventsLine("user.message", `{"content":"Do something"}`) + "\n" + |
| 115 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"tc1","toolName":"mcpscripts-gh","arguments":{}}`) + "\n" + |
| 116 | realFormatEventsLine("session.shutdown", `{"shutdownType":"routine","modelMetrics":{"claude-haiku-4.5":{"requests":{"count":1,"cost":0},"usage":{"inputTokens":5442,"outputTokens":457,"cacheReadTokens":0,"cacheWriteTokens":0}}}}`) + "\n", |
| 117 | wantTurns: 1, |
| 118 | wantToolCalls: []string{"mcpscripts-gh"}, |
| 119 | wantTokens: 5899, // 5442 + 457 |
| 120 | wantSequences: 1, |
| 121 | }, |
| 122 | { |
| 123 | name: "repeated tool calls aggregated by name", |
| 124 | content: realFormatEventsLine("user.message", `{"content":"Run tests"}`) + "\n" + |
| 125 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"tc1","toolName":"bash","arguments":{}}`) + "\n" + |
| 126 | realFormatEventsLine("tool.execution_start", `{"toolCallId":"tc2","toolName":"bash","arguments":{}}`) + "\n" + |
| 127 | realFormatEventsLine("session.shutdown", `{"shutdownType":"routine","modelMetrics":{"m":{"usage":{"inputTokens":100,"outputTokens":10}}}}`) + "\n", |
| 128 | wantTurns: 1, |
| 129 | wantToolCalls: []string{"bash"}, |
| 130 | wantTokens: 110, |
| 131 | wantSequences: 1, |
| 132 | }, |
| 133 | { |
| 134 | name: "empty file returns error", |
| 135 | content: "", |
| 136 | wantErr: true, |
| 137 | }, |
| 138 | { |
| 139 | name: "file with no recognizable events returns error", |
| 140 | content: "not json at all\njust plain text\n", |
| 141 | wantErr: true, |
| 142 | }, |
nothing calls this directly
no test coverage detected