Skip to content

The agent that grows with you

fix(cli): the gateway seams stay inert for HermesCLI test doubles

Teknium0cad460db9bf
diff --git a/hermes_cli/cli_info_mixin.py b/hermes_cli/cli_info_mixin.py
index 068a4faba57..f30a6e605cc 100644
--- a/hermes_cli/cli_info_mixin.py
+++ b/hermes_cli/cli_info_mixin.py
@@ -128,7 +128,7 @@ class CLIInfoMixin:
enabled_toolsets=self.enabled_toolsets, session_id=self.session_id,
context_length=ctx_len, provider=self.provider, context_pinned=ctx_pinned)
- gateway_inventory = getattr(self._session_db, "banner_inventory", lambda: None)()
+ gateway_inventory = getattr(getattr(self, "_session_db", None), "banner_inventory", lambda: None)()
if gateway_inventory is not None:
# The gateway session's snapshot (the TUI banner's data): the CLI enumerates nothing.
self._defer_tool_warnings = True
diff --git a/hermes_cli/cli_init_mixin.py b/hermes_cli/cli_init_mixin.py
index dd7915cadf0..6858814e042 100644
--- a/hermes_cli/cli_init_mixin.py
+++ b/hermes_cli/cli_init_mixin.py
@@ -359,8 +359,9 @@ class CLIInitMixin:
def _ensure_gateway_session(self):
"""Create (or resume) this CLI's gateway session and adopt the id it returns, before the banner
and the first turn. Idempotent; a store without the gateway facade (tests) is left alone."""
- store = self._session_db
- if getattr(self, "_gateway_session_open", False) or not hasattr(store, "open_session"):
+ from hermes_cli.gateway_session_store import GatewaySessionStore
+ store = getattr(self, "_session_db", None)
+ if getattr(self, "_gateway_session_open", False) or not isinstance(store, GatewaySessionStore):
return
launch = {"model": self.model if getattr(self, "_explicit_model_override", False) else None,
"provider": (self.requested_provider if getattr(self, "_explicit_model_override", False)
diff --git a/tests/hermes_cli/test_cli_provider_resolution.py b/tests/hermes_cli/test_cli_provider_resolution.py
index 6e197b98b1c..b7230bdcf50 100644
--- a/tests/hermes_cli/test_cli_provider_resolution.py
+++ b/tests/hermes_cli/test_cli_provider_resolution.py
@@ -286,7 +286,8 @@ def test_runtime_resolution_failure_is_not_sticky(monkeypatch):
monkeypatch.setattr("hermes_cli.runtime_provider.resolve_runtime_provider", _runtime_resolve)
monkeypatch.setattr("hermes_cli.runtime_provider.format_runtime_provider_error", lambda exc: str(exc))
- monkeypatch.setattr("run_agent.AIAgent", _DummyAgent)
+ monkeypatch.setattr("hermes_cli.gateway_agent.GatewayAgent", _DummyAgent)
+ monkeypatch.setattr("hermes_cli.gateway_session_store.session_store", lambda: None) # no live gateway
shell = cli.HermesCLI(model="gpt-5", compact=True, max_turns=1)
diff --git a/tests/hermes_cli/test_cli_session_store_shared_registry.py b/tests/hermes_cli/test_cli_session_store_shared_registry.py
index f8e83ffa6b1..40cd916253c 100644
--- a/tests/hermes_cli/test_cli_session_store_shared_registry.py
+++ b/tests/hermes_cli/test_cli_session_store_shared_registry.py
@@ -1,37 +1,21 @@
-"""The CLI's session store must be the registry's shared handle for state.db.
+"""The CLI's session store is the gateway's, never a state.db writer in the CLI process.
-``_init_session_store`` used to construct a bare ``SessionDB()``. The goal/loop/heartbeat
-managers acquire the same path through ``hermes_state_registry`` from the REPL thread a
-moment later, so a bare handle meant a SECOND full open — including the /proc-wide
-deleted-WAL sidecar scan (~4k readlinks, each a GIL round-trip against the busy startup
-threads) — which showed up as the post-banner freeze before the first prompt.
+Main acquired ``hermes_state_registry`` (a writer handle) at startup. Rewired, the gateway is the
+single writer: ``_init_session_store`` builds a ``GatewaySessionStore`` and opens no SessionDB.
"""
from types import SimpleNamespace
-from hermes_cli import goals
from cli import HermesCLI
-def test_cli_session_store_is_the_registry_handle_goals_reuse(monkeypatch):
+def test_cli_session_store_is_the_gateway_store_and_opens_no_writer(monkeypatch):
import hermes_state_registry
+ from hermes_cli.gateway_session_store import GatewaySessionStore
- monkeypatch.setattr(goals, "_DB_CACHE", {})
constructed = []
- real_open = hermes_state_registry._open_session_db
-
- def recording_open(path):
- constructed.append(path)
- return real_open(path)
-
- monkeypatch.setattr(hermes_state_registry, "_open_session_db", recording_open)
-
+ monkeypatch.setattr(hermes_state_registry, "_open_session_db", lambda path: constructed.append(path))
cli = SimpleNamespace()
- try:
- HermesCLI._init_session_store(cli)
- assert cli._session_db is not None and not cli._session_db_unavailable
- # goals/loops/heartbeat go through the registry: same object, no second open.
- assert goals._get_session_db() is cli._session_db
- assert len(constructed) == 1
- finally:
- hermes_state_registry.close_all()
+ HermesCLI._init_session_store(cli)
+ assert isinstance(cli._session_db, GatewaySessionStore) and not cli._session_db_unavailable
+ assert constructed == []
diff --git a/tests/hermes_cli/test_mcp_discovery_timing.py b/tests/hermes_cli/test_mcp_discovery_timing.py
index b847118f77b..1b55daf7f74 100644
--- a/tests/hermes_cli/test_mcp_discovery_timing.py
+++ b/tests/hermes_cli/test_mcp_discovery_timing.py
@@ -179,8 +179,8 @@ def test_init_agent_forwards_single_query_flag(monkeypatch):
"ensure_mcp_discovery_before_agent_build",
_fake_ensure,
)
- import run_agent
- monkeypatch.setattr(run_agent, "AIAgent", lambda *_a, **_k: types.SimpleNamespace())
+ import hermes_cli.gateway_agent as gateway_agent
+ monkeypatch.setattr(gateway_agent, "GatewayAgent", lambda *_a, **_k: types.SimpleNamespace())
assert cli._init_agent() is True
assert seen.get("single_query") is True
@@ -206,8 +206,8 @@ def test_init_agent_defaults_to_interactive(monkeypatch):
"ensure_mcp_discovery_before_agent_build",
_fake_ensure,
)
- import run_agent
- monkeypatch.setattr(run_agent, "AIAgent", lambda *_a, **_k: types.SimpleNamespace())
+ import hermes_cli.gateway_agent as gateway_agent
+ monkeypatch.setattr(gateway_agent, "GatewayAgent", lambda *_a, **_k: types.SimpleNamespace())
assert cli._init_agent() is True
assert seen.get("single_query") is False