test: fix capture_ws TestClient host for loopback guard

Follow-up to f15f6d9 (WS loopback guard on /ws/transcribe). The functional
tests in tests/test_capture_ws.py constructed TestClient with the Starlette
default client=("testclient", 50000), which the guard's _LOOPBACK_HOSTS
allow-list rejects. PR #84 established the fix pattern for HTTP tests:
explicitly pass client=("127.0.0.1", 50000) to TestClient — same security
property, same semantics. Applied here.

3 tests previously failing now pass:
- test_eof_text_frame_triggers_final_without_disconnect
- test_legacy_disconnect_still_finalizes
- test_empty_binary_frame_acts_as_eof
This commit is contained in:
debpalash
2026-05-19 09:24:50 +05:30
parent e764fdb63e
commit 71c10dc7e0
+5 -1
View File
@@ -45,7 +45,11 @@ def client(monkeypatch):
monkeypatch.setattr(cw, "_transcribe_buffer_full", fake_full)
from main import app
return TestClient(app)
# client=("127.0.0.1", 50000) matches the loopback allow-list in
# backend/api/routers/capture_ws.py:_LOOPBACK_HOSTS. Starlette's default
# TestClient uses client=("testclient", 50000), which the WS guard rejects.
# Matches the pattern PR #84 established for HTTP TestClient fixtures.
return TestClient(app, client=("127.0.0.1", 50000))
def _audio_chunk(n_bytes: int = 20_000) -> bytes: