From ca53ea0fc4d705af276eec170e84e32bd964058f Mon Sep 17 00:00:00 2001 From: james Date: Thu, 2 Apr 2026 09:52:20 -0500 Subject: [PATCH] fix(honcho): make status run a real connectivity check --- honcho_integration/cli.py | 14 ++++++- tests/honcho_integration/test_cli.py | 57 ++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/honcho_integration/cli.py b/honcho_integration/cli.py index f6cbcedf6606..3b5a1c379b8b 100644 --- a/honcho_integration/cli.py +++ b/honcho_integration/cli.py @@ -237,6 +237,16 @@ def cmd_setup(args) -> None: print(" hermes honcho map — map this directory to a session name\n") +def _check_connection(hcfg) -> None: + """Perform a real Honcho connectivity check using the session path.""" + from honcho_integration.client import get_honcho_client + from honcho_integration.session import HonchoSessionManager + + client = get_honcho_client(hcfg) + manager = HonchoSessionManager(honcho=client, config=hcfg) + manager.get_or_create(hcfg.resolve_session_name()) + + def cmd_status(args) -> None: """Show current Honcho config and connection status.""" try: @@ -256,7 +266,7 @@ def cmd_status(args) -> None: return try: - from honcho_integration.client import HonchoClientConfig, get_honcho_client + from honcho_integration.client import HonchoClientConfig hcfg = HonchoClientConfig.from_global_config() except Exception as e: print(f" Config error: {e}\n") @@ -287,7 +297,7 @@ def cmd_status(args) -> None: if hcfg.enabled and (hcfg.api_key or hcfg.base_url): print("\n Connection... ", end="", flush=True) try: - get_honcho_client(hcfg) + _check_connection(hcfg) print("OK\n") except Exception as e: print(f"FAILED ({e})\n") diff --git a/tests/honcho_integration/test_cli.py b/tests/honcho_integration/test_cli.py index b5a1c9f618be..cfe913877a59 100644 --- a/tests/honcho_integration/test_cli.py +++ b/tests/honcho_integration/test_cli.py @@ -27,3 +27,60 @@ def test_falls_back_to_env_key(self, monkeypatch): assert _resolve_api_key({}) == "env-key" monkeypatch.delenv("HONCHO_API_KEY", raising=False) + +class TestCmdStatus: + def test_reports_connection_failure_when_session_setup_fails(self, monkeypatch, capsys, tmp_path): + import sys + import types + + import honcho_integration.cli as honcho_cli + import honcho_integration.client as client_mod + import honcho_integration.session as session_mod + + cfg_path = tmp_path / "honcho.json" + cfg_path.write_text("{}") + + monkeypatch.setitem(sys.modules, "honcho", types.SimpleNamespace()) + monkeypatch.setattr(honcho_cli, "_read_config", lambda: {"apiKey": "root-key"}) + monkeypatch.setattr(honcho_cli, "_config_path", lambda: cfg_path) + monkeypatch.setattr(honcho_cli, "_local_config_path", lambda: cfg_path) + + class FakeConfig: + enabled = True + api_key = "root-key" + workspace_id = "hermes" + host = "hermes" + base_url = None + ai_peer = "hermes" + peer_name = "genos" + recall_mode = "hybrid" + memory_mode = "hybrid" + peer_memory_modes = {} + write_frequency = "async" + + def resolve_session_name(self): + return "hermes" + + class FakeHonchoClientConfig: + @classmethod + def from_global_config(cls): + return FakeConfig() + + class FakeSessionManager: + def __init__(self, honcho, config): + self.honcho = honcho + self.config = config + + def get_or_create(self, key): + raise RuntimeError("Invalid API key") + + monkeypatch.setattr(client_mod, "HonchoClientConfig", FakeHonchoClientConfig) + monkeypatch.setattr(client_mod, "get_honcho_client", lambda cfg: object()) + monkeypatch.setattr(session_mod, "HonchoSessionManager", FakeSessionManager) + + honcho_cli.cmd_status(None) + + out = capsys.readouterr().out + assert "FAILED (Invalid API key)" in out + assert "Connection... OK" not in out +