test(gateway): a first gateway.run import under a routed override bridges the launch home

Invariant for the import-time config bridge: a multiplexed backend's first import of
gateway.run can happen inside a routed profile's session (hermes serve imports it lazily
from an agent build), and the bridge must still write the launch home's agent.max_turns and
terminal.cwd into the process env. Red on the previous gateway.run (HERMES_MAX_ITERATIONS
came from the routed profile), green with get_process_hermes_home().
This commit is contained in:
teknium1
2026-09-23 07:04:30 -07:00
committed by Teknium
parent 12ca697015
commit 02fa29943a

View File

@@ -21,7 +21,9 @@ import pytest
PROJECT_ROOT = Path(__file__).resolve().parents[2]
def _run_gateway_import(hermes_home: Path, initial_env: dict[str, str]) -> dict[str, str]:
def _run_gateway_import(
hermes_home: Path, initial_env: dict[str, str], routed_home: Path | None = None
) -> dict[str, str]:
"""Import gateway.run in a clean subprocess and return the post-import env.
The bridge runs at module-import time, so simply importing is enough
@@ -33,6 +35,9 @@ def _run_gateway_import(hermes_home: Path, initial_env: dict[str, str]) -> dict[
f"""
import os, sys
sys.path.insert(0, {str(PROJECT_ROOT)!r})
if {str(routed_home or "")!r}:
from hermes_constants import set_hermes_home_override
set_hermes_home_override({str(routed_home or "")!r})
try:
from gateway import run # noqa: F401 — module import triggers bridge
@@ -50,6 +55,7 @@ def _run_gateway_import(hermes_home: Path, initial_env: dict[str, str]) -> dict[
"HERMES_GATEWAY_BUSY_TEXT_MODE",
"HERMES_GATEWAY_PLATFORM_CONNECT_TIMEOUT",
"HERMES_TIMEZONE",
"TERMINAL_CWD",
):
v = os.environ.get(k)
if v is not None:
@@ -218,3 +224,22 @@ def test_env_platform_connect_timeout_wins_over_config(hermes_home: Path) -> Non
)
assert env.get("HERMES_GATEWAY_PLATFORM_CONNECT_TIMEOUT") == "120"
def test_first_import_under_a_routed_override_bridges_the_process_home(tmp_path: Path) -> None:
"""A multiplexed backend first imports gateway.run lazily inside a routed profile's session;
the import-time bridge must still write the LAUNCH home's config into the process env."""
import yaml
homes = {}
for name, turns in (("launch", 111), ("routed", 222)):
home = tmp_path / name
(home / "work").mkdir(parents=True)
cfg = {"agent": {"max_turns": turns}, "terminal": {"cwd": str(home / "work")}}
(home / "config.yaml").write_text(yaml.safe_dump(cfg), encoding="utf-8")
homes[name] = home
env = _run_gateway_import(homes["launch"], {}, routed_home=homes["routed"])
assert env.get("HERMES_MAX_ITERATIONS") == "111"
assert env.get("TERMINAL_CWD") == str(homes["launch"] / "work")