fix: include codeflash.toml in config resolution depth comparison#1829
fix: include codeflash.toml in config resolution depth comparison#1829mashraf-222 merged 1 commit intoomni-javafrom
Conversation
When both package.json and codeflash.toml exist in the directory tree, parse_config_file() only compared package.json against pyproject.toml. Java projects use codeflash.toml, which was never checked — so any package.json in a parent directory would always win, setting the wrong module_root and project_root. Now we find the closest toml config (pyproject.toml or codeflash.toml) and compare its depth against package.json, so a closer codeflash.toml correctly takes priority. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @mashraf-222's task in 2m 15s —— View job PR Review SummaryTasks
Prek Checks✅ Mypy: 6 pre-existing errors in Code ReviewThe fix is logically correct and well-scoped. The root cause and solution match. One potential concern — closest_toml_path = max(pyproject_toml_path, codeflash_toml_path, key=lambda p: len(p.parent.parts))If Observation — use_package_json = package_json_depth >= toml_depthIf Duplicate DetectionNo duplicates detected. Test Coverage
|
Problems fixed
When a
package.jsonexists in a parent directory (e.g., monorepo root or dev dependency),parse_config_file()would always prefer it over a closercodeflash.tomlin the current project directory. This caused Java projects to resolve the wrongmodule_rootandproject_root, leading to:cwd(nopom.xml→ build failure)dependency:resolvealso needs a validpom.xmlin the working directory)Root cause
The depth comparison in
parse_config_file()only checkedpackage.jsonagainstpyproject.toml. Java projects usecodeflash.toml, which was never included in the comparison. Whenpyproject_toml_pathwasNone(nopyproject.tomlexists), the code unconditionally setuse_package_json = True— regardless of whether a closercodeflash.tomlexisted.Solution
Find the closest toml config file (either
pyproject.tomlorcodeflash.toml) and use that in the depth comparison againstpackage.json. A closercodeflash.tomlnow correctly takes priority over a fartherpackage.json.Code changes
codeflash/code_utils/config_parser.py: Addedcodeflash.tomllookup viafind_closest_config_file(), pick the closer ofpyproject.toml/codeflash.toml, and compare that againstpackage.jsondepth.Testing
tests/test_setup/— 22 config + 65 detector + 29 e2e + 29 first_run)codeflash.toml+ parentpackage.json→ now correctly resolvescodeflash.tomlpackage.json→ still resolvespackage.json(unchanged)pyproject.toml→ still resolvespyproject.toml(unchanged)Impact
package.json(e.g., dev testing) now work correctly