Skip to content

The agent that grows with you

fix(google_chat): request both extras before surfacing the restart

ethernet94a47320f129
diff --git a/plugins/platforms/google_chat/adapter.py b/plugins/platforms/google_chat/adapter.py
index dbe90e41261..083bed98ac8 100644
--- a/plugins/platforms/google_chat/adapter.py
+++ b/plugins/platforms/google_chat/adapter.py
@@ -200,9 +200,18 @@ def ensure_google_chat_deps() -> bool:
global _google_modules_loaded, GOOGLE_CHAT_AVAILABLE
if GOOGLE_CHAT_AVAILABLE:
return True
- from pm import ensure_import
+ from pm import InstallError, ensure_import
+ # Request BOTH extras before surfacing a failure: a successful install raises
+ # InstallError("restart Hermes to activate…") for the first extra, and aborting
+ # there would leave the second uninstalled — the restart would land back here.
+ failures: list[InstallError] = []
for extra in ("google", "google-chat"):
- ensure_import(extra)
+ try:
+ ensure_import(extra)
+ except InstallError as exc:
+ failures.append(exc)
+ if failures:
+ raise failures[0]
_google_modules_loaded = False
return _load_google_modules()
diff --git a/tests/gateway/test_google_chat_oauth_dependencies.py b/tests/gateway/test_google_chat_oauth_dependencies.py
index c7f7c449042..1e602271408 100644
--- a/tests/gateway/test_google_chat_oauth_dependencies.py
+++ b/tests/gateway/test_google_chat_oauth_dependencies.py
@@ -59,3 +59,22 @@ def test_ensure_deps_surfaces_install_reason(monkeypatch):
monkeypatch.setattr(pm, "ensure_import", blocked)
with pytest.raises(RuntimeError, match="lazy installs are disabled"):
adapter.ensure_google_chat_deps()
+
+
+def test_ensure_deps_requests_every_extra_before_reporting_a_restart(monkeypatch):
+ """A successful install of the FIRST extra raises InstallError("restart Hermes…"); stopping
+ there left the second extra uninstalled, so the restart landed right back here. Both are
+ requested in one pass and the first failure is what the registry sees."""
+ from plugins.platforms.google_chat import adapter
+
+ monkeypatch.setattr(adapter, "GOOGLE_CHAT_AVAILABLE", False)
+ requested = []
+
+ def installs_then_needs_restart(extra):
+ requested.append(extra)
+ raise pm.InstallError("venv", f"{extra} installed; restart Hermes to activate the new dependency environment")
+
+ monkeypatch.setattr(pm, "ensure_import", installs_then_needs_restart)
+ with pytest.raises(pm.InstallError, match="google installed"):
+ adapter.ensure_google_chat_deps()
+ assert requested == ["google", "google-chat"]