From 33967b4e525d20484501039f57bbe33971210fb8 Mon Sep 17 00:00:00 2001 From: briandevans <252620095+briandevans@users.noreply.github.com> Date: Tue, 28 Apr 2026 16:06:37 -0700 Subject: [PATCH] fix(tts): tolerate missing hermes_cli.config in tts_tool import Wrap the new top-level `from hermes_cli.config import get_env_value` in try/except ImportError and fall back to a thin os.getenv shim, so importing tools.tts_tool keeps working in environments where hermes_cli.config is unavailable. This matches the existing tolerance in `_load_tts_config()` (tools/tts_tool.py) and the same import-fallback pattern in tools/tool_backend_helpers.py::fal_key_is_configured. Also update the TestDotenvFallbackPerProvider docstring to accurately describe the mocking strategy: per-provider tests patch `tools.tts_tool.get_env_value` directly, while the regression-guard tests cover the lower-level `hermes_cli.config.load_env` integration. Addresses Copilot review on #17163. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/tools/test_tts_dotenv_fallback.py | 9 ++++++--- tools/tts_tool.py | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/tools/test_tts_dotenv_fallback.py b/tests/tools/test_tts_dotenv_fallback.py index ed72a78ade..37618db59a 100644 --- a/tests/tools/test_tts_dotenv_fallback.py +++ b/tests/tools/test_tts_dotenv_fallback.py @@ -34,9 +34,12 @@ def isolate_env(monkeypatch): class TestDotenvFallbackPerProvider: """For each affected provider, when only ``~/.hermes/.env`` carries the - key (mocked via ``hermes_cli.config.load_env``), the provider must find - it. Before the fix, ``os.getenv`` returned ``None`` and the provider - raised ``ValueError("X_API_KEY not set")``. + key, the provider must find it. These per-provider tests model that + dotenv-backed lookup by mocking ``tools.tts_tool.get_env_value`` directly; + the separate regression-guard tests cover the lower-level + ``hermes_cli.config.load_env`` integration. Before the fix, ``os.getenv`` + returned ``None`` and the provider raised + ``ValueError("X_API_KEY not set")``. """ def test_elevenlabs_reads_dotenv_key(self, tmp_path): diff --git a/tools/tts_tool.py b/tools/tts_tool.py index ae01843a8f..30300f2144 100644 --- a/tools/tts_tool.py +++ b/tools/tts_tool.py @@ -44,7 +44,11 @@ from urllib.parse import urljoin from hermes_constants import display_hermes_home logger = logging.getLogger(__name__) -from hermes_cli.config import get_env_value +try: + from hermes_cli.config import get_env_value +except ImportError: + def get_env_value(name, default=None): + return os.getenv(name, default) from tools.managed_tool_gateway import resolve_managed_tool_gateway from tools.tool_backend_helpers import managed_nous_tools_enabled, prefers_gateway, resolve_openai_audio_api_key from tools.xai_http import hermes_xai_user_agent