Production: - agent/bedrock_adapter.py, agent/vertex_adapter.py: pm.ensure_import ran at module import. In any process that imports these modules without a committed PM selection (CI's build_environment test venv, a fresh checkout) that sync rebuilt the dependency environment mid-process and replaced sys.path with a generation missing the caller's own packages (anthropic, aiohttp vanished). The extra is now ensured at first client build / credential request. - plugins/platforms/matrix/adapter.py: a complete install needs no ensure_and_bind round trip; only a partial one syncs. - tools/browser_tool.py: drop the facade's duplicate warm_agent_browser_npx_cache shim; the compat pointer already resolves to browser_tool_install. Test harness: - tests/home_io_guard.py: PATH-entry probes (shutil.which) and the running interpreter's own installation (stdlib reads, realpath ancestry, fixture symlinks into it) are not Hermes state; a patched Path.expanduser must not crash the guard. run_tests.sh no longer filters PATH — the guard owns it. - tests/tui_gateway/conftest.py: import hermes_bootstrap before any file opens a MagicMock hermes_constants window (6 files exited the process at boot). - tests/hermes_cli/conftest.py probe_root: scratch checkouts the import guard probes need hermes_bootstrap.py (the launcher imports it). - tests/pm/_fixtures.py stage_host_python: a copied relocatable python needs its stdlib beside it (No module named 'encodings' on CI). - tests/install/e2e-assets/smoke-env.mjs: dependency-free env shaping so the source-build-env probe runs under bare node (main deleted the Playwright entry it was imported through). - adapt main's new tests to branch seams (model_metadata_http, launch completion tail, CI toolchain exports uv after python, source_launch hermes_cli stub, systemd_notify single marker).
82 lines
2.2 KiB
Python
82 lines
2.2 KiB
Python
"""Tests for the optional systemd event-loop watchdog protocol."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import socket
|
|
|
|
import pytest
|
|
|
|
pytestmark = pytest.mark.platforms("linux")
|
|
|
|
|
|
# abstract (NUL-prefixed) AF_UNIX names are a Linux kernel feature
|
|
def test_notify_supports_systemd_abstract_socket(monkeypatch):
|
|
name = "\0hermes-test-notify"
|
|
receiver = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
|
receiver.bind(name)
|
|
receiver.settimeout(1.0)
|
|
monkeypatch.setenv("NOTIFY_SOCKET", "@hermes-test-notify")
|
|
|
|
try:
|
|
from gateway.systemd_notify import notify
|
|
|
|
assert notify("WATCHDOG=1") is True
|
|
assert receiver.recv(4096) == b"WATCHDOG=1"
|
|
finally:
|
|
receiver.close()
|
|
|
|
|
|
def test_notify_uses_nonblocking_datagram_send(monkeypatch):
|
|
calls: list[object] = []
|
|
|
|
class _Sender:
|
|
def __enter__(self):
|
|
return self
|
|
|
|
def __exit__(self, *_args):
|
|
return None
|
|
|
|
def setblocking(self, value):
|
|
calls.append(("setblocking", value))
|
|
|
|
def connect(self, address):
|
|
calls.append(("connect", address))
|
|
|
|
def send(self, payload):
|
|
calls.append(("send", payload))
|
|
|
|
import gateway.systemd_notify as notify_mod
|
|
|
|
monkeypatch.setenv("NOTIFY_SOCKET", "/tmp/hermes-test-notify")
|
|
monkeypatch.setattr(notify_mod.socket, "socket", lambda *_args: _Sender())
|
|
|
|
assert notify_mod.notify("READY=1") is True
|
|
assert calls[0] == ("setblocking", False)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_watchdog_sends_ready_heartbeat_and_stopping(monkeypatch):
|
|
calls: list[str] = []
|
|
monkeypatch.setenv("NOTIFY_SOCKET", "/tmp/hermes-test-notify")
|
|
monkeypatch.setenv("WATCHDOG_USEC", "20000")
|
|
|
|
import gateway.systemd_notify as notify_mod
|
|
|
|
monkeypatch.setattr(
|
|
notify_mod, "notify", lambda message: calls.append(message) or True
|
|
)
|
|
watchdog = notify_mod.SystemdWatchdog(lag_tolerance_seconds=1.0)
|
|
|
|
assert watchdog.start() is True
|
|
assert watchdog.ready("Gateway running") is True
|
|
await asyncio.sleep(0.04)
|
|
await watchdog.stop()
|
|
|
|
assert any(message.startswith("READY=1") for message in calls)
|
|
assert "WATCHDOG=1" in calls
|
|
assert calls[-1] == "STOPPING=1"
|
|
assert watchdog.unhealthy is False
|
|
|
|
|