fix: handle co-located test directories with traverse_up#1979
fix: handle co-located test directories with traverse_up#1979mohammedahmed18 wants to merge 2 commits intomainfrom
Conversation
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>
|
Codeflash Bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Claude finished @mohammedahmed18's task in 2m 39s —— View job PR Review Summary
Prek ChecksRuff checks passed. Mypy reports 2 pre-existing errors in Code ReviewThe fix is correct. Adding How Minor observations:
No bugs, security issues, or breaking API changes. Duplicate DetectionNo duplicates detected. Last updated: 2026-04-03T13:37Z |
…ocated-test-path-resolution
Problem
When optimizing functions in projects with co-located
__tests__directories, the CLI crashes with:This occurs when:
src/gateway/server/ws-connection/connect-policy.tstest/src/gateway/server/__tests__/codeflash-generated/Root Cause
The CLI's
_find_codeflash_test_dir()method intelligently places tests near their source files by looking for co-located__tests__directories. However,verifier.pyline 37 tries to compute a module path relative to the configuredtests_root:When the test path is NOT under
tests_root, this fails becausemodule_name_from_file_path()doesn't traverse up by default.Solution
Enable the
traverse_upparameter:With
traverse_up=True, the function can find a common ancestor directory and compute the relative path from there, properly handling tests outside the configuredtests_root.Testing
Added comprehensive unit tests:
Impact
References
Trace ID:
7b97ddba-6ecd-42fd-b572-d40658746836