fix: support monorepo hoisted dependencies in JS requirements check#1376
Conversation
The verify_requirements() method only checked for test frameworks (jest/vitest) in the local package's node_modules. In monorepos with workspace hoisting (yarn/pnpm), dependencies are often installed at the workspace root instead. Changes: - Check both local node_modules and workspace root node_modules - Use _find_monorepo_root() to locate workspace root - Add debug logging for framework resolution - Update docstring to document monorepo support Fixes false positive "jest is not installed" warnings in monorepo projects where jest is hoisted to the workspace root. Tested with Budibase monorepo where jest is at workspace root.
PR Review Summary✅ Prek ChecksAll linting and formatting checks passed successfully. No issues found. ✅ Mypy Type ChecksThe changed lines in this PR do not introduce any new type errors. All mypy errors reported are pre-existing issues in the codebase and are unrelated to this PR's changes. 📋 Code ReviewStatus: No critical issues found This PR successfully adds monorepo support for hoisted dependencies in JavaScript requirements checking. The implementation:
Existing Review Comments:
📊 Test Coverage Analysis
Coverage Details:
Coverage Assessment:
🔀 Codeflash Optimization PRsChecked 30 open optimization PRs from codeflash-ai[bot]. None are ready to merge - all have failing CI checks (unit tests, type checks, or pr-review failures). Last updated: 2026-02-04 |
| rel_path = source_file.relative_to(project_root) | ||
| return "../" + rel_path.with_suffix("").as_posix() | ||
|
|
||
| def verify_requirements(self, project_root: Path, test_framework: str = "jest") -> tuple[bool, list[str]]: |
There was a problem hiding this comment.
✅ Fixed in latest commit - moved to init_javascript.py as find_node_modules_with_package()
| # If not found locally, check for hoisted dependencies in monorepo workspace root | ||
| if not framework_found: | ||
| from codeflash.languages.javascript.test_runner import _find_monorepo_root | ||
|
|
||
| workspace_root = _find_monorepo_root(project_root) | ||
| if workspace_root: | ||
| workspace_framework = workspace_root / "node_modules" / test_framework | ||
| if workspace_framework.exists(): | ||
| framework_found = True | ||
| logger.debug("Found %s in workspace root node_modules at %s", test_framework, workspace_framework) |
There was a problem hiding this comment.
The existing tests in test_javascript_requirements.py only verify the case where the test framework is in local node_modules. Consider adding a test case like:
def test_verify_requirements_monorepo_hoisted_dependencies(self, js_support, tmp_path):
"""Test that frameworks in workspace root node_modules are detected."""
# Create package without local node_modules
package_root = tmp_path / "packages" / "shared-core"
package_root.mkdir(parents=True)
# Create workspace root with jest
workspace_node_modules = tmp_path / "node_modules"
workspace_node_modules.mkdir()
(workspace_node_modules / "jest").mkdir()
# Add workspace marker (e.g., yarn.lock)
(tmp_path / "yarn.lock").touch()
with patch("subprocess.run") as mock_run:
mock_run.return_value = MagicMock(returncode=0)
success, errors = js_support.verify_requirements(package_root, "jest")
assert success is True
assert errors == []This would ensure the monorepo support actually works as intended.
- Add find_node_modules_with_package() to init_javascript.py - Uses same tree-search pattern as determine_js_package_manager() - Simplify verify_requirements() to use the new helper - Reduces code duplication and centralizes monorepo logic Benefits: - Consistent monorepo support across codebase - Single source of truth for finding node_modules - Easier to maintain and test - Works alongside determine_js_package_manager() pattern
Problem
The
verify_requirements()method in JavaScript support only checked for test frameworks (jest/vitest) in the local package'snode_modules. In monorepos with workspace dependency hoisting (yarn workspaces, pnpm workspaces, etc.), dependencies are often installed at the workspace root instead of in each package.This caused false positive warnings like:
Even though jest was properly installed at the workspace root.
Solution
node_modulesand workspace rootnode_modules_find_monorepo_root()helper to locate workspace rootTesting
Tested with Budibase monorepo where jest is installed at:
/home/ubuntu/budibase/packages/shared-core/node_modules/jest(doesn't exist)/home/ubuntu/budibase/node_modules/jest(workspace root - now detected)Related
This complements the monorepo support already added to: