The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: service suffix follows main profile-root rule; drop in-process cli.main tests
Teknium0ea5a879b957
diff --git a/hermes_cli/gateway_runtime_service.py b/hermes_cli/gateway_runtime_service.pyindex 673ada67e34..ec49a8db8be 100644--- a/hermes_cli/gateway_runtime_service.py+++ b/hermes_cli/gateway_runtime_service.py@@ -35,18 +35,27 @@ def remaining(deadline: float) -> float:def service_suffix(home: Path) -> str:+ """Host-service suffix for the REQUESTED home, never the initiating client's env.++ Same rule as ``hermes_cli.gateway._profile_suffix``: only the platform-native+ default home owns the bare unit name; ``<root>/profiles/<name>`` yields the+ profile name; any other root (Docker, a temp harness) yields a path hash so a+ custom root can never resolve to the production ``hermes-gateway`` unit.+ """from hermes_constants import _get_platform_default_hermes_homefrom hermes_cli.gateway import _profile_name_from_homedefault = _get_platform_default_hermes_home().resolve()home = home.resolve()- # Mirror the installer's custom-root rule for the REQUESTED home, not the- # initiating client's environment. Two custom roots can share a unit name;- # effective binding validation, not a guessed hash, disambiguates them.- if not home.is_relative_to(default):- default = home.parent.parent if home.parent.name == "profiles" else homeif home == default:return ""- return _profile_name_from_home(home, default) or hashlib.sha256(str(home).encode()).hexdigest()[:8]+ root = default+ if not home.is_relative_to(default):+ root = home.parent.parent if home.parent.name == "profiles" else home+ if home != root:+ name = _profile_name_from_home(home, root)+ if name:+ return name+ return hashlib.sha256(str(home).encode()).hexdigest()[:8]@dataclass(frozen=True)diff --git a/tests/cli/test_chat_q_exit_clear.py b/tests/cli/test_chat_q_exit_clear.pyindex 9382123d0a0..d85ddeb342c 100644--- a/tests/cli/test_chat_q_exit_clear.py+++ b/tests/cli/test_chat_q_exit_clear.py@@ -63,60 +63,6 @@ def test_print_exit_summary_skips_clear_when_clear_screen_false(monkeypatch):# ── Production-path test: single-query -q path skips the clear ──────────────-def test_single_query_main_skips_clear_on_exit_summary(monkeypatch):- """The single-query (-q) path calls _print_exit_summary without clearing."""- calls = []- clear_calls = []-- class FakeCLI:- def __init__(self, **_kwargs):- self.console = SimpleNamespace(print=lambda *_a, **_kw: calls.append("query-label"))- self.session_id = "sq-test"- self.agent = SimpleNamespace(- session_id="sq-test",- platform="cli",- )-- def _claim_active_session(self, surface, *, stderr=False):- calls.append(("claim", surface, stderr))- return True-- def _show_security_advisories(self):- calls.append("advisories")-- def chat(self, query, images=None):- calls.append(("chat", query, images))- return "done"-- def _print_exit_summary(self, clear_screen=True):- calls.append(("summary", clear_screen))- if clear_screen:- clear_calls.append("CLEARED") # should NOT happen-- monkeypatch.setattr(cli_mod, "HermesCLI", FakeCLI)- monkeypatch.setattr(cli_mod.atexit, "register", lambda *_a, **_kw: None)- monkeypatch.setattr(- cli_mod,- "_finalize_single_query",- lambda fake_cli: calls.append(("finalize", fake_cli.session_id)),- )-- cli_mod.main(query="hello", quiet=False, toolsets="terminal")-- assert calls == [- ("claim", "cli", False),- "query-label",- "advisories",- ("chat", "hello", None),- ("summary", False), # <-- clear_screen=False for single-query- ("finalize", "sq-test"),- ]- assert len(clear_calls) == 0, (- "_clear_terminal_on_exit must NOT be called in single-query mode"- )---# ── Verify interactive mode still clears ────────────────────────────────────def test_print_exit_summary_still_clears_in_interactive_path(monkeypatch):"""Interactive mode should still clear the screen (preserving #38928)."""diff --git a/tests/cli/test_cli_preloaded_skills.py b/tests/cli/test_cli_preloaded_skills.pyindex 732fee4e834..33d233ae3a9 100644--- a/tests/cli/test_cli_preloaded_skills.py+++ b/tests/cli/test_cli_preloaded_skills.py@@ -48,92 +48,6 @@ def _make_real_cli(**kwargs):return cli_mod.HermesCLI(**kwargs)-class _DummyCLI:- def __init__(self, **kwargs):- self.kwargs = kwargs- self.session_id = "session-123"- self.system_prompt = "base prompt"- self.preloaded_skills = []-- def show_banner(self):- return None-- def show_tools(self):- return None-- def show_toolsets(self):- return None-- def run(self):- return None---def _real_finalize(cli_obj):- """Call the real HermesCLI.finalize_preloaded_skills on a dummy object."""- return _REAL_FINALIZE(cli_obj)---def _capture_real_finalize():- import cli as cli_mod- return cli_mod.HermesCLI.__dict__["finalize_preloaded_skills"]---_REAL_FINALIZE = _capture_real_finalize()---def test_main_applies_preloaded_skills_to_system_prompt(monkeypatch):- import cli as cli_mod-- created = {}-- def fake_cli(**kwargs):- created["cli"] = _DummyCLI(**kwargs)- return created["cli"]-- monkeypatch.setattr(cli_mod, "HermesCLI", fake_cli)- monkeypatch.setattr(- cli_mod,- "build_preloaded_skills_prompt",- lambda skills, task_id=None: ("skill prompt", ["hermes-agent-dev", "github-auth"], []),- )-- with pytest.raises(SystemExit):- cli_mod.main(skills="hermes-agent-dev,github-auth", list_tools=True)-- cli_obj = created["cli"]- # The preload now runs in a background thread and is folded in at agent- # init via finalize_preloaded_skills() (startup-latency change). Drive- # the finalize explicitly — the same call _init_agent makes.- _real_finalize(cli_obj)- assert cli_obj.system_prompt == "base prompt\n\nskill prompt"- assert cli_obj.preloaded_skills == ["hermes-agent-dev", "github-auth"]---def test_main_raises_for_unknown_preloaded_skill(monkeypatch):- import cli as cli_mod-- created = {}-- def fake_cli(**kwargs):- created["cli"] = _DummyCLI(**kwargs)- return created["cli"]-- monkeypatch.setattr(cli_mod, "HermesCLI", fake_cli)- monkeypatch.setattr(- cli_mod,- "build_preloaded_skills_prompt",- lambda skills, task_id=None: ("", [], ["missing-skill"]),- )-- with pytest.raises(SystemExit):- cli_mod.main(skills="missing-skill", list_tools=True)-- # The all-skills-unknown hard failure now surfaces when the preload is- # finalized (agent init), preserving the fail-loud contract.- with pytest.raises(ValueError, match=r"Unknown skill\(s\): missing-skill"):- _real_finalize(created["cli"])--def test_show_banner_does_not_print_skills():"""show_banner() no longer prints the activated skills line — it moved to run()."""cli_obj = _make_real_cli(compact=False)diff --git a/tests/cli/test_single_query_session_finalize.py b/tests/cli/test_single_query_session_finalize.pyindex d754c6ae91e..1199664939a 100644--- a/tests/cli/test_single_query_session_finalize.py+++ b/tests/cli/test_single_query_session_finalize.py@@ -11,8 +11,6 @@ def reset_single_query_finalize_state(monkeypatch):monkeypatch.setattr(cli, "_cleanup_done", False)--def test_finalize_single_query_releases_session_when_cleanup_fails(monkeypatch):calls = []fake_cli = SimpleNamespace(_release_active_session=lambda: calls.append("release"))@@ -55,8 +53,6 @@ def test_finalize_single_query_runs_cleanup_when_finalize_hook_fails(monkeypatchassert calls == ["finalize", "cleanup", "release"]--def test_notify_single_query_session_finalize_uses_agent_session(monkeypatch):calls = []fake_agent = SimpleNamespace(session_id="agent-session", platform="cli")@@ -79,125 +75,3 @@ def test_notify_single_query_session_finalize_uses_agent_session(monkeypatch):},)]---def test_human_single_query_main_finalizes_after_query(monkeypatch):- calls = []-- import cli as cli_mod-- class _Console:- def print(self, *_args, **_kwargs):- calls.append("query-label")-- class FakeCLI:- def __init__(self, **_kwargs):- self.console = _Console()- self.session_id = "single-query-session"- self.agent = SimpleNamespace(- session_id="single-query-session",- platform="cli",- )-- def _claim_active_session(self, surface, *, stderr=False):- calls.append(("claim", surface, stderr))- return True-- def _show_security_advisories(self):- calls.append("advisories")-- def chat(self, query, images=None):- calls.append(("chat", query, images))- return "done"-- def _print_exit_summary(self, clear_screen=True):- calls.append("summary")-- monkeypatch.setattr(cli_mod, "HermesCLI", FakeCLI)- monkeypatch.setattr(cli_mod.atexit, "register", lambda *_args, **_kwargs: None)- monkeypatch.setattr(- cli_mod,- "_finalize_single_query",- lambda fake_cli: calls.append(("finalize", fake_cli.session_id)),- )-- cli_mod.main(query="hello", quiet=False, toolsets="terminal")-- assert calls == [- ("claim", "cli", False),- "query-label",- "advisories",- ("chat", "hello", None),- "summary",- ("finalize", "single-query-session"),- ]---def test_quiet_single_query_main_finalizes_while_preserving_exit_code(monkeypatch):- calls = []-- import cli as cli_mod-- def run_conversation(*, user_message, conversation_history):- calls.append(("run", user_message, conversation_history))- return {- "final_response": "",- "error": "provider failed",- "failed": True,- }-- class FakeCLI:- def __init__(self, **_kwargs):- self.provider = "test-provider"- self.model = "test-model"- self.session_id = "quiet-session"- self.conversation_history = []- self._active_agent_route_signature = "same-route"- self.agent = SimpleNamespace(- session_id="quiet-session",- platform="cli",- quiet_mode=False,- suppress_status_output=False,- stream_delta_callback=object(),- tool_gen_callback=object(),- run_conversation=run_conversation,- )-- def _claim_active_session(self, surface, *, stderr=False):- calls.append(("claim", surface, stderr))- return True-- def _ensure_runtime_credentials(self):- calls.append("credentials")- return True-- def _resolve_turn_agent_config(self, effective_query):- calls.append(("resolve", effective_query))- return {- "signature": "same-route",- "model": None,- "runtime": None,- "request_overrides": None,- }-- def _init_agent(self, **kwargs):- calls.append(("init", kwargs))- return True-- monkeypatch.delenv("HERMES_KANBAN_TASK", raising=False)- monkeypatch.delenv("HERMES_KANBAN_GOAL_MODE", raising=False)- monkeypatch.setattr(cli_mod, "HermesCLI", FakeCLI)- monkeypatch.setattr(cli_mod.atexit, "register", lambda *_args, **_kwargs: None)- monkeypatch.setattr(- cli_mod,- "_finalize_single_query",- lambda fake_cli: calls.append(("finalize", fake_cli.session_id)),- )-- with pytest.raises(SystemExit) as exc_info:- cli_mod.main(query="hello", quiet=True, toolsets="terminal")-- assert exc_info.value.code == 1- assert ("claim", "cli", True) in calls- assert ("run", "hello", []) in calls- assert calls[-1] == ("finalize", "quiet-session")diff --git a/tests/hermes_cli/test_gateway_runtime_ensure.py b/tests/hermes_cli/test_gateway_runtime_ensure.pyindex 5929d6763ea..f9431a4eb5c 100644--- a/tests/hermes_cli/test_gateway_runtime_ensure.py+++ b/tests/hermes_cli/test_gateway_runtime_ensure.py@@ -174,6 +174,7 @@ def test_unmanaged_child_uses_explicit_home_and_survives_launcher_exit(tmp_path,@pytest.mark.linux_only[email protected]_gateway_lookalike # stub interpreter records env then exits; reaped belowdef test_unmanaged_runtime_does_not_inherit_client_yolo(tmp_path, monkeypatch):from hermes_cli import gateway_runtime_start as start