The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): resolve the user systemd unit dir from the account home, not profile HOME (#98699, salvage #98715)
liuhao102408d73dae37e2
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.pyindex 22f2b7c043b..b5f8bb704f2 100644--- a/hermes_cli/gateway.py+++ b/hermes_cli/gateway.py@@ -2301,13 +2301,20 @@ def get_service_name() -> str:def user_systemd_unit_dir() -> Path:- """``$XDG_CONFIG_HOME/systemd/user`` (``~/.config`` only as the spec's default).+ """``$XDG_CONFIG_HOME/systemd/user`` (``~/.config`` only as the spec's default), ``~`` being the+ ACCOUNT home, not the process HOME.Hardcoding ``~/.config`` made every unit probe silently false-negative on a host that moves- XDG_CONFIG_HOME — doctor then reported no gateway unit while systemd was running ours.+ XDG_CONFIG_HOME — doctor then reported no gateway unit while systemd was running ours. And+ ``Path.home()`` trusts a process HOME that profile isolation may point at ``{HERMES_HOME}/home`` — the+ ACTIVE profile's, not even the one selected with ``-p`` — so ``gateway install`` wrote the unit under+ ``~/.hermes/profiles/<active>/home/.config/systemd/user/`` where ``systemctl --user`` never looks and+ ``enable`` failed with "Unit ... does not exist" (#98699). ``systemctl --user`` targets the login+ user's session, so the unit dir follows the account home like ``get_launchd_plist_path()`` does."""+ from hermes_constants import get_real_homeconfig_home = os.environ.get("XDG_CONFIG_HOME", "").strip()- base = Path(config_home) if config_home else Path.home() / ".config"+ base = Path(config_home) if config_home else Path(get_real_home()) / ".config"return base / "systemd" / "user"diff --git a/tests/hermes_cli/test_gateway_unit_paths.py b/tests/hermes_cli/test_gateway_unit_paths.pynew file mode 100644index 00000000000..81bdc6aed50--- /dev/null+++ b/tests/hermes_cli/test_gateway_unit_paths.py@@ -0,0 +1,28 @@+"""User systemd unit location and identity: the account home owns the unit dir (#98699) and a bare+``hermes-gateway.service`` pinning THIS home is this home's service (#109476)."""++import pytest++import hermes_cli.gateway as gateway++pytestmark = pytest.mark.platforms("linux")+++def test_user_unit_dir_follows_the_account_home_not_a_profile_pinned_process_home(tmp_path, monkeypatch):+ # ``hermes -p x gateway install`` launched from a process whose HOME profile isolation already+ # pointed at the ACTIVE profile's ``{HERMES_HOME}/home``; the unit must land where+ # ``systemctl --user`` looks — under the account home — not under that profile dir.+ account_home = tmp_path / "account"+ active_root = tmp_path / "active-profile-root"+ process_home = active_root / "home"+ process_home.mkdir(parents=True)+ monkeypatch.setenv("HERMES_HOME", str(active_root))+ monkeypatch.setenv("HOME", str(process_home))+ monkeypatch.setenv("HERMES_REAL_HOME", str(account_home))+ monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)++ unit_path = gateway.get_systemd_unit_path(system=False)++ assert unit_path.parent == account_home / ".config" / "systemd" / "user"+ assert not unit_path.is_relative_to(process_home)+