The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: retain WhatsApp runtime binary guards under optimized Python
ethernete4b886f71cbe
diff --git a/hermes_cli/main_platform_setup.py b/hermes_cli/main_platform_setup.pyindex 1f858a138ed..f72db22199c 100644--- a/hermes_cli/main_platform_setup.py+++ b/hermes_cli/main_platform_setup.py@@ -109,7 +109,8 @@ def _whatsapp_install_bridge(bridge_dir) -> bool:if npm is None:env = pm.ensure("npm", explicit=True).envinstalled = pm.installed_package("npm")- assert installed is not None and installed.binary is not None+ if installed is None or installed.binary is None:+ raise pm.InstallError("npm", "npm binary is missing after preparation")npm = str(installed.binary)result = subprocess.run([npm, "install", "--no-fund", "--no-audit", "--progress=false"],@@ -191,7 +192,8 @@ def cmd_whatsapp(args):try:pm.ensure("node", explicit=True)installed = pm.installed_package("node")- assert installed is not None and installed.binary is not None+ if installed is None or installed.binary is None:+ raise pm.InstallError("node", "Node.js binary is missing after preparation")node = str(installed.binary)except pm.InstallError as exc:print(f" ✗ Node.js preparation failed: {exc}")diff --git a/hermes_cli/web_routers/messaging.py b/hermes_cli/web_routers/messaging.pyindex 48bccd37d5c..d4722c3ea25 100644--- a/hermes_cli/web_routers/messaging.py+++ b/hermes_cli/web_routers/messaging.py@@ -377,7 +377,8 @@ def _ensure_whatsapp_bridge_dependencies(bridge_dir: Path) -> None:if npm is None:env = pm.ensure("npm", explicit=True).envinstalled = pm.installed_package("npm")- assert installed is not None and installed.binary is not None+ if installed is None or installed.binary is None:+ raise pm.InstallError("npm", "npm binary is missing after preparation")npm = str(installed.binary)# npm output is UTF-8; encoding= guards the Windows ANSI-code-page# default against undefined bytes crashing the reader thread.@@ -412,7 +413,8 @@ def _spawn_whatsapp_pairing_process(session_path: Path, mode: str) -> subprocesstry:pm.ensure("node", explicit=True)installed = pm.installed_package("node")- assert installed is not None and installed.binary is not None+ if installed is None or installed.binary is None:+ raise pm.InstallError("node", "Node.js binary is missing after preparation")node = str(installed.binary)except pm.InstallError as exc:raise HTTPException(status_code=500, detail=f"Node.js preparation failed: {exc}") from excdiff --git a/tests/hermes_cli/test_whatsapp_missing_runtime.py b/tests/hermes_cli/test_whatsapp_missing_runtime.pynew file mode 100644index 00000000000..31a33e98bed--- /dev/null+++ b/tests/hermes_cli/test_whatsapp_missing_runtime.py@@ -0,0 +1,62 @@+"""A successful PM preparation must still supply a runnable bridge binary."""++from types import SimpleNamespace++import pytest+from fastapi import HTTPException+++def _missing_package(monkeypatch):+ import pm+ import hermes_constants++ monkeypatch.setattr(hermes_constants, "find_node_executable", lambda executable: None)+ monkeypatch.setattr(hermes_constants, "with_hermes_node_path", lambda: {})+ monkeypatch.setattr(pm, "ensure", lambda package, explicit: SimpleNamespace(env={}))+ monkeypatch.setattr(pm, "installed_package", lambda package: None)++[email protected]("executable", ["npm", "node"])+def test_dashboard_reports_prepared_bridge_binary_missing(tmp_path, monkeypatch, executable):+ from hermes_cli.web_routers import messaging+ from gateway.platforms import whatsapp_common++ _missing_package(monkeypatch)+ bridge_dir = tmp_path / "bridge"+ bridge_dir.mkdir()+ (bridge_dir / "bridge.js").write_text("", encoding="utf-8")+ monkeypatch.setattr(whatsapp_common, "resolve_whatsapp_bridge_dir", lambda: bridge_dir)+ if executable == "npm":+ operation = lambda: messaging._ensure_whatsapp_bridge_dependencies(bridge_dir)+ else:+ monkeypatch.setattr(messaging, "_ensure_whatsapp_bridge_dependencies", lambda path: None)+ operation = lambda: messaging._spawn_whatsapp_pairing_process(tmp_path / "session", "bot")+ with pytest.raises(HTTPException) as caught:+ operation()+ if caught.value.status_code != 500 or executable not in caught.value.detail or "binary" not in caught.value.detail:+ pytest.fail(f"Unexpected dashboard error: {caught.value!r}")++[email protected]("executable", ["npm", "node"])+def test_cli_reports_prepared_bridge_binary_missing(tmp_path, monkeypatch, capsys, executable):+ from hermes_cli import main, main_platform_setup as setup+ from gateway.platforms import whatsapp_common++ _missing_package(monkeypatch)+ bridge_dir = tmp_path / "bridge"+ bridge_dir.mkdir()+ (bridge_dir / "bridge.js").write_text("", encoding="utf-8")+ if executable == "npm":+ if setup._whatsapp_install_bridge(bridge_dir) is not False:+ pytest.fail("CLI continued despite missing npm binary")+ else:+ monkeypatch.setattr(main, "_require_tty", lambda command: None)+ monkeypatch.setattr(setup, "_whatsapp_choose_mode", lambda *args: "bot")+ monkeypatch.setattr(setup, "_whatsapp_allowed_users", lambda *args: None)+ monkeypatch.setattr(setup, "_whatsapp_install_bridge", lambda path: True)+ monkeypatch.setattr(whatsapp_common, "resolve_whatsapp_bridge_dir", lambda: bridge_dir)+ monkeypatch.setattr(main, "get_hermes_home", lambda: tmp_path)+ setup.cmd_whatsapp(SimpleNamespace())+ output = capsys.readouterr().out+ if executable not in output or "binary" not in output:+ pytest.fail(f"CLI did not report the missing binary: {output!r}")