Fix worktree mode filtering out all diff-discovered functions#1522
Conversation
In --worktree mode, get_git_diff resolves file paths from cwd (the original repo), but module_root/project_root are mirrored to the worktree. This caused filter_functions to reject all diff-discovered functions as "outside module-root". Use the pre-mirror roots for filtering, then remap file paths to the worktree for downstream use.
PR Review SummaryPrek Checks✅ All checks pass — Mypy
Code Review✅ No critical issues found. The changes are logically sound:
Minor nit: Test Coverage
Changed lines coverage:
Assessment: No coverage regression. The new code follows the same integration-heavy code paths that were already uncovered. These paths involve git worktree operations that are difficult to unit test without integration infrastructure. Test results: 2374 passed, 57 skipped, 8 failed (all failures in Last updated: 2026-02-18 |
git_root_dir() searches from CWD (original repo), but in worktree mode file paths have been remapped to the worktree. This caused relative_to() to raise ValueError when creating PRs. Search from module_root instead so root_dir is always in the same path space as the file paths.
Summary
--worktreemode (git-diff path),get_git_diffresolves file paths fromcwd(the original repo), butmodule_root/project_roothave been mirrored to the worktree directory bymirror_paths_for_worktree_mode. This causedfilter_functionsto reject all diff-discovered functions as "outside module-root" since the paths are in different directory trees.Test plan
codeflash --worktreenow finds functions (previously reported "Found 0 function to optimize" with "Functions outside module-root: 1")--alland--filemodes are unaffected (guarded by condition)