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.
This commit is contained in:
briandevans 2026-05-22 02:11:31 -07:00 committed by kshitij
parent c25f9d1d36
commit 5dc232a6e2
3 changed files with 42 additions and 0 deletions

View file

@ -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."""

View file

@ -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

View file

@ -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
# ============================================================================