Skip to content

fix: resolve test module path for JS when tests are outside tests_project_rootdir#1871

Closed
aseembits93 wants to merge 1 commit intomainfrom
fix/js-test-module-path-resolution
Closed

fix: resolve test module path for JS when tests are outside tests_project_rootdir#1871
aseembits93 wants to merge 1 commit intomainfrom
fix/js-test-module-path-resolution

Conversation

@aseembits93
Copy link
Contributor

Summary

  • For JS projects, generated tests are placed near the source file (not under tests_project_rootdir), causing module_name_from_file_path to crash with ValueError
  • Added fallback to project_root_path in verifier.py and function_optimizer.py when test path isn't under tests_project_rootdir
  • Added unit test covering the path resolution failure and fallback

Test plan

  • test_module_name_from_file_path_not_under_root passes
  • codeflash --file code_to_optimize/js/code_to_optimize_js/calculator.js --module-root code_to_optimize --subagent runs to completion

🤖 Generated with Claude Code

…ject_rootdir

For JavaScript projects, generated tests are placed near the source file
(e.g., code_to_optimize/js/.../tests/codeflash-generated/) rather than
under tests_project_rootdir. This caused module_name_from_file_path to
crash with ValueError. Fall back to project_root_path when the test path
isn't under tests_project_rootdir.

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

claude bot commented Mar 18, 2026

Claude finished @aseembits93's task in 3m 35s —— View job


PR Review Summary

Todo

  • Triage PR scope
  • Run lint and type checks
  • Resolve stale review threads
  • Code review
  • Duplicate detection
  • Test coverage
  • Post summary

Prek Checks

ruff check and ruff format both pass. No issues found.

Mypy was not run via prek (interactive prompt issue in CI environment), but the new test function has proper -> None annotation.


Code Review

The fix is correct and handles the root cause: for JS/TS, codeflash places generated tests near the source file (not under tests_project_rootdir), causing module_name_from_file_path to raise ValueError.

No bugs found. A few observations:

Duplicate fallback pattern — The same try/except pattern is now in two places:

  • codeflash/verification/verifier.py:36–40
  • codeflash/languages/function_optimizer.py:2108–2115

Both fallbacks are identical in structure. Extracting a small helper (e.g., resolve_test_module_path(file_path, primary_root, fallback_root)) would remove the duplication. That said, since the fix is minimal and the pattern is simple, this is a style preference rather than a blocking issue. Consider extracting helper →

Other callers not affectedinstrument_existing_tests.py:650,728 also call module_name_from_file_path(test_path, tests_project_root) without fallback, but these functions use ast.parse and are Python-only paths, so they won't hit the JS case.

project_root_path is always non-null — confirmed in TestConfig dataclass (verification_utils.py:108), so no null-safety concern on the fallback path.


Duplicate Detection

No duplicates detected. The two changed call sites are intentionally parallel (test generation vs. test repair), not candidates for a shared abstraction in this codebase style.


Test Coverage

  • New test test_module_name_from_file_path_not_under_root in tests/test_code_utils.py directly covers both the failure path and the fallback behavior.
  • All 56 tests in test_code_utils.py pass locally.
  • Coverage for verifier.py and function_optimizer.py could not be measured in isolation (no targeted test harness for those call sites), but the unit test added is the right level of coverage for this fix.

Bot PR Cleanup

Closed PR #1870 (codeflash-ai[bot]) — CI unit tests were failing across all Python versions due to pre-existing failures in test_git_utils.py::TestGetGitDiffMultiLanguage on the base branch fix/trigger_cc_on_multiple_commits.


Last updated: 2026-03-18

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.

1 participant