Skip to content

The agent that grows with you

test(desktop): the build-lock tests never reach the real Node toolchain

Teknium02c0bbc65b18
diff --git a/tests/hermes_cli/test_desktop_build_lock.py b/tests/hermes_cli/test_desktop_build_lock.py
index 942df4d6545..534c7dbb87a 100644
--- a/tests/hermes_cli/test_desktop_build_lock.py
+++ b/tests/hermes_cli/test_desktop_build_lock.py
@@ -5,6 +5,7 @@ from __future__ import annotations
import argparse
import subprocess
import sys
+import threading
from pathlib import Path
from unittest.mock import patch
@@ -14,6 +15,35 @@ from hermes_cli import main_desktop as cli_desktop
from hermes_cli.desktop_build_lock import DesktopBuildLock
[email protected](autouse=True)
+def _no_real_node_toolchain(monkeypatch):
+ """These tests are about the lock, never the build: a real ``source_build_env`` provisions
+ the PM runtime and Node over the network and ``prepare_source_dependencies`` runs node, so
+ a stalled runner network hung this file at CI's 600 s cap. Reaching either is a test bug."""
+ from hermes_cli import source_build
+
+ def refuse(*_args, **_kwargs):
+ raise AssertionError("test reached the real Node toolchain (network provisioning + npm)")
+
+ monkeypatch.setattr(source_build, "source_build_env", refuse)
+ monkeypatch.setattr(source_build, "prepare_source_dependencies", refuse)
+
+
+def _read_line(proc: subprocess.Popen, timeout: float = 60) -> str:
+ """``proc.stdout.readline()`` bounded: a child stuck before it prints fails the test instead
+ of hanging it."""
+ stdout = proc.stdout
+ assert stdout is not None
+ line: list[str] = []
+ reader = threading.Thread(target=lambda: line.append(stdout.readline()), daemon=True)
+ reader.start()
+ reader.join(timeout)
+ if not line:
+ proc.kill()
+ pytest.fail(f"child printed nothing within {timeout:.0f}s")
+ return line[0]
+
+
def _checkout(tmp_path: Path) -> Path:
root = tmp_path / "hermes-agent"
desktop_dir = root / "apps" / "desktop"
@@ -68,6 +98,7 @@ def test_desktop_build_lock_excludes_another_process(tmp_path):
result = subprocess.run(
[sys.executable, "-c", probe, str(tmp_path)],
check=False,
+ timeout=60,
)
finally:
holder.release()
@@ -187,6 +218,11 @@ def test_gui_releases_lock_after_build_failure(tmp_path, monkeypatch, capsys):
def failing_build(*_args, **_kwargs):
raise RuntimeError("tsc missing: ENOTEMPTY node_modules race")
+ prepared: list[Path] = []
+ monkeypatch.setattr("hermes_cli.source_build.source_build_env", lambda *_a, **_kw: {"PATH": ""})
+ monkeypatch.setattr("hermes_cli.source_build.prepare_source_dependencies",
+ lambda project_root, *_a, **_kw: prepared.append(project_root))
+
with patch("hermes_cli.main_desktop._desktop_launch_env", return_value=({}, [])), \
patch("hermes_cli.main_desktop._desktop_build_needed", return_value=True), \
patch("hermes_cli.main_desktop.build_prepared_desktop", side_effect=failing_build), \
@@ -194,6 +230,7 @@ def test_gui_releases_lock_after_build_failure(tmp_path, monkeypatch, capsys):
cli_desktop.cmd_gui(_args(build_only=True))
assert exc.value.code == 1
+ assert prepared == [root], "the build failed before the step the test fails"
successor = DesktopBuildLock(root)
assert successor.acquire() is True, "build lock was not released after a failed build"
successor.release()
@@ -282,7 +319,7 @@ def test_a_running_update_refuses_a_direct_desktop_build(tmp_path):
holder = subprocess.Popen([sys.executable, "-c", _UPDATE_HOLDER, str(root), str(tmp_path / "marker")],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True, encoding="utf-8")
try:
- assert holder.stdout.readline().strip() == "held"
+ assert _read_line(holder).strip() == "held"
build = DesktopBuildLock(root)
assert build.acquire() is False, "a desktop build started while an updater held the checkout"
assert _desktop_lock_free(root), "a refused build kept the desktop build lock"