import asyncio import importlib import sys from omnivoice.utils.voice_design import _INSTRUCT_VALID_EN from backend.voice_design import VOICE_DESIGN_OPTIONS from backend.voice_presets import VOICE_PRESETS def test_voice_presets_match_their_scriptorium_descriptions() -> None: assert VOICE_PRESETS == [ { "id": "the-archivist", "name": "The Archivist", "desc": "Voice design preset · elderly monk · low pitch · british accent", "initial": "A", "instruct": "male, elderly, low pitch, british accent", }, { "id": "the-novice", "name": "The Novice", "desc": "Voice design preset · young sister · moderate pitch · british accent", "initial": "N", "instruct": "female, young adult, moderate pitch, british accent", }, { "id": "the-warden", "name": "The Warden", "desc": "Voice design preset · stern keeper · very low pitch · american accent", "initial": "W", "instruct": "male, middle-aged, very low pitch, american accent", }, { "id": "the-illuminator", "name": "The Illuminator", "desc": "Voice design preset · bright scholar · high pitch · canadian accent", "initial": "I", "instruct": "female, middle-aged, high pitch, canadian accent", }, ] def test_voice_presets_use_only_supported_omnivoice_design_tokens() -> None: for preset in VOICE_PRESETS: instruct = preset["instruct"] parts = [part.strip().lower() for part in instruct.split(",")] assert all(parts), f"Preset {preset['id']} contains an empty instruct token" assert all( part in _INSTRUCT_VALID_EN for part in parts ), f"Preset {preset['id']} has unsupported instruct tokens: {instruct}" def test_homepage_injects_voice_presets_for_frontend() -> None: sys.modules.pop("app", None) module = importlib.import_module("app") response = asyncio.run(module.homepage()) html = response.body.decode("utf-8") assert "window.__VOICE_PRESETS__" in html assert "window.__VOICE_DESIGN_OPTIONS__" in html assert "window.__MAGPIE_OPTIONS__" in html assert "window.__SYNTHESIS_BACKENDS__" in html def test_voice_design_options_use_only_supported_omnivoice_design_tokens() -> None: option_values = [ option["value"] for category in VOICE_DESIGN_OPTIONS for option in category["options"] ] assert option_values assert all(value in _INSTRUCT_VALID_EN for value in option_values)