From cacb98473222b8cd18b3a5937cc2b9e8d2f522ab Mon Sep 17 00:00:00 2001 From: helix4u <4317663+helix4u@users.noreply.github.com> Date: Fri, 8 May 2026 12:55:20 -0600 Subject: [PATCH] fix(google-chat): repair setup prompt imports --- plugins/platforms/google_chat/adapter.py | 9 ++-- tests/gateway/test_google_chat.py | 55 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/plugins/platforms/google_chat/adapter.py b/plugins/platforms/google_chat/adapter.py index c371082707..bfc63bf9ee 100644 --- a/plugins/platforms/google_chat/adapter.py +++ b/plugins/platforms/google_chat/adapter.py @@ -2936,15 +2936,14 @@ def interactive_setup() -> None: prompt for env vars, persist them to ``~/.hermes/.env`` so the next gateway restart picks them up. """ - from hermes_cli.config import ( - get_env_value, - save_env_value, - prompt, - prompt_yes_no, + from hermes_cli.cli_output import ( print_info, print_success, print_warning, + prompt, + prompt_yes_no, ) + from hermes_cli.config import get_env_value, save_env_value existing_sub = get_env_value("GOOGLE_CHAT_SUBSCRIPTION_NAME") if existing_sub: diff --git a/tests/gateway/test_google_chat.py b/tests/gateway/test_google_chat.py index 4b0d73d0ea..a5a1bc0dac 100644 --- a/tests/gateway/test_google_chat.py +++ b/tests/gateway/test_google_chat.py @@ -2359,6 +2359,61 @@ class TestADCFallback: assert "google_chat_service_account_json" in msg +class TestGoogleChatInteractiveSetup: + def test_interactive_setup_uses_shared_cli_prompt_helpers(self, monkeypatch): + """Google Chat setup should not import prompt helpers from config.py.""" + from plugins.platforms.google_chat import adapter as gc_mod + + saved: dict[str, str] = {} + answers = { + "GCP project ID (e.g. my-project)": "demo-project", + "Pub/Sub subscription (projects//subscriptions/)": ( + "projects/demo-project/subscriptions/hermes-chat" + ), + "Path to Service Account JSON (or inline JSON)": "/tmp/sa.json", + "Allowed user emails (comma-separated)": "alice@example.com, bob@example.com", + "Home space for cron/notification delivery (e.g. spaces/AAAA, or empty)": ( + "spaces/AAAA" + ), + } + + def fake_get_env_value(key): + return saved.get(key, "") + + def fake_save_env_value(key, value): + saved[key] = value + + def fake_prompt(question, default=None, password=False): + return answers.get(question, default or "") + + monkeypatch.setattr("hermes_cli.config.get_env_value", fake_get_env_value) + monkeypatch.setattr("hermes_cli.config.save_env_value", fake_save_env_value) + monkeypatch.setattr("hermes_cli.cli_output.prompt", fake_prompt) + monkeypatch.setattr( + "hermes_cli.cli_output.prompt_yes_no", lambda *_a, **_kw: True + ) + monkeypatch.setattr( + "hermes_cli.cli_output.print_info", lambda *_a, **_kw: None + ) + monkeypatch.setattr( + "hermes_cli.cli_output.print_success", lambda *_a, **_kw: None + ) + monkeypatch.setattr( + "hermes_cli.cli_output.print_warning", lambda *_a, **_kw: None + ) + + gc_mod.interactive_setup() + + assert saved["GOOGLE_CHAT_PROJECT_ID"] == "demo-project" + assert ( + saved["GOOGLE_CHAT_SUBSCRIPTION_NAME"] + == "projects/demo-project/subscriptions/hermes-chat" + ) + assert saved["GOOGLE_CHAT_SERVICE_ACCOUNT_JSON"] == "/tmp/sa.json" + assert saved["GOOGLE_CHAT_ALLOWED_USERS"] == "alice@example.com,bob@example.com" + assert saved["GOOGLE_CHAT_HOME_CHANNEL"] == "spaces/AAAA" + + # =========================================================================== # Supervisor reconnect (backoff + fatal) # ===========================================================================