|
3 | 3 | package cli |
4 | 4 |
|
5 | 5 | import ( |
| 6 | + "os" |
| 7 | + "path/filepath" |
6 | 8 | "testing" |
7 | 9 | "time" |
8 | 10 | ) |
@@ -908,3 +910,53 @@ func TestDeriveRunClassification(t *testing.T) { |
908 | 910 | }) |
909 | 911 | } |
910 | 912 | } |
| 913 | + |
| 914 | +// TestBuildLogsDataEngineCountsFromAwInfo verifies that engine_counts in the summary |
| 915 | +// is populated from aw_info.json data (the authoritative engine source), not from |
| 916 | +// lock file string matching. |
| 917 | +func TestBuildLogsDataEngineCountsFromAwInfo(t *testing.T) { |
| 918 | + createRunDir := func(engineID string) string { |
| 919 | + dir := t.TempDir() |
| 920 | + awInfo := `{"engine_id":"` + engineID + `","engine_name":"Test","workflow_name":"test","created_at":"2024-01-01T00:00:00Z"}` |
| 921 | + if err := os.WriteFile(filepath.Join(dir, "aw_info.json"), []byte(awInfo), 0600); err != nil { |
| 922 | + t.Fatalf("Failed to write aw_info.json: %v", err) |
| 923 | + } |
| 924 | + return dir |
| 925 | + } |
| 926 | + |
| 927 | + claudeDir := createRunDir("claude") |
| 928 | + claudeDir2 := createRunDir("claude") |
| 929 | + copilotDir := createRunDir("copilot") |
| 930 | + |
| 931 | + processedRuns := []ProcessedRun{ |
| 932 | + {Run: WorkflowRun{DatabaseID: 1, WorkflowName: "wf-claude-1", LogsPath: claudeDir}}, |
| 933 | + {Run: WorkflowRun{DatabaseID: 2, WorkflowName: "wf-claude-2", LogsPath: claudeDir2}}, |
| 934 | + {Run: WorkflowRun{DatabaseID: 3, WorkflowName: "wf-copilot", LogsPath: copilotDir}}, |
| 935 | + } |
| 936 | + |
| 937 | + data := buildLogsData(processedRuns, "/tmp/logs", nil) |
| 938 | + |
| 939 | + if data.Summary.EngineCounts == nil { |
| 940 | + t.Fatal("EngineCounts should not be nil when runs have aw_info.json") |
| 941 | + } |
| 942 | + if got := data.Summary.EngineCounts["claude"]; got != 2 { |
| 943 | + t.Errorf("Expected 2 claude runs, got %d", got) |
| 944 | + } |
| 945 | + if got := data.Summary.EngineCounts["copilot"]; got != 1 { |
| 946 | + t.Errorf("Expected 1 copilot run, got %d", got) |
| 947 | + } |
| 948 | + // Verify individual RunData.Agent fields also reflect the engine from aw_info.json |
| 949 | + agentsByID := make(map[int64]string) |
| 950 | + for _, run := range data.Runs { |
| 951 | + agentsByID[run.DatabaseID] = run.Agent |
| 952 | + } |
| 953 | + if agentsByID[1] != "claude" { |
| 954 | + t.Errorf("Run 1: expected agent=claude, got %q", agentsByID[1]) |
| 955 | + } |
| 956 | + if agentsByID[2] != "claude" { |
| 957 | + t.Errorf("Run 2: expected agent=claude, got %q", agentsByID[2]) |
| 958 | + } |
| 959 | + if agentsByID[3] != "copilot" { |
| 960 | + t.Errorf("Run 3: expected agent=copilot, got %q", agentsByID[3]) |
| 961 | + } |
| 962 | +} |
0 commit comments