hermes-agent/tests/agent/test_transcription_registry.py
Teknium 6b81590c55
test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions
Systematic prune per AGENTS.md test policy, one pass over every major
test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli,
cron, tui_gateway, honcho/openviking, root-level):

- DELETE: source-reading tests (read_text/getsource on prod files),
  change-detector tests (exact catalog counts, model-name snapshots,
  config version literals), mock-echo tests (assert a mock returns what
  it was told), assertion-free/trivial tests, near-duplicate
  parametrizations (boundaries + one representative kept), async/sync
  twin duplicates, cosmetic within-file variations.
- KEEP (mandatory): security/redaction/approval guards, message-role
  alternation invariants, prompt-caching/deterministic-call-id
  invariants, issue-number regression tests (deduped), E2E tests.
- 6 test files deleted outright (script-style/no-assert or fully
  redundant); conftest.py, fakes/, fixtures/ untouched.
- tests/acp/conftest.py added: autouse fixture stubs the live
  models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server
  tests performed on every session create — test_server.py 147s → 3.4s,
  and the tests are now genuinely hermetic.
- Sleep-based slowness shrunk where safe (codex_ttfb_watchdog,
  compression_concurrent_fork, etc.); no wall-clock assertion tightened.

Verification: full hermetic suite via scripts/run_tests.sh —
2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall
(baseline: 583s wall, 13,564s subprocess CPU).
2026-07-29 13:10:23 -07:00

187 lines
6.3 KiB
Python

"""Tests for agent/transcription_registry.py and agent/transcription_provider.py.
Covers:
- Registration happy path
- Registration rejection: non-TranscriptionProvider type
- Registration rejection: empty/whitespace name
- Built-in name shadowing: warning + silent ignore (no exception)
- Re-registration: overwrites + logs at debug
- Case + whitespace insensitivity on lookup
- ABC contract: default implementations work
- ABC contract: transcribe() must be implemented
- Sync invariant: registry built-ins match tools/transcription_tools.py
"""
from __future__ import annotations
import logging
from typing import Any, Optional
import pytest
from agent import transcription_registry
from agent.transcription_provider import TranscriptionProvider
class _FakeProvider(TranscriptionProvider):
def __init__(
self,
name: str = "fake",
display: Optional[str] = None,
available: bool = True,
transcribe_impl: Optional[Any] = None,
):
self._name = name
self._display = display
self._available = available
self._transcribe_impl = transcribe_impl
@property
def name(self) -> str:
return self._name
@property
def display_name(self) -> str:
return self._display if self._display is not None else super().display_name
def is_available(self) -> bool:
return self._available
def transcribe(self, file_path: str, **kw):
if self._transcribe_impl is not None:
return self._transcribe_impl(file_path, **kw)
return {"success": True, "transcript": f"fake({file_path})", "provider": self._name}
@pytest.fixture(autouse=True)
def _reset_registry():
transcription_registry._reset_for_tests()
yield
transcription_registry._reset_for_tests()
# ---------------------------------------------------------------------------
# Registration
# ---------------------------------------------------------------------------
class TestRegistration:
def test_happy_path(self):
p = _FakeProvider(name="openrouter")
transcription_registry.register_provider(p)
assert transcription_registry.get_provider("openrouter") is p
assert [r.name for r in transcription_registry.list_providers()] == ["openrouter"]
@pytest.mark.parametrize(
"builtin",
[
"local",
"local_command",
"groq",
"openai",
"mistral",
"xai",
"elevenlabs",
"deepinfra",
],
)
def test_rejects_builtin_shadow_with_warning(self, builtin, caplog):
p = _FakeProvider(name=builtin)
with caplog.at_level(logging.WARNING, logger="agent.transcription_registry"):
transcription_registry.register_provider(p)
assert "shadows a built-in name" in caplog.text
assert builtin in caplog.text
assert transcription_registry.get_provider(builtin) is None
assert transcription_registry.list_providers() == []
# ---------------------------------------------------------------------------
# Lookup
# ---------------------------------------------------------------------------
class TestLookup:
def test_get_provider_non_string_returns_none(self):
assert transcription_registry.get_provider(None) is None # type: ignore[arg-type]
assert transcription_registry.get_provider(123) is None # type: ignore[arg-type]
def test_list_providers_sorted(self):
transcription_registry.register_provider(_FakeProvider(name="zylo"))
transcription_registry.register_provider(_FakeProvider(name="alpha"))
transcription_registry.register_provider(_FakeProvider(name="middle"))
names = [p.name for p in transcription_registry.list_providers()]
assert names == ["alpha", "middle", "zylo"]
# ---------------------------------------------------------------------------
# ABC contract
# ---------------------------------------------------------------------------
class TestABCContract:
def test_must_implement_name(self):
class Incomplete(TranscriptionProvider):
def transcribe(self, file_path, **kw):
return {"success": True, "transcript": "", "provider": "incomplete"}
# name NOT implemented
with pytest.raises(TypeError, match="abstract"):
Incomplete() # type: ignore[abstract]
def test_default_model_first_listed(self):
class WithModels(_FakeProvider):
def list_models(self):
return [{"id": "whisper-large-v3-turbo"}, {"id": "whisper-large-v3"}]
p = WithModels(name="openrouter")
assert p.default_model() == "whisper-large-v3-turbo"
def test_get_setup_schema_default_minimal(self):
p = _FakeProvider(name="openrouter")
schema = p.get_setup_schema()
assert schema["name"] == "Openrouter"
assert schema["env_vars"] == []
# ---------------------------------------------------------------------------
# Sync invariant: registry built-ins vs dispatcher built-ins
# ---------------------------------------------------------------------------
class TestBuiltinSync:
"""``_BUILTIN_NAMES`` in agent/transcription_registry.py is duplicated
from ``BUILTIN_STT_PROVIDERS`` in tools/transcription_tools.py
(importing directly would create a circular dependency). This test
fails loudly if the two lists drift — a new built-in added to
transcription_tools.py MUST also be added to
transcription_registry.py's ``_BUILTIN_NAMES`` or the registry will
accept a name the dispatcher will silently route to the wrong
handler.
"""
def test_registry_builtins_match_dispatcher_builtins(self):
from tools.transcription_tools import BUILTIN_STT_PROVIDERS
assert transcription_registry._BUILTIN_NAMES == BUILTIN_STT_PROVIDERS, (
"agent.transcription_registry._BUILTIN_NAMES and "
"tools.transcription_tools.BUILTIN_STT_PROVIDERS have drifted!\n"
f" Registry only: {sorted(transcription_registry._BUILTIN_NAMES - BUILTIN_STT_PROVIDERS)}\n"
f" Dispatcher only: {sorted(BUILTIN_STT_PROVIDERS - transcription_registry._BUILTIN_NAMES)}\n"
"Add the missing names to whichever list is incomplete. "
"These two lists exist as a circular-import workaround and "
"MUST be kept in sync manually."
)