fix(install): correct check_dir tautology and add --workspace web test

- check_dir = npm_dir if audit_extra else npm_dir evaluated identically in
  both branches; change to PROJECT_ROOT if audit_extra else npm_dir so
  workspace-scoped audits check the workspace root's node_modules
- Add test_npm_install_uses_workspace_web_scope asserting --workspace web is
  passed adjacently in the _build_web_ui npm install invocation
This commit is contained in:
Zak B. Elep 2026-06-05 11:18:21 +08:00 committed by Teknium
parent 4bf52022e5
commit 675fb10240
2 changed files with 14 additions and 1 deletions

View file

@ -1469,7 +1469,7 @@ def run_doctor(args):
# For workspace-scoped audits run from PROJECT_ROOT the
# node_modules check must use the workspace root; standalone dirs
# (whatsapp-bridge) check their own node_modules.
check_dir = npm_dir if audit_extra else npm_dir
check_dir = PROJECT_ROOT if audit_extra else npm_dir
if not (check_dir / "node_modules").exists():
continue
try:

View file

@ -140,6 +140,19 @@ class TestBuildWebUISkipsWhenFresh:
assert kwargs["encoding"] == "utf-8"
assert kwargs["errors"] == "replace"
def test_npm_install_uses_workspace_web_scope(self, tmp_path):
web_dir, _ = _make_web_dir(tmp_path)
mock_cp = __import__("subprocess").CompletedProcess([], 0, stdout="", stderr="")
build_ok = __import__("subprocess").CompletedProcess([], 0, stdout="", stderr="")
with patch("hermes_cli.main.shutil.which", return_value="/usr/bin/npm"), \
patch("hermes_cli.main.subprocess.run", return_value=mock_cp) as mock_run, \
patch("hermes_cli.main._run_with_idle_timeout", return_value=build_ok):
result = _build_web_ui(web_dir)
assert result is True
install_cmd = mock_run.call_args[0][0]
assert "--workspace" in install_cmd
assert install_cmd[install_cmd.index("--workspace") + 1] == "web"
def test_web_build_uses_idle_timeout_helper(self, tmp_path):
"""npm run build now goes through _run_with_idle_timeout (issue #33788).