Skip to content

Commit 43bd334

Browse files
Saga4claude
andcommitted
fix: prevent false positive test file detection for projects in /tests/ folders
When a project is located inside a directory named "tests" (e.g., /home/user/tests/myproject), source files were incorrectly filtered as test files because the full path contained "/tests/". The fix ensures directory pattern matching (/test/, /tests/, /__tests__/) only applies to the relative path from project root, not parent directories. If the relative path cannot be computed, we now skip directory pattern matching entirely instead of checking the full path. Example: - Before: /home/user/tests/myproject/src/utils.ts was filtered as test file - After: Only checks if /src/utils.ts contains /tests/ (correctly returns false) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 2f19cdd commit 43bd334

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

codeflash/discovery/functions_to_optimize.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,13 @@ def is_test_file(file_path_normalized: str) -> bool:
839839
if any(pattern in file_lower for pattern in test_file_name_patterns):
840840
return True
841841
# Check directory patterns, but only within the project root
842-
# to avoid false positives from parent directories
843-
relative_path = file_lower
842+
# to avoid false positives from parent directories (e.g., project at /home/user/tests/myproject)
844843
if project_root_str and file_lower.startswith(project_root_str.lower()):
845844
relative_path = file_lower[len(project_root_str) :]
846-
return any(pattern in relative_path for pattern in test_dir_patterns)
845+
return any(pattern in relative_path for pattern in test_dir_patterns)
846+
# If we can't compute relative path from project root, don't check directory patterns
847+
# This avoids false positives when project is inside a folder named "tests"
848+
return False
847849
# Use directory-based filtering when tests are in a separate directory
848850
return file_path_normalized.startswith(tests_root_str + os.sep)
849851

0 commit comments

Comments
 (0)