Skip to content

Conversation

@Saga4
Copy link
Contributor

@Saga4 Saga4 commented Jan 31, 2026

Summary

  • Fixed critical bug where all functions were incorrectly filtered as "test functions" when tests_root equals module_root or project_root
  • Introduced pattern-based test file detection that checks filename patterns (.test., .spec., _test., _spec.) and directory patterns (/test/, /tests/, /__tests__/)
  • Directory patterns are only checked within the project root to avoid false positives from parent directories (e.g., when repo is located in /path/tests/my-project)

Problem

When auto-detection sets tests_root to the same value as module_root or project_root (common in monorepos and projects without dedicated test directories), the filter condition file_path.startswith(tests_root + os.sep) matches ALL source files, causing them all to be filtered out as "test functions".

Solution

The fix adds an is_test_file() helper function that:

  1. Detects when tests_root overlaps with source directories
  2. Uses pattern-based matching in this case instead of directory-based matching
  3. Falls back to the original behavior when tests are in a dedicated separate directory

Test Plan

  • Verified that n8n repo now discovers 1+ optimizable functions instead of 0
  • Run existing test suite to ensure no regressions

…source

When tests_root equals module_root or project_root (common in monorepos
and projects without separate test directories), all functions were
incorrectly filtered as "test functions" because every file path would
match the tests_root prefix.

This fix introduces pattern-based test file detection that:
- Checks filename patterns (.test., .spec., _test., _spec.)
- Checks directory patterns (/test/, /tests/, /__tests__/) only within
  the project root to avoid false positives from parent directories
- Falls back to the original directory-based filtering when tests are
  in a dedicated separate directory

This enables codeflash to properly discover optimizable functions in
projects like n8n where tests are co-located with source files.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@misrasaurabh1
Copy link
Contributor

Please add tests

@Saga4 Saga4 merged commit a2963cb into main Feb 1, 2026
22 of 26 checks passed
@Saga4 Saga4 deleted the fix/test-file-filtering-when-tests-root-overlaps-source branch February 1, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants