Files
hermes-agent/tests/hermes_cli/test_systemd_watchdog_unit.py
kshitijk4poor 4c4845f0af fix(gateway): order the system unit after the target user's manager
run_gateway() adopts the user bus once at boot; the generated system unit had
no ordering against user@<uid>.service, so after a reboot the two race and
the adoption can miss until the next gateway restart. Emit After=/Wants=
user@<uid>.service for the unit's User= (uid now returned by
_system_service_identity, which already resolved the account). Existing
system units are flagged outdated once and refreshed on the next
install/restart. Refs #104893.
2026-09-08 22:35:39 +05:30

61 lines
1.6 KiB
Python

"""Generated service behavior for the opt-in systemd watchdog."""
from __future__ import annotations
from gateway.config import GatewayConfig
from hermes_cli import gateway as gateway_cli
def test_positive_watchdog_config_generates_notify_unit(monkeypatch):
monkeypatch.setattr(
gateway_cli,
"load_gateway_config",
lambda: GatewayConfig.from_dict({"systemd_watchdog_seconds": 120}),
raising=False,
)
unit = gateway_cli.generate_systemd_unit(system=False)
assert "Type=notify" in unit
assert "NotifyAccess=main" in unit
assert "WatchdogSec=120s" in unit
def test_system_unit_reads_watchdog_from_target_home(tmp_path, monkeypatch):
caller_home = tmp_path / "caller"
target_home = tmp_path / "target"
caller_home.mkdir()
target_home.mkdir()
(caller_home / "config.yaml").write_text(
"gateway:\n systemd_watchdog_seconds: 0\n",
encoding="utf-8",
)
(target_home / "config.yaml").write_text(
"gateway:\n systemd_watchdog_seconds: 75\n",
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(caller_home))
monkeypatch.setattr(
gateway_cli,
"_system_service_identity",
lambda _user: ("service", "service", str(tmp_path / "account"), 1001),
)
monkeypatch.setattr(
gateway_cli,
"_hermes_home_for_target_user",
lambda _home: str(target_home),
)
unit = gateway_cli.generate_systemd_unit(system=True, run_as_user="service")
assert "Type=notify" in unit
assert "WatchdogSec=75s" in unit