refactor(connect): one live connection, no token in any address (SSE removed)

Plan step 4.0. Owner (2026-11-17): no phone in use needs to keep working, so no
compatibility path.
- Removed the SSE channel: routers/sse.py (/api/sse/stream, which still accepted a JWT whose
  session had ended — a signed-out phone could keep listening), services/sse_bus.py (every
  backend module now calls services/ws_bus.broadcast_sync directly), waiter useSSE.js.
- Credentials only in the first frame: the waiter's useWebSocket and the manager's
  LiveProvider send {token} there like the terminal; routers/ws.py no longer reads ?token=
  (a token in a URL ends up in proxy and server logs).
- Waiter: SSEContext → LiveContext (LiveProvider, useLiveContext, liveAlive, the
  'live-event' / 'live-reconnected' window events), dead SSE compat code removed.
- Tests: a token in the address is refused, /api/sse/stream is 404; e2e browser (3 delivery
  modes) and manager assert no token in the live connection's address. Android taps now
  wait for their element (the fixed sleeps made the suite flaky, KI-009).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 10:49:21 +02:00
co-authored by Claude Opus 5.5
parent d0c6a10e47
commit f85894a72e
43 changed files with 112 additions and 350 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ def _no_event_persistence(monkeypatch):
"""services.ws_bus writes every broadcast to sync_events through its OWN connection,
which waits on the test's open transaction until SQLite's 5 s lock timeout (and then
fails quietly). Tests don't use the replay buffer, so the write is skipped here.
Tests about events capture services.sse_bus.broadcast_sync instead."""
Tests about events capture services.ws_bus.broadcast_sync instead."""
import services.ws_bus as ws_bus
monkeypatch.setattr(ws_bus, "_persist_event", lambda *a, **k: 0)
+8 -4
View File
@@ -69,13 +69,17 @@ def expect_closed(sock, close):
# ── who may connect ──────────────────────────────────────────────────────────
def test_user_token_in_query_still_works(client, make_user, login):
def test_a_token_in_the_address_is_ignored(client, make_user, login):
"""Phase 4.0: credentials only in the first frame (a token in a URL ends up in logs)."""
h = login(make_user(role="waiter"), "waiter")
with client.websocket_connect(f"{WS}?token={h['Authorization'][7:]}") as sock:
sock.send_json({"cursor": 0})
expect_ready(sock)
ws_bus.broadcast_sync("order_updated", {"order_id": 1})
assert sock.receive_json() == {"seq": 0, "type": "order_updated", "data": {"order_id": 1}}
assert sock.receive_json()["type"] == "refused"
def test_the_sse_stream_is_gone(client, make_user, login):
h = login(make_user(role="waiter"), "waiter")
assert client.get(f"/api/sse/stream?token={h['Authorization'][7:]}").status_code == 404
def test_nothing_or_garbage_is_refused(client):
+2 -2
View File
@@ -12,8 +12,8 @@ URL = "/api/platform/notifications"
@pytest.fixture
def events(monkeypatch):
sent = []
import services.sse_bus as bus
monkeypatch.setattr(bus, "broadcast_sync", lambda t, d, user_ids=None: sent.append((t, d, sorted(user_ids or []))))
import services.ws_bus as bus
monkeypatch.setattr(bus, "broadcast_sync", lambda t, d, user_ids=None, device_ids=None: sent.append((t, d, sorted(user_ids or []))))
return sent