Skip to content

Commit 6da33f8

Browse files
Merge pull request #1829 from codeflash-ai/fix/config-resolution-codeflash-toml
fix: include codeflash.toml in config resolution depth comparison
2 parents 13fcb04 + d22d74e commit 6da33f8

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

codeflash/code_utils/config_parser.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,28 @@ def parse_config_file(
9696
) -> tuple[dict[str, Any], Path]:
9797
package_json_path = find_package_json(config_file_path)
9898
pyproject_toml_path = find_closest_config_file("pyproject.toml") if config_file_path is None else None
99+
codeflash_toml_path = find_closest_config_file("codeflash.toml") if config_file_path is None else None
100+
101+
# Pick the closest toml config (pyproject.toml or codeflash.toml).
102+
# Java projects use codeflash.toml; Python projects use pyproject.toml.
103+
closest_toml_path = None
104+
if pyproject_toml_path and codeflash_toml_path:
105+
closest_toml_path = max(pyproject_toml_path, codeflash_toml_path, key=lambda p: len(p.parent.parts))
106+
else:
107+
closest_toml_path = pyproject_toml_path or codeflash_toml_path
99108

100109
# When both config files exist, prefer the one closer to CWD.
101110
# This prevents a parent-directory package.json (e.g., monorepo root)
102-
# from overriding a closer pyproject.toml with [tool.codeflash].
111+
# from overriding a closer pyproject.toml or codeflash.toml.
103112
use_package_json = False
104113
if package_json_path:
105-
if pyproject_toml_path is None:
114+
if closest_toml_path is None:
106115
use_package_json = True
107116
else:
108117
# Compare depth: more path parts = closer to CWD = more specific
109118
package_json_depth = len(package_json_path.parent.parts)
110-
pyproject_toml_depth = len(pyproject_toml_path.parent.parts)
111-
use_package_json = package_json_depth >= pyproject_toml_depth
119+
toml_depth = len(closest_toml_path.parent.parts)
120+
use_package_json = package_json_depth >= toml_depth
112121

113122
if use_package_json:
114123
assert package_json_path is not None

0 commit comments

Comments
 (0)