The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(gateway): trim the s6 handoff watchdog tests to the two invariants
kshitijk4poor237eb82e7153
diff --git a/tests/hermes_cli/test_gateway_s6_dispatch.py b/tests/hermes_cli/test_gateway_s6_dispatch.pyindex 9738486d843..dae88022307 100644--- a/tests/hermes_cli/test_gateway_s6_dispatch.py+++ b/tests/hermes_cli/test_gateway_s6_dispatch.py@@ -115,6 +115,10 @@ def _stub_s6(monkeypatch: pytest.MonkeyPatch, *, on_s6: bool) -> _CallRecorder:+def _raise_missing_sleep(file: str, args: list[str]) -> None:+ raise FileNotFoundError(2, "No such file or directory", file)++def test_redirect_falls_back_when_sleep_missing(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str],) -> None:@@ -129,10 +133,7 @@ def test_redirect_falls_back_when_sleep_missing(rec = _stub_s6(monkeypatch, on_s6=True)monkeypatch.setattr("hermes_cli.gateway._profile_suffix", lambda: "")- def missing_sleep(file: str, args: list[str]) -> None:- raise FileNotFoundError(2, "No such file or directory", file)-- monkeypatch.setattr("hermes_cli.gateway.os.execvp", missing_sleep)+ monkeypatch.setattr("hermes_cli.gateway.os.execvp", _raise_missing_sleep)block_calls: list[bool] = []monkeypatch.setattr("hermes_cli.gateway._block_until_terminated",@@ -152,18 +153,15 @@ def test_redirect_falls_back_when_sleep_missing(assert "`sleep` is unavailable" in err-def _arm_for_redirect(monkeypatch: pytest.MonkeyPatch):- """Arm the real startup watchdog the way the argv fast-path does.-- ``hermes_cli.main`` arms whenever argv carries the adjacent tokens- ``gateway run`` — which is exactly the invocation the s6 redirect- intercepts. A long timeout keeps the deadline out of the test's way:- what is under test is the handle's state at handoff, not the timer.- """+def _armed_watchdog(monkeypatch: pytest.MonkeyPatch):+ """Arm the real watchdog as hermes_cli.main's argv fast-path does; the long timeout keeps the+ deadline out of the test, only the handle state at handoff is under test."""import hermes_startup_watchdog as swmonkeypatch.delenv(sw.ENV_STARTUP_WATCHDOG, raising=False)- monkeypatch.delenv(sw.ENV_STARTUP_WATCHDOG_TIMEOUT_S, raising=False)+ monkeypatch.delenv("HERMES_S6_SUPERVISED_CHILD", raising=False)+ monkeypatch.delenv("HERMES_GATEWAY_NO_SUPERVISE", raising=False)+ monkeypatch.setattr("hermes_cli.gateway._profile_suffix", lambda: "")sw._reset_for_tests()handle = sw.arm_startup_watchdog(timeout_s=3600)assert handle is not None and handle.is_alive()@@ -173,30 +171,14 @@ def _arm_for_redirect(monkeypatch: pytest.MonkeyPatch):def test_redirect_disarms_startup_watchdog_before_parking(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str],) -> None:- """The #36208 in-process heartbeat must not park under an armed- startup watchdog.-- The CMD process arms the OOF-298 watchdog (its argv is ``gateway- run``) and then hands the gateway to s6 — it never reaches a- GatewayRunner, so nothing downstream disarms. Parked on- ``signal.pause()`` it burns ~zero CPU and holds no progress lease,- reading exactly like the wedged startup the watchdog exists to kill:- it would ``os._exit(75)`` the container's main process on schedule- while the supervised gateway is perfectly healthy.- """+ """Issue #102000: the CMD process never reaches a GatewayRunner, so the #36208 in-process+ heartbeat must not park under an armed watchdog (it would os._exit(75) a healthy container)."""from hermes_cli import gateway as gw- sw, handle = _arm_for_redirect(monkeypatch)+ sw, handle = _armed_watchdog(monkeypatch)try:_stub_s6(monkeypatch, on_s6=True)- monkeypatch.setattr("hermes_cli.gateway._profile_suffix", lambda: "")- monkeypatch.delenv("HERMES_S6_SUPERVISED_CHILD", raising=False)- monkeypatch.delenv("HERMES_GATEWAY_NO_SUPERVISE", raising=False)-- def missing_sleep(file: str, args: list[str]) -> None:- raise FileNotFoundError(2, "No such file or directory", file)-- monkeypatch.setattr("hermes_cli.gateway.os.execvp", missing_sleep)+ monkeypatch.setattr("hermes_cli.gateway.os.execvp", _raise_missing_sleep)disarmed_at_park: list[bool] = []monkeypatch.setattr("hermes_cli.gateway._block_until_terminated",@@ -205,51 +187,26 @@ def test_redirect_disarms_startup_watchdog_before_parking(assert gw._maybe_redirect_run_to_s6_supervision(_Args()) is True- assert disarmed_at_park == [True], (- "the CMD process parked forever with the startup watchdog still "- "armed — it will be hard-exited with code 75"- )- # The singleton is cleared too, so a later arm site cannot revive- # this handle's deadline.+ assert disarmed_at_park == [True]assert sw._handle is None- # And the timer thread actually stands down rather than lingering.- handle.join(timeout=5)- assert not handle.is_alive()finally:sw._reset_for_tests()capsys.readouterr()-def test_redirect_disarms_startup_watchdog_before_exec(- monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str],-) -> None:- """Same handoff, the normal ``sleep infinity`` path.-- The exec replaces the process image (watchdog thread included), so- this arm is not a live hazard — but the disarm belongs to the- handoff, not to one of its two heartbeats. Pinning it here keeps a- future third heartbeat from inheriting the parked-process bug.- """+def test_redirect_not_taken_leaves_startup_watchdog_armed(monkeypatch: pytest.MonkeyPatch) -> None:+ """Outside s6 the gateway still boots in-process, so GatewayRunner's own disarm must govern."""from hermes_cli import gateway as gw- sw, handle = _arm_for_redirect(monkeypatch)+ sw, handle = _armed_watchdog(monkeypatch)try:- _stub_s6(monkeypatch, on_s6=True)- monkeypatch.setattr("hermes_cli.gateway._profile_suffix", lambda: "")- monkeypatch.delenv("HERMES_S6_SUPERVISED_CHILD", raising=False)- monkeypatch.delenv("HERMES_GATEWAY_NO_SUPERVISE", raising=False)- disarmed_at_exec: list[bool] = []- monkeypatch.setattr(- "hermes_cli.gateway.os.execvp",- lambda file, args: disarmed_at_exec.append(handle.disarmed),- )+ _stub_s6(monkeypatch, on_s6=False)- assert gw._maybe_redirect_run_to_s6_supervision(_Args()) is True+ assert gw._maybe_redirect_run_to_s6_supervision(_Args()) is False- assert disarmed_at_exec == [True]+ assert sw._handle is handle and handle.is_alive() and not handle.disarmedfinally:sw._reset_for_tests()- capsys.readouterr()# ---------------------------------------------------------------------------