Commit graph

1 commit

Author SHA1 Message Date
Codeflash Bot
c57c39ae09 fix: handle co-located test directories with traverse_up
This fixes a ValueError that occurs when generated tests are placed in
co-located __tests__ directories outside the configured tests_root.

Root cause:
The CLI's _find_codeflash_test_dir() method generates tests in co-located
__tests__ directories (e.g., src/gateway/server/__tests__/) when they exist,
but verifier.py tried to compute a module path relative to the configured
tests_root (e.g., /workspace/target/test), causing:

ValueError: '/workspace/target/src/gateway/server/__tests__/codeflash-generated/test_xxx.test.ts'
is not in the subpath of '/workspace/target/test'

Fix:
- Added traverse_up=True to module_name_from_file_path() call in verifier.py
- This allows the function to find a common ancestor directory and compute
  the relative path from there, handling tests outside tests_root

Testing:
- Added comprehensive unit tests in test_module_name_from_file_path.py
- All existing tests pass 
- Linting passes 

Impact:
- Resolves crashes when optimizing functions with co-located test directories
- Enables proper handling of monorepo and __tests__ directory structures

Trace IDs affected: 7b97ddba-6ecd-42fd-b572-d40658746836

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-03 07:23:10 +00:00