Skip to content

The agent that grows with you

test(install): pin the workspace selection away from apps/desktop

xxxigm59c5bd091332
diff --git a/tests/ci/test_classify_changes.py b/tests/ci/test_classify_changes.py
index 4902cbafc28..81e93d68094 100644
--- a/tests/ci/test_classify_changes.py
+++ b/tests/ci/test_classify_changes.py
@@ -8,7 +8,11 @@ change could have broken.
from __future__ import annotations
import importlib.util
+import io
+import json
import re
+import subprocess
+import sys
from pathlib import Path
import pytest
@@ -21,6 +25,8 @@ _mod = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_mod)
classify = _mod.classify
ci_review_files = _mod.ci_review_files
+pull_request_changed_files = _mod.pull_request_changed_files
+main = _mod.main
DEFAULT = {
"python": True,
@@ -300,3 +306,82 @@ def test_ci_review_files_returns_only_sensitive_paths_sorted_and_unique():
".github/workflows/ci.yml",
"apps/desktop/eslint.config.mjs",
]
+
+
+def _write_event(tmp_path, number: int | None = 88442) -> Path:
+ payload = {"pull_request": {"number": number}} if number is not None else {}
+ path = tmp_path / "event.json"
+ path.write_text(json.dumps(payload), encoding="utf-8")
+ return path
+
+
+def test_pull_request_changed_files_skips_non_pr_events(monkeypatch):
+ monkeypatch.setenv("EVENT_NAME", "push")
+ monkeypatch.setenv("REPO", "NousResearch/hermes-agent")
+ assert pull_request_changed_files() == []
+
+
+def test_pull_request_changed_files_skips_without_pr_number(tmp_path, monkeypatch):
+ monkeypatch.setenv("EVENT_NAME", "pull_request")
+ monkeypatch.setenv("REPO", "NousResearch/hermes-agent")
+ monkeypatch.setenv("GITHUB_EVENT_PATH", str(_write_event(tmp_path, number=None)))
+ assert pull_request_changed_files() == []
+
+
+def test_pull_request_changed_files_parses_gh_output(tmp_path, monkeypatch):
+ monkeypatch.setenv("EVENT_NAME", "pull_request")
+ monkeypatch.setenv("REPO", "NousResearch/hermes-agent")
+ monkeypatch.setenv("GITHUB_EVENT_PATH", str(_write_event(tmp_path)))
+
+ def fake_run(*args, **kwargs):
+ return subprocess.CompletedProcess(
+ args[0],
+ 0,
+ stdout="scripts/install.sh\ntests/test_install_sh_node_deps_workspaces.py\n",
+ stderr="",
+ )
+
+ monkeypatch.setattr(_mod.subprocess, "run", fake_run)
+ assert pull_request_changed_files() == [
+ "scripts/install.sh",
+ "tests/test_install_sh_node_deps_workspaces.py",
+ ]
+
+
+def test_pull_request_changed_files_returns_empty_when_gh_fails(tmp_path, monkeypatch):
+ monkeypatch.setenv("EVENT_NAME", "pull_request")
+ monkeypatch.setenv("REPO", "NousResearch/hermes-agent")
+ monkeypatch.setenv("GITHUB_EVENT_PATH", str(_write_event(tmp_path)))
+
+ def fake_run(*args, **kwargs):
+ return subprocess.CompletedProcess(args[0], 1, stdout="", stderr="gh: Not Found")
+
+ monkeypatch.setattr(_mod.subprocess, "run", fake_run)
+ assert pull_request_changed_files() == []
+
+
+def test_main_recovers_pr_files_instead_of_fail_open_ci_review(monkeypatch, capsys):
+ """A fork compare 404 must not demand ci-reviewed for a CLI-only install."""
+ monkeypatch.setattr(
+ _mod,
+ "pull_request_changed_files",
+ lambda: ["scripts/install.sh", "tests/test_install_sh_node_deps_workspaces.py"],
+ )
+ monkeypatch.setattr(sys, "stdin", io.StringIO("\n"))
+ monkeypatch.delenv("GITHUB_OUTPUT", raising=False)
+
+ assert main() == 0
+ out = capsys.readouterr().out
+ assert "ci_review=false" in out
+ assert "python=true" in out
+ assert "python_prod=true" in out
+
+
+def test_main_still_fail_opens_when_recovery_is_empty(monkeypatch, capsys):
+ monkeypatch.setattr(_mod, "pull_request_changed_files", lambda: [])
+ monkeypatch.setattr(sys, "stdin", io.StringIO(""))
+ monkeypatch.delenv("GITHUB_OUTPUT", raising=False)
+
+ assert main() == 0
+ out = capsys.readouterr().out
+ assert "ci_review=true" in out
diff --git a/tests/test_install_sh_node_deps_workspaces.py b/tests/test_install_sh_node_deps_workspaces.py
new file mode 100644
index 00000000000..176e9efad30
--- /dev/null
+++ b/tests/test_install_sh_node_deps_workspaces.py
@@ -0,0 +1,94 @@
+"""A CLI install must never resolve the desktop workspace.
+
+``apps/desktop`` declares ``node-pty``, which ships no Linux prebuild and so
+falls back to ``node-gyp rebuild``. A bare ``npm install`` at the repo root
+resolves the root ``apps/*`` workspace glob and drags it in, so a host with no
+make/gcc cannot finish an install for a machine that will never launch Electron
+or a PTY addon (#38311, #38772). Since #85297 a failed npm install aborts the
+whole install, so this is the difference between a working CLI install and none.
+
+These exercise the real ``node_deps_workspace_args`` from ``scripts/install.sh``.
+``--manifest`` makes the installer print its stage manifest and stop before
+``main``, so sourcing it defines every function without running an install.
+"""
+
+import shutil
+import subprocess
+from pathlib import Path
+
+import pytest
+
+REPO_ROOT = Path(__file__).resolve().parent.parent
+INSTALL_SH = REPO_ROOT / "scripts" / "install.sh"
+
+pytestmark = pytest.mark.skipif(shutil.which("bash") is None, reason="needs bash")
+
+
+def workspace_args(install_dir: Path) -> list[str]:
+ """Return the npm arguments install.sh would use for ``install_dir``."""
+ script = (
+ f'source "{INSTALL_SH}" --manifest >/dev/null\n'
+ f'node_deps_workspace_args "{install_dir}"\n'
+ 'printf "%s\\n" "${NODE_DEPS_WORKSPACE_ARGS[@]}"\n'
+ )
+ result = subprocess.run(
+ ["bash", "-c", script],
+ capture_output=True,
+ text=True,
+ check=True,
+ )
+ return result.stdout.split()
+
+
+def make_checkout(root: Path, workspaces: tuple[str, ...]) -> Path:
+ """Lay out a checkout with a root package and the given workspace dirs."""
+ (root / "package.json").write_text('{"workspaces": ["apps/*", "ui-tui", "web"]}')
+ for workspace in ("apps/desktop", *workspaces):
+ directory = root / workspace
+ directory.mkdir(parents=True)
+ (directory / "package.json").write_text("{}")
+ return root
+
+
+def selected_workspaces(args: list[str]) -> list[str]:
+ return [value for flag, value in zip(args, args[1:]) if flag == "--workspace"]
+
+
+ "workspaces",
+ [("ui-tui", "web"), ("ui-tui",), ("web",), ()],
+ ids=["full", "tui-only", "web-only", "bare"],
+)
+def test_desktop_workspace_is_never_selected(tmp_path, workspaces):
+ """No checkout shape may let apps/desktop (and its node-pty) resolve."""
+ args = workspace_args(make_checkout(tmp_path, workspaces))
+
+ assert "desktop" not in " ".join(args)
+ # Constraining npm is the whole point: an empty argument list would leave
+ # npm resolving every workspace, including apps/*.
+ assert args, "npm must be constrained, otherwise apps/* resolves"
+ assert "--workspaces=false" in args or selected_workspaces(args)
+
+
+def test_present_workspaces_are_installed_alongside_the_root(tmp_path):
+ """ui-tui and web are what a CLI install needs; the root owns shared
+ devDependencies that a scoped install would otherwise prune."""
+ args = workspace_args(make_checkout(tmp_path, ("ui-tui", "web")))
+
+ assert selected_workspaces(args) == ["ui-tui", "web"]
+ assert "--include-workspace-root" in args
+
+
+def test_absent_workspace_is_not_named(tmp_path):
+ """npm fails hard on a workspace it cannot find, so a partial checkout
+ must only name the workspaces that exist."""
+ args = workspace_args(make_checkout(tmp_path, ("ui-tui",)))
+
+ assert selected_workspaces(args) == ["ui-tui"]
+
+
+def test_bare_checkout_installs_the_root_only(tmp_path):
+ """With no installable workspace, npm still must not walk apps/*."""
+ args = workspace_args(make_checkout(tmp_path, ()))
+
+ assert args == ["--workspaces=false"]