Skip to content

Commit 4ac7e05

Browse files
authored
[WIP] Add compilation error report to compile command (#7074)
1 parent 204c79b commit 4ac7e05

File tree

4 files changed

+122
-14
lines changed

4 files changed

+122
-14
lines changed

pkg/cli/compile_command_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,31 @@ func TestPrintCompilationSummary(t *testing.T) {
106106
FailedWorkflows: []string{"workflow1.md", "workflow2.md"},
107107
},
108108
},
109+
{
110+
name: "with detailed failure information",
111+
stats: &CompilationStats{
112+
Total: 5,
113+
Errors: 3,
114+
Warnings: 1,
115+
FailureDetails: []WorkflowFailure{
116+
{Path: ".github/workflows/test1.md", ErrorCount: 1},
117+
{Path: ".github/workflows/test2.md", ErrorCount: 2},
118+
{Path: ".github/workflows/test3.md", ErrorCount: 1},
119+
},
120+
},
121+
},
122+
{
123+
name: "with multiple errors per workflow",
124+
stats: &CompilationStats{
125+
Total: 3,
126+
Errors: 5,
127+
Warnings: 0,
128+
FailureDetails: []WorkflowFailure{
129+
{Path: ".github/workflows/complex.md", ErrorCount: 3},
130+
{Path: ".github/workflows/simple.md", ErrorCount: 2},
131+
},
132+
},
133+
},
109134
}
110135

111136
for _, tt := range tests {
@@ -116,6 +141,60 @@ func TestPrintCompilationSummary(t *testing.T) {
116141
}
117142
}
118143

144+
// TestTrackWorkflowFailure tests the trackWorkflowFailure helper function
145+
func TestTrackWorkflowFailure(t *testing.T) {
146+
tests := []struct {
147+
name string
148+
workflowPath string
149+
errorCount int
150+
expectedDetails WorkflowFailure
151+
}{
152+
{
153+
name: "single error",
154+
workflowPath: ".github/workflows/test.md",
155+
errorCount: 1,
156+
expectedDetails: WorkflowFailure{
157+
Path: ".github/workflows/test.md",
158+
ErrorCount: 1,
159+
},
160+
},
161+
{
162+
name: "multiple errors",
163+
workflowPath: ".github/workflows/complex.md",
164+
errorCount: 5,
165+
expectedDetails: WorkflowFailure{
166+
Path: ".github/workflows/complex.md",
167+
ErrorCount: 5,
168+
},
169+
},
170+
}
171+
172+
for _, tt := range tests {
173+
t.Run(tt.name, func(t *testing.T) {
174+
stats := &CompilationStats{}
175+
trackWorkflowFailure(stats, tt.workflowPath, tt.errorCount)
176+
177+
// Check that FailedWorkflows was updated
178+
if len(stats.FailedWorkflows) != 1 {
179+
t.Errorf("Expected 1 failed workflow, got %d", len(stats.FailedWorkflows))
180+
}
181+
182+
// Check that FailureDetails was updated correctly
183+
if len(stats.FailureDetails) != 1 {
184+
t.Errorf("Expected 1 failure detail, got %d", len(stats.FailureDetails))
185+
}
186+
187+
detail := stats.FailureDetails[0]
188+
if detail.Path != tt.expectedDetails.Path {
189+
t.Errorf("Expected path %s, got %s", tt.expectedDetails.Path, detail.Path)
190+
}
191+
if detail.ErrorCount != tt.expectedDetails.ErrorCount {
192+
t.Errorf("Expected error count %d, got %d", tt.expectedDetails.ErrorCount, detail.ErrorCount)
193+
}
194+
})
195+
}
196+
}
197+
119198
// Note: TestHandleFileDeleted is already tested in commands_file_watching_test.go
120199

121200
// TestCompileWorkflowWithValidation_InvalidFile tests error handling

pkg/cli/compile_config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@ type CompileConfig struct {
2525
Stats bool // Display statistics table sorted by file size
2626
}
2727

28+
// WorkflowFailure represents a failed workflow with its error count
29+
type WorkflowFailure struct {
30+
Path string // File path of the workflow
31+
ErrorCount int // Number of errors in this workflow
32+
}
33+
2834
// CompilationStats tracks the results of workflow compilation
2935
type CompilationStats struct {
3036
Total int
3137
Errors int
3238
Warnings int
33-
FailedWorkflows []string // Names of workflows that failed compilation
39+
FailedWorkflows []string // Names of workflows that failed compilation (deprecated, use FailedWorkflowDetails)
40+
FailureDetails []WorkflowFailure // Detailed information about failed workflows
3441
}
3542

3643
// ValidationError represents a single validation error or warning

pkg/cli/compile_helpers.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,18 @@ func handleFileDeleted(mdFile string, verbose bool) {
398398
}
399399
}
400400

401+
// trackWorkflowFailure adds a workflow failure to the compilation statistics
402+
func trackWorkflowFailure(stats *CompilationStats, workflowPath string, errorCount int) {
403+
// Add to FailedWorkflows for backward compatibility
404+
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(workflowPath))
405+
406+
// Add detailed failure information
407+
stats.FailureDetails = append(stats.FailureDetails, WorkflowFailure{
408+
Path: workflowPath,
409+
ErrorCount: errorCount,
410+
})
411+
}
412+
401413
// printCompilationSummary prints a summary of the compilation results
402414
func printCompilationSummary(stats *CompilationStats) {
403415
if stats.Total == 0 {
@@ -410,8 +422,18 @@ func printCompilationSummary(stats *CompilationStats) {
410422
// Use different formatting based on whether there were errors
411423
if stats.Errors > 0 {
412424
fmt.Fprintln(os.Stderr, console.FormatErrorMessage(summary))
413-
// List the failed workflows
414-
if len(stats.FailedWorkflows) > 0 {
425+
// List the failed workflows with their error counts
426+
if len(stats.FailureDetails) > 0 {
427+
fmt.Fprintln(os.Stderr, console.FormatErrorMessage("Failed workflows:"))
428+
for _, failure := range stats.FailureDetails {
429+
errorWord := "error"
430+
if failure.ErrorCount > 1 {
431+
errorWord = "errors"
432+
}
433+
fmt.Fprintf(os.Stderr, " - %s (%d %s)\n", failure.Path, failure.ErrorCount, errorWord)
434+
}
435+
} else if len(stats.FailedWorkflows) > 0 {
436+
// Fallback for backward compatibility if FailureDetails is not populated
415437
fmt.Fprintln(os.Stderr, console.FormatErrorMessage("Failed workflows:"))
416438
for _, workflow := range stats.FailedWorkflows {
417439
fmt.Fprintf(os.Stderr, " - %s\n", workflow)

pkg/cli/compile_orchestrator.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
321321
errorMessages = append(errorMessages, err.Error())
322322
errorCount++
323323
stats.Errors++
324-
stats.FailedWorkflows = append(stats.FailedWorkflows, markdownFile)
324+
trackWorkflowFailure(stats, markdownFile, 1)
325325

326326
// Add to validation results
327327
result.Valid = false
@@ -350,7 +350,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
350350
errorMessages = append(errorMessages, vErr.Error())
351351
errorCount++
352352
stats.Errors++
353-
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(resolvedFile))
353+
trackWorkflowFailure(stats, resolvedFile, 1)
354354

355355
result.Valid = false
356356
result.Errors = append(result.Errors, ValidationError{
@@ -380,7 +380,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
380380
errorMessages = append(errorMessages, problems[0])
381381
errorCount++
382382
stats.Errors++
383-
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(resolvedFile))
383+
trackWorkflowFailure(stats, resolvedFile, len(problems))
384384
} else {
385385
if verbose && !jsonOutput {
386386
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage(fmt.Sprintf("Validated campaign spec %s", filepath.Base(resolvedFile))))
@@ -405,7 +405,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
405405
errorMessages = append(errorMessages, errMsg)
406406
errorCount++
407407
stats.Errors++
408-
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(resolvedFile))
408+
trackWorkflowFailure(stats, resolvedFile, 1)
409409
result.Valid = false
410410
result.Errors = append(result.Errors, ValidationError{Type: "campaign_orchestrator_error", Message: errMsg})
411411
}
@@ -447,7 +447,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
447447
errorMessages = append(errorMessages, err.Error())
448448
errorCount++
449449
stats.Errors++
450-
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(resolvedFile))
450+
trackWorkflowFailure(stats, resolvedFile, 1)
451451

452452
// Add to validation results
453453
result.Valid = false
@@ -469,7 +469,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
469469
errorMessages = append(errorMessages, err.Error())
470470
errorCount++
471471
stats.Errors++
472-
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(resolvedFile))
472+
trackWorkflowFailure(stats, resolvedFile, 1)
473473

474474
// Add to validation results
475475
result.Valid = false
@@ -701,7 +701,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
701701
}
702702
errorCount++
703703
stats.Errors++
704-
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(file))
704+
trackWorkflowFailure(stats, file, 1)
705705

706706
result.Valid = false
707707
result.Errors = append(result.Errors, ValidationError{
@@ -730,7 +730,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
730730
// Treat campaign spec problems as compilation errors for this file
731731
errorCount++
732732
stats.Errors++
733-
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(file))
733+
trackWorkflowFailure(stats, file, len(problems))
734734
} else {
735735
if verbose && !jsonOutput {
736736
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage(fmt.Sprintf("Validated campaign spec %s", filepath.Base(file))))
@@ -753,7 +753,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
753753
}
754754
errorCount++
755755
stats.Errors++
756-
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(file))
756+
trackWorkflowFailure(stats, file, 1)
757757
result.Valid = false
758758
result.Errors = append(result.Errors, ValidationError{Type: "campaign_orchestrator_error", Message: genErr.Error()})
759759
}
@@ -792,7 +792,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
792792
}
793793
errorCount++
794794
stats.Errors++
795-
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(file))
795+
trackWorkflowFailure(stats, file, 1)
796796

797797
// Add to validation results
798798
result.Valid = false
@@ -812,7 +812,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
812812
}
813813
errorCount++
814814
stats.Errors++
815-
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(file))
815+
trackWorkflowFailure(stats, file, 1)
816816

817817
// Add to validation results
818818
result.Valid = false

0 commit comments

Comments
 (0)