From c7ad00b9dae9ddd03c0a9abe9835fb339e710987 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 18 May 2026 21:18:26 +0000 Subject: [PATCH] fix(campaign): Filter empty paths in EdgeCaseDetector.AnalyzeFiles Co-authored-by: theRebelliousNerd <187437903+theRebelliousNerd@users.noreply.github.com> --- internal/campaign/edge_case_detector.go | 8 ++--- .../campaign/edge_case_detector_gaps_test.go | 9 ++---- internal/campaign/edge_case_detector_test.go | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/internal/campaign/edge_case_detector.go b/internal/campaign/edge_case_detector.go index 6a84513f..989c9fc1 100644 --- a/internal/campaign/edge_case_detector.go +++ b/internal/campaign/edge_case_detector.go @@ -166,6 +166,10 @@ func (d *EdgeCaseDetector) AnalyzeFiles(ctx context.Context, paths []string, int decisions := make([]FileDecision, 0, len(paths)) for _, path := range paths { + if strings.TrimSpace(path) == "" { + continue + } + select { case <-ctx.Done(): logging.Campaign("Edge case analysis interrupted: %d/%d files analyzed before timeout", len(decisions), len(paths)) @@ -800,10 +804,6 @@ func (a *EdgeCaseAnalysis) GetPreworkTasks() []string { // analyzeFile should aggressively verify ctx.Err() before executing heavy operations, // potentially mid-query, to prevent leaking goroutines or excessive delay. -// TODO: Missing Edge Case - Null/Undefined/Empty: Empty string in paths slice. -// AnalyzeFiles should filter or reject `""` paths before processing them. -// detectLanguage, matchesPath, and other file utilities behavior on `""` should be explicit. - // TODO: Missing Edge Case - Null/Undefined/Empty: IntelligenceReport fields are empty. // If an empty IntelligenceReport is passed, missing dependencies or metrics could lead // to incorrect Action decisions. diff --git a/internal/campaign/edge_case_detector_gaps_test.go b/internal/campaign/edge_case_detector_gaps_test.go index a9cd9be9..97f54d10 100644 --- a/internal/campaign/edge_case_detector_gaps_test.go +++ b/internal/campaign/edge_case_detector_gaps_test.go @@ -64,12 +64,9 @@ func TestEdgeCaseDetectorGap_EmptyPathString(t *testing.T) { paths := []string{""} decisions, _ := detector.AnalyzeFiles(context.Background(), paths, nil) - if len(decisions) != 1 { - t.Fatalf("Expected 1 decision, got %d", len(decisions)) - } - - if decisions[0].Language != "unknown" { - t.Errorf("Expected unknown language for empty path, got %s", decisions[0].Language) + // Since we fixed the bug, empty paths are filtered out. + if len(decisions) != 0 { + t.Fatalf("Expected 0 decisions for empty path, got %d", len(decisions)) } } diff --git a/internal/campaign/edge_case_detector_test.go b/internal/campaign/edge_case_detector_test.go index 30bceb09..86204d35 100644 --- a/internal/campaign/edge_case_detector_test.go +++ b/internal/campaign/edge_case_detector_test.go @@ -329,3 +329,35 @@ func TestEdgeCaseAnalysis_FileCategories(t *testing.T) { // TODO: Missing Edge Case - Extreme Values: Max file size boundaries. // Test determineAction with `LineCount = math.MaxInt32`. // Expected behavior: Should cleanly suggest ActionModularize without overflow in heuristics (e.g., complexity calc). + +func TestEdgeCaseDetector_AnalyzeFiles_EmptyPaths(t *testing.T) { + detector := NewEdgeCaseDetector(nil, nil) + ctx := context.Background() + + // Mix of valid and empty paths + paths := []string{"valid1.go", "", " ", "valid2.go"} + + decisions, err := detector.AnalyzeFiles(ctx, paths, nil) + + if err != nil { + t.Fatalf("AnalyzeFiles failed: %v", err) + } + + // We expect decisions only for "valid1.go" and "valid2.go" + if len(decisions) != 2 { + t.Fatalf("Expected 2 decisions for 2 valid paths, got %d", len(decisions)) + } + + // Verify the decisions are actually for the valid paths + pathsFound := make(map[string]bool) + for _, dec := range decisions { + pathsFound[dec.Path] = true + } + + if !pathsFound["valid1.go"] { + t.Errorf("Expected decision for 'valid1.go', but not found") + } + if !pathsFound["valid2.go"] { + t.Errorf("Expected decision for 'valid2.go', but not found") + } +}