Track four test files that were never committed
CLAUDE.md cites tests/test_model_config.py as the guard against reintroducing retired OpenRouter model ids, but the file existed only on disk — the guard was not in the repository. Same for the town geo, voice roster and voicemail transcript tests, and the Reaper bleep-selection test. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
"""Guards against the two model-config failures that have bitten us:
|
||||
a routed model with no pricing entry (silently costs $0.00 on the dashboard),
|
||||
and a stale model id that 404s at the OpenRouter API."""
|
||||
|
||||
from backend.config import settings
|
||||
from backend.services.cost_tracker import OPENROUTER_PRICING
|
||||
from backend.services.llm import OPENROUTER_MODELS, LLMService
|
||||
|
||||
_CALLER_DIALOG_MODEL_PARAMS = LLMService._CALLER_DIALOG_MODEL_PARAMS
|
||||
|
||||
# Retired on OpenRouter — kept here so a reintroduction fails loudly.
|
||||
RETIRED_MODELS = {
|
||||
"anthropic/claude-3.5-haiku",
|
||||
"anthropic/claude-3.5-sonnet",
|
||||
"anthropic/claude-sonnet-4-5", # note the dash; the live id uses a dot
|
||||
"google/gemini-flash-1.5",
|
||||
"mistralai/mistral-small-creative",
|
||||
"x-ai/grok-4",
|
||||
"x-ai/grok-4-fast",
|
||||
"x-ai/grok-4.1-fast",
|
||||
}
|
||||
|
||||
|
||||
def test_every_routed_model_has_pricing():
|
||||
"""A routed model missing from OPENROUTER_PRICING records cost as $0.00."""
|
||||
unpriced = {
|
||||
cat: model
|
||||
for cat, model in settings.category_models.items()
|
||||
if model not in OPENROUTER_PRICING
|
||||
}
|
||||
assert not unpriced, f"routed models with no pricing entry: {unpriced}"
|
||||
|
||||
|
||||
def test_no_retired_models_are_routed():
|
||||
routed = {
|
||||
cat: model
|
||||
for cat, model in settings.category_models.items()
|
||||
if model in RETIRED_MODELS
|
||||
}
|
||||
assert not routed, f"category routed to a retired model: {routed}"
|
||||
|
||||
|
||||
def test_no_retired_models_in_the_pool():
|
||||
stale = sorted(set(OPENROUTER_MODELS) & RETIRED_MODELS)
|
||||
assert not stale, f"retired models still listed in OPENROUTER_MODELS: {stale}"
|
||||
|
||||
|
||||
def test_no_retired_models_in_caller_dialog_params():
|
||||
stale = sorted(set(_CALLER_DIALOG_MODEL_PARAMS) & RETIRED_MODELS)
|
||||
assert not stale, f"per-model tuning keyed to retired models: {stale}"
|
||||
|
||||
|
||||
def test_pool_models_are_priced():
|
||||
"""Anything selectable should be costable."""
|
||||
unpriced = [m for m in OPENROUTER_MODELS if m not in OPENROUTER_PRICING]
|
||||
assert not unpriced, f"pool models with no pricing entry: {unpriced}"
|
||||
|
||||
|
||||
def test_no_retired_model_ids_anywhere_in_the_codebase():
|
||||
"""publish_episode.py, make_clips.py and relabel_transcripts.py each shipped
|
||||
a retired model id and only failed when someone ran them. Scan every source
|
||||
file so the next one fails here instead.
|
||||
|
||||
cost_tracker.py is exempt: it intentionally keeps retired ids as pricing
|
||||
keys so historical cost records stay costable.
|
||||
"""
|
||||
import pathlib
|
||||
|
||||
root = pathlib.Path(__file__).resolve().parent.parent
|
||||
exempt = {root / "backend" / "services" / "cost_tracker.py",
|
||||
pathlib.Path(__file__).resolve()}
|
||||
|
||||
offenders = {}
|
||||
for path in root.rglob("*.py"):
|
||||
if path in exempt:
|
||||
continue
|
||||
# Skip venvs, vendored models, and git worktrees (separate checkouts
|
||||
# on other branches — not this tree's code).
|
||||
if any(part in {"venv", "mlx_models", ".git", ".claude", ".worktrees",
|
||||
"node_modules", "remotion-demo"} for part in path.parts):
|
||||
continue
|
||||
try:
|
||||
text = path.read_text(encoding="utf-8", errors="ignore")
|
||||
except OSError:
|
||||
continue
|
||||
hits = sorted(m for m in RETIRED_MODELS if f'"{m}"' in text or f"'{m}'" in text)
|
||||
if hits:
|
||||
offenders[str(path.relative_to(root))] = hits
|
||||
|
||||
assert not offenders, f"retired model ids still referenced: {offenders}"
|
||||
@@ -0,0 +1,29 @@
|
||||
from backend.main import _get_town_from_location, BIG_BEND_TOWNS
|
||||
|
||||
|
||||
def test_matches_simple_town():
|
||||
assert _get_town_from_location("Alpine, Texas") == "alpine"
|
||||
assert _get_town_from_location("Marfa") == "marfa"
|
||||
assert _get_town_from_location("outside Terlingua") == "terlingua"
|
||||
|
||||
|
||||
def test_matches_two_word_town():
|
||||
assert _get_town_from_location("Fort Stockton, TX") == "fort stockton"
|
||||
assert _get_town_from_location("ft stockton") == "fort stockton"
|
||||
|
||||
|
||||
def test_case_insensitive():
|
||||
assert _get_town_from_location("MARATHON, texas") == "marathon"
|
||||
|
||||
|
||||
def test_no_match_returns_none():
|
||||
assert _get_town_from_location("Albuquerque, New Mexico") is None
|
||||
assert _get_town_from_location("") is None
|
||||
|
||||
|
||||
def test_every_town_has_coords():
|
||||
for town, coords in BIG_BEND_TOWNS.items():
|
||||
assert town == town.lower()
|
||||
lat, lon = coords
|
||||
assert 28.0 < lat < 32.0
|
||||
assert -105.0 < lon < -102.0
|
||||
@@ -0,0 +1,47 @@
|
||||
from backend.main import (
|
||||
INWORLD_MALE_VOICES,
|
||||
INWORLD_FEMALE_VOICES,
|
||||
BLACKLISTED_VOICES,
|
||||
)
|
||||
|
||||
NEWLY_ADDED = ["Arthur", "Daniel", "Brooke", "Joy", "Selene", "Zadie"]
|
||||
|
||||
# Child / adolescent voices — deliberately kept off the roster for an
|
||||
# adult late-night call-in show.
|
||||
EXCLUDED_CHILD_VOICES = ["Abby", "Mia", "Riley"]
|
||||
|
||||
|
||||
def test_rosters_are_sorted_and_deduped():
|
||||
for roster in (INWORLD_MALE_VOICES, INWORLD_FEMALE_VOICES):
|
||||
assert roster == sorted(roster), "roster must stay alphabetical"
|
||||
assert len(roster) == len(set(roster)), "duplicate voice in roster"
|
||||
|
||||
|
||||
def test_no_voice_appears_in_both_genders():
|
||||
overlap = set(INWORLD_MALE_VOICES) & set(INWORLD_FEMALE_VOICES)
|
||||
assert not overlap, f"voice in both rosters: {overlap}"
|
||||
|
||||
|
||||
def test_newly_added_voices_are_present():
|
||||
roster = set(INWORLD_MALE_VOICES) | set(INWORLD_FEMALE_VOICES)
|
||||
missing = [v for v in NEWLY_ADDED if v not in roster]
|
||||
assert not missing, f"missing: {missing}"
|
||||
|
||||
|
||||
def test_child_voices_stay_off_the_roster():
|
||||
roster = set(INWORLD_MALE_VOICES) | set(INWORLD_FEMALE_VOICES)
|
||||
present = [v for v in EXCLUDED_CHILD_VOICES if v in roster]
|
||||
assert not present, f"child/adolescent voice on roster: {present}"
|
||||
|
||||
|
||||
def test_blacklist_only_references_real_roster_voices():
|
||||
roster = set(INWORLD_MALE_VOICES) | set(INWORLD_FEMALE_VOICES)
|
||||
orphans = sorted(set(BLACKLISTED_VOICES) - roster)
|
||||
assert not orphans, f"blacklist names voices not in the roster: {orphans}"
|
||||
|
||||
|
||||
def test_effective_pool_is_large_enough_for_session_sampling():
|
||||
"""main.py samples 25 voices per session from the non-blacklisted pool."""
|
||||
roster = set(INWORLD_MALE_VOICES) | set(INWORLD_FEMALE_VOICES)
|
||||
effective = roster - set(BLACKLISTED_VOICES)
|
||||
assert len(effective) >= 25
|
||||
@@ -0,0 +1,138 @@
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.main import (
|
||||
Voicemail,
|
||||
_load_voicemails,
|
||||
_save_voicemails,
|
||||
play_voicemail_on_air,
|
||||
)
|
||||
import backend.main as main
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def isolated_store(tmp_path, monkeypatch):
|
||||
"""Point the voicemail store at a temp dir and start from a clean slate."""
|
||||
meta = tmp_path / "voicemails.json"
|
||||
monkeypatch.setattr(main, "VOICEMAILS_META", meta)
|
||||
monkeypatch.setattr(main, "_voicemails", [])
|
||||
monkeypatch.setattr(main, "_deleted_vm_timestamps", set())
|
||||
return meta
|
||||
|
||||
|
||||
def test_voicemail_defaults_to_empty_transcript():
|
||||
vm = Voicemail(id="a1", phone="+15551234567", timestamp=1.0, duration=30, file_path="/x.wav")
|
||||
assert vm.transcript == ""
|
||||
|
||||
|
||||
def test_transcript_round_trips_through_save_and_load(isolated_store):
|
||||
main._voicemails.append(
|
||||
Voicemail(
|
||||
id="a1", phone="+15551234567", timestamp=1.0, duration=30,
|
||||
file_path="/x.wav", transcript="Hey Luke, it's Susan out in Deming.",
|
||||
)
|
||||
)
|
||||
_save_voicemails()
|
||||
|
||||
on_disk = json.loads(isolated_store.read_text())
|
||||
assert on_disk["voicemails"][0]["transcript"] == "Hey Luke, it's Susan out in Deming."
|
||||
|
||||
main._voicemails.clear()
|
||||
_load_voicemails()
|
||||
assert main._voicemails[0].transcript == "Hey Luke, it's Susan out in Deming."
|
||||
|
||||
|
||||
def test_load_tolerates_legacy_entries_without_transcript(isolated_store):
|
||||
isolated_store.write_text(json.dumps({
|
||||
"voicemails": [{
|
||||
"id": "old", "phone": "+15551234567", "timestamp": 1.0,
|
||||
"duration": 30, "file_path": "/x.wav", "listened": True,
|
||||
}],
|
||||
"deleted_timestamps": [],
|
||||
}))
|
||||
_load_voicemails()
|
||||
assert main._voicemails[0].transcript == ""
|
||||
|
||||
|
||||
def test_play_on_air_puts_transcript_into_conversation(isolated_store, tmp_path, monkeypatch):
|
||||
"""The actual fix: Devon reads session.conversation, so playing a
|
||||
voicemail on air must write its transcript there."""
|
||||
wav = tmp_path / "vm.wav"
|
||||
wav.write_bytes(b"fake wav bytes")
|
||||
|
||||
main._voicemails.append(
|
||||
Voicemail(
|
||||
id="vm1", phone="+15753424105", timestamp=1.0, duration=77,
|
||||
file_path=str(wav), transcript="My neighbor keeps moving my fence posts.",
|
||||
)
|
||||
)
|
||||
|
||||
monkeypatch.setattr(main.session, "conversation", [])
|
||||
monkeypatch.setattr(main, "_save_voicemails", lambda: None)
|
||||
|
||||
played = {}
|
||||
monkeypatch.setattr(
|
||||
main.audio_service, "play_caller_audio",
|
||||
lambda data, sr: played.update(bytes=len(data), rate=sr),
|
||||
)
|
||||
|
||||
class FakeLibrosa:
|
||||
@staticmethod
|
||||
def load(path, sr=None, mono=True):
|
||||
import numpy as np
|
||||
return np.zeros(sr or 24000, dtype="float32"), sr or 24000
|
||||
|
||||
monkeypatch.setitem(__import__("sys").modules, "librosa", FakeLibrosa)
|
||||
|
||||
result = asyncio.run(play_voicemail_on_air("vm1"))
|
||||
assert result["status"] == "playing"
|
||||
|
||||
roles = [m["role"] for m in main.session.conversation]
|
||||
contents = [m["content"] for m in main.session.conversation]
|
||||
assert any("voicemail" in r for r in roles), f"no voicemail role in {roles}"
|
||||
assert any("fence posts" in c for c in contents), f"transcript missing from {contents}"
|
||||
|
||||
|
||||
def test_voicemail_role_is_normalized_to_a_valid_llm_role():
|
||||
"""A raw 'voicemail:+1555...' role would reach the LLM API as an invalid
|
||||
role; llm.py swallows the resulting error and returns empty text, so
|
||||
callers would silently go mute."""
|
||||
out = main._normalize_messages_for_llm([
|
||||
{"role": "voicemail:+15753424105", "content": "My name is Sandra."},
|
||||
])
|
||||
assert out[0]["role"] in ("user", "assistant", "system"), out[0]["role"]
|
||||
assert "Sandra" in out[0]["content"]
|
||||
assert "+15753424105" in out[0]["content"], "caller identity should survive"
|
||||
|
||||
|
||||
def test_play_on_air_without_transcript_still_announces_the_voicemail(isolated_store, tmp_path, monkeypatch):
|
||||
"""An untranscribed voicemail should still tell Devon something happened,
|
||||
rather than silently playing audio he can't perceive."""
|
||||
wav = tmp_path / "vm.wav"
|
||||
wav.write_bytes(b"fake wav bytes")
|
||||
|
||||
main._voicemails.append(
|
||||
Voicemail(
|
||||
id="vm2", phone="+15753424105", timestamp=1.0, duration=77,
|
||||
file_path=str(wav), transcript="",
|
||||
)
|
||||
)
|
||||
|
||||
monkeypatch.setattr(main.session, "conversation", [])
|
||||
monkeypatch.setattr(main, "_save_voicemails", lambda: None)
|
||||
monkeypatch.setattr(main.audio_service, "play_caller_audio", lambda data, sr: None)
|
||||
|
||||
class FakeLibrosa:
|
||||
@staticmethod
|
||||
def load(path, sr=None, mono=True):
|
||||
import numpy as np
|
||||
return np.zeros(sr or 24000, dtype="float32"), sr or 24000
|
||||
|
||||
monkeypatch.setitem(__import__("sys").modules, "librosa", FakeLibrosa)
|
||||
|
||||
asyncio.run(play_voicemail_on_air("vm2"))
|
||||
|
||||
assert main.session.conversation, "nothing was added to the conversation"
|
||||
assert any("voicemail" in m["role"] for m in main.session.conversation)
|
||||
Reference in New Issue
Block a user