fix: git diff auto-detection filters by current language instead of hardcoding .py#1855
Conversation
…ardcoding .py get_git_diff() hardcoded `.py` as the only valid file extension, causing the auto-detect flow (no --file flag) to return 0 functions for Java, JavaScript, and TypeScript projects. This broke the Claude Code plugin integration where the hook runs `codeflash --subagent` without --file. Now uses current_language_support().file_extensions to filter by the active language's extensions dynamically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @mashraf-222's task in 2m 31s —— View job PR Review Summary
Prek Checks✅ All checks pass (ruff lint, ruff format). Mypy CI also passing. Code ReviewThe fix is correct and minimal. The change replaces the hardcoded Observations:
No bugs, no security issues, no breaking API changes. Duplicate DetectionNo duplicates detected. The change is isolated to the Test CoverageAll 15 tests pass (12 existing + 3 new). Coverage on Overall: Clean, minimal fix with correct approach. ✅ |
|
@claude fix the failing windows unit test |
|
Claude finished @aseembits93's task in 6m 24s —— View job Fixed Failing Windows Unit Test
Root cause: Fix: Replaced # Before
start = time.time_ns()
result = func(*args, **kwargs)
end = time.time_ns()
# After
start = time.perf_counter_ns()
result = func(*args, **kwargs)
end = time.perf_counter_ns()All 3 trace benchmark tests pass locally. Pushed as commit |
…ision time.time_ns() has ~15ms resolution on Windows, causing fast benchmark functions to record 0 ns elapsed time and fail timing assertions. time.perf_counter_ns() provides ~100ns resolution on all platforms. Co-authored-by: Aseem Saxena <aseembits93@users.noreply.github.com>
Summary
get_git_diff()incode_utils/git_utils.pyhardcoded.pyas the only valid file extension when parsing git diffs--file) to return 0 functions for Java, JavaScript, and TypeScript projectscodeflash --subagentwithout specifying--file, relying on git diff auto-detection to find changed functionsProblems fixed
Symptom: When running
codeflash --subagent(or any invocation without--file) on a Java/JS/TS project, the pipeline discovers no functions to optimize and exits silently — even when the git diff contains changed functions.Root cause: Line 42 of
codeflash/code_utils/git_utils.pyhadif file_path.suffix != ".py": continue, which filtered out all non-Python files from the git diff results. This function is called by bothget_functions_within_git_diff()andget_functions_within_commit()indiscovery/functions_to_optimize.py.Solution
Replaced the hardcoded
.pycheck withcurrent_language_support().file_extensions, which returns the correct extensions for whatever language is active in the session (e.g.,(".java",)for Java,(".js", ".jsx", ".mjs")for JavaScript). The current language is already set by the timeget_git_diff()is called during an optimization run.Code changes
codeflash/code_utils/git_utils.py: Importcurrent_language_support, resolve extensions once at function entry, usenot in supported_extensionsinstead of!= ".py"tests/test_git_utils.py: Added 3 new tests:test_java_diff_found_when_language_is_java— Java files discovered when language is Javatest_java_diff_ignored_when_language_is_python— Java files filtered out when language is Pythontest_mixed_lang_diff_filters_by_current_language— mixed Python+Java diff correctly filters by active languageTesting
$ uv run pytest tests/test_git_utils.py -v # 15 passed (12 existing + 3 new) — no regressions🤖 Generated with Claude Code