From 5dc232a6e26e93bc602ac7e409a93d44ef2ab38a Mon Sep 17 00:00:00 2001 From: briandevans <252620095+briandevans@users.noreply.github.com> Date: Fri, 22 May 2026 02:11:31 -0700 Subject: [PATCH] test(tools): disarm lazy-install probe so _HAS_FASTER_WHISPER patches work `b5c6d9ac0` ("fix: wire STT lazy-install into transcription_tools.py") added `_try_lazy_install_stt()`, which calls `importlib.util.find_spec("faster_whisper")` after `ensure()` runs. In the dev / CI environment `faster_whisper` is already installed, so the probe returns truthy and `_get_provider()` returns "local" even when the test has patched `_HAS_FASTER_WHISPER=False` to simulate "not installed". Add a per-file autouse fixture that patches `_try_lazy_install_stt` to return False so the simulation stays accurate. The 16 baseline failures across `test_transcription_tools.py`, `test_transcription.py`, and `test_transcription_dotenv_fallback.py` disappear; the production lazy-install path is unaffected at runtime. --- tests/tools/test_transcription.py | 14 ++++++++++++++ tests/tools/test_transcription_dotenv_fallback.py | 14 ++++++++++++++ tests/tools/test_transcription_tools.py | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/tests/tools/test_transcription.py b/tests/tools/test_transcription.py index 32f0ad48798..606a3e100a2 100644 --- a/tests/tools/test_transcription.py +++ b/tests/tools/test_transcription.py @@ -28,6 +28,20 @@ def _clear_openai_env(monkeypatch): monkeypatch.delenv("OPENAI_API_KEY", raising=False) +@pytest.fixture(autouse=True) +def _disable_lazy_stt_install(): + """Disarm the runtime lazy-install probe so static ``_HAS_FASTER_WHISPER`` + patches accurately simulate 'faster-whisper not installed'. + + Without this, ``_try_lazy_install_stt()`` calls + ``importlib.util.find_spec("faster_whisper")``, which returns truthy + whenever the package is installed in the dev / CI environment — + defeating the test's ``_HAS_FASTER_WHISPER=False`` patch. + """ + with patch("tools.transcription_tools._try_lazy_install_stt", return_value=False): + yield + + class TestGetProvider: """_get_provider() picks the right backend based on config + availability.""" diff --git a/tests/tools/test_transcription_dotenv_fallback.py b/tests/tools/test_transcription_dotenv_fallback.py index 365b910d4cc..6248d0acd06 100644 --- a/tests/tools/test_transcription_dotenv_fallback.py +++ b/tests/tools/test_transcription_dotenv_fallback.py @@ -28,6 +28,20 @@ def isolate_env(monkeypatch): monkeypatch.delenv(key, raising=False) +@pytest.fixture(autouse=True) +def _disable_lazy_stt_install(): + """Disarm the runtime lazy-install probe so static ``_HAS_FASTER_WHISPER`` + patches accurately simulate 'faster-whisper not installed'. + + Without this, ``_try_lazy_install_stt()`` calls + ``importlib.util.find_spec("faster_whisper")``, which returns truthy + whenever the package is installed in the dev / CI environment — + defeating the test's ``_HAS_FASTER_WHISPER=False`` patch. + """ + with patch("tools.transcription_tools._try_lazy_install_stt", return_value=False): + yield + + class TestProviderSelectionGate: """``_get_provider`` picks the STT backend. If it only consulted ``os.environ`` a user with keys in ``~/.hermes/.env`` would be told diff --git a/tests/tools/test_transcription_tools.py b/tests/tools/test_transcription_tools.py index 7f83565b5d8..953a68be79e 100644 --- a/tests/tools/test_transcription_tools.py +++ b/tests/tools/test_transcription_tools.py @@ -53,6 +53,20 @@ def clean_env(monkeypatch): monkeypatch.delenv("HERMES_LOCAL_STT_LANGUAGE", raising=False) +@pytest.fixture(autouse=True) +def _disable_lazy_stt_install(): + """Disarm the runtime lazy-install probe so static ``_HAS_FASTER_WHISPER`` + patches accurately simulate 'faster-whisper not installed'. + + Without this, ``_try_lazy_install_stt()`` calls + ``importlib.util.find_spec("faster_whisper")``, which returns truthy + whenever the package is installed in the dev / CI environment — + defeating the test's ``_HAS_FASTER_WHISPER=False`` patch. + """ + with patch("tools.transcription_tools._try_lazy_install_stt", return_value=False): + yield + + # ============================================================================ # _get_provider — full permutation matrix # ============================================================================