mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
Second, deeper pass over tools/gateway/hermes_cli plus first pass over the trees wave 1 missed (acp, acp_adapter, skills, computer_use, docker, dashboard, conformance, monitoring, secret_sources, hermes_state, providers). Same rubric as wave 1 (AGENTS.md test policy); security, alternation/caching invariants, issue-number regressions, and E2E kept. Real test-quality fixes found and rooted out along the way: - tests/tools/test_command_guards.py made real auxiliary-LLM HTTPS calls (DEFAULT_CONFIG smart-approval leaked in) — pinned approval mode=manual via autouse fixture: 17.4s → 0.4s. - test_model_switch_custom_providers.py / test_user_providers_model_switch.py silently probed live provider catalogs (~2s/test) — stubbed cached_provider_model_ids/provider_model_ids/fetch_api_models. - test_telegram_noise_filter.py: 15-platform copy-paste matrix over shared gateway.run logic → 3 representative platforms (55s → 3.9s). - test_gateway_shutdown.py: stop()'s 5s interrupt-deadline loop spun on MagicMock agents — interrupt.side_effect now clears _running_agents (22s → 1.0s). - test_gateway_inactivity_timeout.py poll-harness timings shrunk 3-5x (24s → 1.1s); test_mcp_stability.py backoff/SIGTERM-grace sleeps patched (15.4s → 2.5s); test_async_delegation.py negative-drain wait 5s → 0.5s. - test_telegram_init_deadline.py: loop-block margin restored to 1.0s with rationale comment — the watchdog-dump assertion needs the loop blocked well past deadline+grace under parallel load (flaked once in the 40-worker verification run at a 0.2s margin). Verification: full hermetic suite via scripts/run_tests.sh — 2,438 files, 21,718 tests passed, 0 failed, 293.9s wall. Suite totals vs original baseline: 46,820 → 19,757 test functions (−57.8%), wall 583.5s → 293.9s (−50%), subprocess CPU 13,564s → 11,623s.
107 lines
3.1 KiB
Python
107 lines
3.1 KiB
Python
"""Tests for interrupted-install self-heal (the ``.update-incomplete`` marker).
|
|
|
|
Covers the breadcrumb lifecycle and the launch-time recovery guard added so a
|
|
``hermes update`` killed mid-install (Ctrl-C, terminal close, WSL OOM) gets
|
|
finished automatically on the next launch instead of leaving a half-built venv.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import hermes_cli.main as m
|
|
|
|
|
|
def test_marker_round_trip(tmp_path, monkeypatch):
|
|
monkeypatch.setattr(m, "PROJECT_ROOT", tmp_path)
|
|
marker = m._update_marker_path()
|
|
assert marker == tmp_path / ".update-incomplete"
|
|
assert not marker.exists()
|
|
|
|
m._write_update_incomplete_marker()
|
|
assert marker.exists()
|
|
body = marker.read_text()
|
|
assert "started=" in body
|
|
assert "pid=" in body
|
|
|
|
m._clear_update_incomplete_marker()
|
|
assert not marker.exists()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _stub_install_env(monkeypatch, m, seen):
|
|
"""Common stubs so recovery's install path is inert and observable."""
|
|
|
|
class R:
|
|
returncode = 0
|
|
|
|
monkeypatch.setattr(m.subprocess, "run", lambda *a, **k: R())
|
|
monkeypatch.setattr(m, "_is_termux_env", lambda *a, **k: False)
|
|
monkeypatch.setattr("hermes_cli.managed_uv.ensure_uv", lambda: None)
|
|
monkeypatch.setattr(
|
|
m,
|
|
"_install_python_dependencies_with_optional_fallback",
|
|
lambda *a, **k: seen.__setitem__("install", True),
|
|
)
|
|
|
|
|
|
def test_recovery_self_lock_does_not_clear_core_marker_via_import_probes(
|
|
tmp_path, monkeypatch
|
|
):
|
|
# ``.update-incomplete`` is the generic core-install marker. Healthy
|
|
# lazy-refresh import probes alone must NOT clear it and skip full
|
|
# reinstall — a missing dep outside the 7-probe set would look healthy
|
|
# (#58004 review blocker).
|
|
monkeypatch.setattr(m, "PROJECT_ROOT", tmp_path)
|
|
(tmp_path / "pyproject.toml").write_text("[project]\nname='x'\n")
|
|
m._write_update_incomplete_marker()
|
|
|
|
scripts_dir = tmp_path / "venv" / "Scripts"
|
|
scripts_dir.mkdir(parents=True)
|
|
shim = scripts_dir / "hermes.exe"
|
|
shim.write_text("")
|
|
|
|
monkeypatch.setattr(m, "_is_windows", lambda: True)
|
|
monkeypatch.setattr(m, "_venv_scripts_dir", lambda: scripts_dir)
|
|
monkeypatch.setattr(m, "_hermes_exe_shims", lambda d: [shim])
|
|
monkeypatch.setattr(
|
|
m,
|
|
"_default_venv_install_target",
|
|
lambda: (["uv", "pip"], {"VIRTUAL_ENV": str(tmp_path / "venv")}),
|
|
)
|
|
monkeypatch.setattr(
|
|
m, "_repair_venv_via_import_probes", lambda *a, **k: "healthy"
|
|
)
|
|
|
|
class FakeProc:
|
|
def __init__(self, exe_path):
|
|
self._exe = exe_path
|
|
|
|
def exe(self):
|
|
return self._exe
|
|
|
|
def parents(self):
|
|
return [FakeProc(str(shim))]
|
|
|
|
monkeypatch.setattr("psutil.Process", lambda: FakeProc(sys_executable_path()))
|
|
|
|
seen = {"install": False}
|
|
_stub_install_env(monkeypatch, m, seen)
|
|
|
|
m._recover_from_interrupted_install()
|
|
|
|
assert seen["install"] is True, "core marker still requires full reinstall"
|
|
assert not m._update_marker_path().exists(), "cleared only after full reinstall"
|
|
|
|
|
|
|
|
|
|
def sys_executable_path():
|
|
import sys
|
|
|
|
return sys.executable
|
|
|
|
|