view dictation/server_test.py @ 275:78699f810817

Add Qwen3-VL and WebRTC dictation services Add Bazel targets for the CUDA-backed Qwen3-VL server and a local WebRTC faster-whisper dictation service. Co-authored-by: Copilot <[email protected]> Copilot-Session: e3d8cb06-6c95-4ae0-9757-651d3796ab00
author MrJuneJune <me@mrjunejune.com>
date Mon, 17 Aug 2026 10:58:47 -0700
parents
children 49e9e591c9bb
line wrap: on
line source

from pathlib import Path
import unittest

from fastapi.testclient import TestClient

from dictation.config import DictationConfig
from dictation.server import create_app
from dictation.transcriber import Transcript


class FakeTranscriber:
    async def warmup(self):
        return None

    async def transcribe(self, samples, *, final):
        return Transcript("test transcript", "en", 0.99)


def test_config() -> DictationConfig:
    return DictationConfig(
        host="127.0.0.1",
        port=8090,
        model_dir=Path("/tmp/model"),
        compute_type="int8_float16",
        max_sessions=1,
        partial_interval_ms=1200,
        silence_ms=700,
        max_utterance_seconds=30,
        speech_threshold=0.012,
    )


class ServerTest(unittest.TestCase):
    def test_health_and_assets(self):
        with TestClient(create_app(test_config(), FakeTranscriber())) as client:
            health = client.get("/health")
            self.assertEqual(health.status_code, 200)
            self.assertEqual(health.json()["status"], "ok")
            self.assertIn("Zenbu Dictation", client.get("/").text)
            self.assertIn("RTCPeerConnection", client.get("/dictation.js").text)

    def test_rejects_non_offer_sdp(self):
        with TestClient(create_app(test_config(), FakeTranscriber())) as client:
            response = client.post(
                "/api/webrtc/offer",
                json={"sdp": "not-sdp", "type": "answer"},
            )
            self.assertEqual(response.status_code, 422)

    def test_close_is_idempotent(self):
        with TestClient(create_app(test_config(), FakeTranscriber())) as client:
            response = client.post(
                "/api/webrtc/session/00000000-0000-0000-0000-000000000000/close"
            )
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.json(), {"closed": True})


if __name__ == "__main__":
    unittest.main()