Skip to content

Commit 3c835d7

Browse files
committed
Fix package.json config overriding closer pyproject.toml in monorepos
In parse_config_file(), package.json was always checked first by walking up from CWD. In monorepos with both a root package.json and a nested pyproject.toml with [tool.codeflash], the JS config would win and set pytest_cmd to "jest", causing Python function optimization to crash with FileNotFoundError: 'jest'. Now both config files are located first, and the one closer to CWD is preferred, so a pyproject.toml in the working directory takes precedence over a parent-directory package.json.
1 parent b6b47ff commit 3c835d7

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

codeflash/code_utils/config_parser.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,23 @@ def find_conftest_files(test_paths: list[Path]) -> list[Path]:
8888
def parse_config_file(
8989
config_file_path: Path | None = None, override_formatter_check: bool = False
9090
) -> tuple[dict[str, Any], Path]:
91-
# First try package.json for JS/TS projects
9291
package_json_path = find_package_json(config_file_path)
92+
pyproject_toml_path = find_closest_config_file("pyproject.toml") if config_file_path is None else None
93+
94+
# When both config files exist, prefer the one closer to CWD.
95+
# This prevents a parent-directory package.json (e.g., monorepo root)
96+
# from overriding a closer pyproject.toml with [tool.codeflash].
97+
use_package_json = False
9398
if package_json_path:
99+
if pyproject_toml_path is None:
100+
use_package_json = True
101+
else:
102+
# Compare depth: more path parts = closer to CWD = more specific
103+
package_json_depth = len(package_json_path.parent.parts)
104+
pyproject_toml_depth = len(pyproject_toml_path.parent.parts)
105+
use_package_json = package_json_depth >= pyproject_toml_depth
106+
107+
if use_package_json:
94108
result = parse_package_json_config(package_json_path)
95109
if result is not None:
96110
config, path = result

0 commit comments

Comments
 (0)