hermes-agent/tests/hermes_cli/test_update_fleet_restart_timeout.py
Teknium 6b81590c55
test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions
Systematic prune per AGENTS.md test policy, one pass over every major
test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli,
cron, tui_gateway, honcho/openviking, root-level):

- DELETE: source-reading tests (read_text/getsource on prod files),
  change-detector tests (exact catalog counts, model-name snapshots,
  config version literals), mock-echo tests (assert a mock returns what
  it was told), assertion-free/trivial tests, near-duplicate
  parametrizations (boundaries + one representative kept), async/sync
  twin duplicates, cosmetic within-file variations.
- KEEP (mandatory): security/redaction/approval guards, message-role
  alternation invariants, prompt-caching/deterministic-call-id
  invariants, issue-number regression tests (deduped), E2E tests.
- 6 test files deleted outright (script-style/no-assert or fully
  redundant); conftest.py, fakes/, fixtures/ untouched.
- tests/acp/conftest.py added: autouse fixture stubs the live
  models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server
  tests performed on every session create — test_server.py 147s → 3.4s,
  and the tests are now genuinely hermetic.
- Sleep-based slowness shrunk where safe (codex_ttfb_watchdog,
  compression_concurrent_fork, etc.); no wall-clock assertion tightened.

Verification: full hermetic suite via scripts/run_tests.sh —
2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall
(baseline: 583s wall, 13,564s subprocess CPU).
2026-07-29 13:10:23 -07:00

115 lines
4 KiB
Python

"""Regression for #68523 — one systemctl timeout must not abort fleet restarts.
On hosts with many profile-backed ``hermes-gateway*.service`` units,
``hermes update`` used to wrap the entire per-scope unit loop in a single
``except subprocess.TimeoutExpired``. A timeout on unit N skipped units
N+1…, leaving later gateways on pre-update in-memory modules while the
checkout on disk was already new (mixed-generation crashes).
"""
from __future__ import annotations
import subprocess
import pytest
from hermes_cli.main import (
_for_each_systemd_gateway_unit,
_warn_incomplete_gateway_fleet_restart,
)
def _list_units_stdout(names: list[str]) -> str:
return "\n".join(f"{name}.service loaded active running" for name in names)
class TestFleetRestartTimeoutIsolation:
def test_timeout_on_middle_unit_continues_remaining_units(self):
units = [
"hermes-gateway-xiaomo1",
"hermes-gateway-xiaomo2",
"hermes-gateway-xiaomo3",
"hermes-gateway-xiaomo4",
"hermes-gateway-xiaomo5",
"hermes-gateway-xiaomo6",
"hermes-gateway-xiaomo7",
"hermes-gateway",
]
restarted: list[str] = []
failed: list[str] = []
timeout_cmds: list = []
def process_unit(svc_name: str) -> None:
if svc_name == "hermes-gateway-xiaomo5":
raise subprocess.TimeoutExpired(
cmd=["systemctl", "--user", "--no-ask-password", "restart", svc_name],
timeout=15,
)
restarted.append(svc_name)
def on_unit_timeout(svc_name: str, exc: subprocess.TimeoutExpired) -> None:
failed.append(svc_name)
timeout_cmds.append(exc.cmd)
_for_each_systemd_gateway_unit(
_list_units_stdout(units),
process_unit=process_unit,
on_unit_timeout=on_unit_timeout,
)
assert failed == ["hermes-gateway-xiaomo5"]
assert restarted == [
"hermes-gateway-xiaomo1",
"hermes-gateway-xiaomo2",
"hermes-gateway-xiaomo3",
"hermes-gateway-xiaomo4",
"hermes-gateway-xiaomo6",
"hermes-gateway-xiaomo7",
"hermes-gateway",
]
assert set(restarted) | set(failed) == set(units)
assert timeout_cmds == [
["systemctl", "--user", "--no-ask-password", "restart", "hermes-gateway-xiaomo5"]
]
def test_non_gateway_units_in_list_output_are_ignored(self):
seen: list[str] = []
_for_each_systemd_gateway_unit(
"\n".join(
[
"ssh.service loaded active running",
"hermes-gateway-coder.service loaded active running",
"not-a-service loaded active running",
"",
]
),
process_unit=seen.append,
on_unit_timeout=lambda *_: pytest.fail("unexpected timeout"),
)
assert seen == ["hermes-gateway-coder"]
def test_process_errors_other_than_timeout_still_propagate(self):
def process_unit(_svc_name: str) -> None:
raise RuntimeError("not a timeout")
with pytest.raises(RuntimeError, match="not a timeout"):
_for_each_systemd_gateway_unit(
_list_units_stdout(["hermes-gateway"]),
process_unit=process_unit,
on_unit_timeout=lambda *_: pytest.fail("timeout handler must not run"),
)
class TestIncompleteFleetRestartWarning:
def test_warns_with_exact_unrestarted_units(self, capsys):
_warn_incomplete_gateway_fleet_restart(
["hermes-gateway-xiaomo5", "hermes-gateway-xiaomo6", "hermes-gateway-xiaomo5"]
)
out = capsys.readouterr().out
assert "Update incomplete" in out
assert out.count("hermes-gateway-xiaomo5") == 1
assert "hermes-gateway-xiaomo6" in out
assert "pre-update code" in out