Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 274:c9be578316a6 | 275:78699f810817 |
|---|---|
| 1 from pathlib import Path | |
| 2 import unittest | |
| 3 | |
| 4 from fastapi.testclient import TestClient | |
| 5 | |
| 6 from dictation.config import DictationConfig | |
| 7 from dictation.server import create_app | |
| 8 from dictation.transcriber import Transcript | |
| 9 | |
| 10 | |
| 11 class FakeTranscriber: | |
| 12 async def warmup(self): | |
| 13 return None | |
| 14 | |
| 15 async def transcribe(self, samples, *, final): | |
| 16 return Transcript("test transcript", "en", 0.99) | |
| 17 | |
| 18 | |
| 19 def test_config() -> DictationConfig: | |
| 20 return DictationConfig( | |
| 21 host="127.0.0.1", | |
| 22 port=8090, | |
| 23 model_dir=Path("/tmp/model"), | |
| 24 compute_type="int8_float16", | |
| 25 max_sessions=1, | |
| 26 partial_interval_ms=1200, | |
| 27 silence_ms=700, | |
| 28 max_utterance_seconds=30, | |
| 29 speech_threshold=0.012, | |
| 30 ) | |
| 31 | |
| 32 | |
| 33 class ServerTest(unittest.TestCase): | |
| 34 def test_health_and_assets(self): | |
| 35 with TestClient(create_app(test_config(), FakeTranscriber())) as client: | |
| 36 health = client.get("/health") | |
| 37 self.assertEqual(health.status_code, 200) | |
| 38 self.assertEqual(health.json()["status"], "ok") | |
| 39 self.assertIn("Zenbu Dictation", client.get("/").text) | |
| 40 self.assertIn("RTCPeerConnection", client.get("/dictation.js").text) | |
| 41 | |
| 42 def test_rejects_non_offer_sdp(self): | |
| 43 with TestClient(create_app(test_config(), FakeTranscriber())) as client: | |
| 44 response = client.post( | |
| 45 "/api/webrtc/offer", | |
| 46 json={"sdp": "not-sdp", "type": "answer"}, | |
| 47 ) | |
| 48 self.assertEqual(response.status_code, 422) | |
| 49 | |
| 50 def test_close_is_idempotent(self): | |
| 51 with TestClient(create_app(test_config(), FakeTranscriber())) as client: | |
| 52 response = client.post( | |
| 53 "/api/webrtc/session/00000000-0000-0000-0000-000000000000/close" | |
| 54 ) | |
| 55 self.assertEqual(response.status_code, 200) | |
| 56 self.assertEqual(response.json(), {"closed": True}) | |
| 57 | |
| 58 | |
| 59 if __name__ == "__main__": | |
| 60 unittest.main() |