hermes-agent/tests/gateway/test_process_hermes_home_expansion.py
teknium1 235622a98d fix(desktop): expand a literal ~ in HERMES_HOME before resolving the backend home
normalizeHermesHomeRoot ran path.resolve() on the raw env value, so a
fish-style HERMES_HOME='~/.hermes' became <cwd>/~/.hermes (absolute) and was
handed to the Python backend as HERMES_HOME, where no expansion could recover
it. Expand a leading ~ against os.homedir() first; homedir is injectable for
the test.
2026-09-18 09:49:46 -07:00

28 lines
1.1 KiB
Python

"""Gateway identity-file readers expand a literal ``~`` in HERMES_HOME.
``python -m gateway.run`` never passes through the CLI's ``normalize_hermes_home_env()``, so the
process-level home readers (PID/lock/status, lifecycle ledger, heartbeat) must expand on their own
or a fish-style ``HERMES_HOME='~/.hermes'`` lands the identity files under ``<cwd>/~/.hermes``.
"""
from pathlib import Path
import pytest
from gateway import lifecycle_ledger, shutdown_watchdog, status
@pytest.mark.parametrize(
"reader",
[status._get_process_hermes_home, lifecycle_ledger._process_hermes_home,
shutdown_watchdog._process_hermes_home],
ids=["status", "lifecycle_ledger", "shutdown_watchdog"],
)
def test_process_home_readers_expand_literal_tilde(reader, tmp_path, monkeypatch):
monkeypatch.setenv("HOME", str(tmp_path))
monkeypatch.setenv("USERPROFILE", str(tmp_path))
monkeypatch.setenv("HERMES_HOME", "~/.x")
assert reader() == tmp_path / ".x"
assert reader().is_absolute()
monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".abs"))
assert reader() == Path(tmp_path / ".abs")