MCPcopy Create free account
hub / github.com/github/gh-aw / TestParseLogFileWithJSON

Function TestParseLogFileWithJSON

pkg/cli/logs_parsing_test.go:119–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestParseLogFileWithJSON(t *testing.T) {
120 // Create a temporary log file with mixed JSON and text format
121 tmpDir := testutil.TempDir(t, "test-*")
122 logFile := filepath.Join(tmpDir, "test-mixed.log")
123
124 logContent := `2024-01-15T10:30:00Z Starting workflow execution
125{"type": "message_start"}
126{"type": "content_block_delta", "delta": {"type": "text", "text": "Hello"}}
127{"type": "message_delta", "delta": {"usage": {"input_tokens": 150, "output_tokens": 200}}}
128Regular log line: tokens: 1000
129{"cost": 0.035}
1302024-01-15T10:31:30Z Workflow completed successfully`
131
132 err := os.WriteFile(logFile, []byte(logContent), 0644)
133 if err != nil {
134 t.Fatalf("Failed to create test log file: %v", err)
135 }
136
137 metrics, err := parseLogFileWithEngine(logFile, nil, false, false)
138 if err != nil {
139 t.Fatalf("parseLogFileWithEngine failed: %v", err)
140 }
141
142 // Without aw_info.json and specific engine, should return empty metrics
143 if metrics.TokenUsage != 0 {
144 t.Errorf("Expected token usage 0 (no aw_info.json), got %d", metrics.TokenUsage)
145 }
146
147 // Should have no cost without engine-specific parsing
148 if metrics.EstimatedCost != 0 {
149 t.Errorf("Expected cost 0 (no aw_info.json), got %f", metrics.EstimatedCost)
150 }
151
152 // Duration is no longer extracted from logs - using GitHub API timestamps instead
153}
154
155func TestConvertToInt(t *testing.T) {
156 tests := []struct {

Callers

nothing calls this directly

Calls 3

TempDirFunction · 0.92
parseLogFileWithEngineFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected