Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions internal/campaign/edge_case_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ func (d *EdgeCaseDetector) AnalyzeFiles(ctx context.Context, paths []string, int
decisions := make([]FileDecision, 0, len(paths))

for _, path := range paths {
if path == "" {
continue
}
select {
case <-ctx.Done():
logging.Campaign("Edge case analysis interrupted: %d/%d files analyzed before timeout", len(decisions), len(paths))
Expand Down Expand Up @@ -541,6 +544,9 @@ func (d *EdgeCaseDetector) actionPriority(action FileAction) int {

// detectLanguage determines the language from file extension.
func (d *EdgeCaseDetector) detectLanguage(path string) string {
if path == "" {
return "unknown"
}
ext := strings.ToLower(filepath.Ext(path))
langMap := map[string]string{
".go": "go",
Expand All @@ -558,6 +564,9 @@ func (d *EdgeCaseDetector) detectLanguage(path string) string {
}

func (d *EdgeCaseDetector) matchesPath(candidate, path string) bool {
if candidate == "" || path == "" {
return candidate == path
}
if candidate == path {
return true
}
Expand Down Expand Up @@ -800,9 +809,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
Expand Down
9 changes: 3 additions & 6 deletions internal/campaign/edge_case_detector_gaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,16 @@ func TestEdgeCaseDetectorGap_AnalyzeFiles_EmptyIntelligence(t *testing.T) {
}
}

// TestEdgeCaseDetectorGap_EmptyPathString (Vector 1: Empty Paths)
// TestEdgeCaseDetectorGap_EmptyPathString (Vector 1: Empty Paths)
func TestEdgeCaseDetectorGap_EmptyPathString(t *testing.T) {
detector := NewEdgeCaseDetector(nil, nil)

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)
if len(decisions) != 0 {
t.Fatalf("Expected 0 decisions for empty path, got %d", len(decisions))
}
}

Expand Down
37 changes: 33 additions & 4 deletions internal/campaign/edge_case_detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,6 @@ func TestEdgeCaseAnalysis_FileCategories(t *testing.T) {
// Test what happens when AnalyzeFiles is called with an already canceled context.
// Expected behavior: Should return immediately with a ctx.Err() and empty decisions.

// TODO: Missing Edge Case - Null/Undefined/Empty: Empty string in paths slice.
// Test what happens when `paths` contains `""`.
// Expected behavior: The system should not panic; `detectLanguage` should return "unknown";
// `matchesPath` behavior with empty strings must be defined and validated.

// TODO: Missing Edge Case - Null/Undefined/Empty: IntelligenceReport fields are empty (but not nil).
// Test with `IntelligenceReport{FileTopology: map[string]FileInfo{}, GitChurnHotspots: []GitChurn{}}`.
Expand Down Expand Up @@ -329,3 +325,36 @@ 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_EmptyStringInPaths(t *testing.T) {
detector := NewEdgeCaseDetector(nil, nil)
ctx := context.Background()

// AnalyzeFiles takes (ctx, paths, *IntelligenceReport)
decisions, err := detector.AnalyzeFiles(ctx, []string{"", "valid/path.go", ""}, nil)

if err != nil {
t.Errorf("AnalyzeFiles with empty paths should not error: %v", err)
}
if len(decisions) != 1 {
t.Errorf("expected 1 decision for valid path, got %d", len(decisions))
} else if decisions[0].Path != "valid/path.go" {
t.Errorf("expected decision path to be 'valid/path.go', got '%s'", decisions[0].Path)
}

// test detectLanguage empty string
if lang := detector.detectLanguage(""); lang != "unknown" {
t.Errorf("detectLanguage(\"\") expected 'unknown', got '%s'", lang)
}

// test matchesPath empty string
if match := detector.matchesPath("", "path/to/file.go"); match {
t.Errorf("matchesPath(\"\", \"path/to/file.go\") should be false")
}
if match := detector.matchesPath("candidate.go", ""); match {
t.Errorf("matchesPath(\"candidate.go\", \"\") should be false")
}
if match := detector.matchesPath("", ""); !match {
t.Errorf("matchesPath(\"\", \"\") should be true")
}
}