fix: separate bot vs viewer WebSocket connections, add client identification
The dashboard's own WS connection was being counted as a bot subscriber,
causing "1 bot connected" with no bots actually present. Now WS clients
send a role ("bot" or "viewer") in the subscribe message. Only bots count
toward the subscriber total. Bot plugins also send a configurable client_id
so the dashboard shows which specific bots are connected.
Made-with: Cursor
This commit is contained in:
@@ -162,12 +162,23 @@ def test_announce_invalid_position(client, db):
|
||||
|
||||
# --- WebSocket tests ---
|
||||
|
||||
def test_ws_subscribe_with_valid_token(app):
|
||||
def test_ws_subscribe_bot_with_valid_token(app):
|
||||
with TestClient(app) as c:
|
||||
with c.websocket_connect("/ws/announce") as ws:
|
||||
ws.send_json({"type": "subscribe", "token": "test-token"})
|
||||
ws.send_json({"type": "subscribe", "token": "test-token", "role": "bot", "client_id": "test-bot"})
|
||||
data = ws.receive_json()
|
||||
assert data["type"] == "status"
|
||||
assert data["subscribers"] == 1
|
||||
assert data["clients"][0]["client_id"] == "test-bot"
|
||||
|
||||
|
||||
def test_ws_subscribe_viewer_not_counted(app):
|
||||
with TestClient(app) as c:
|
||||
with c.websocket_connect("/ws/announce") as ws:
|
||||
ws.send_json({"type": "subscribe", "token": "test-token", "role": "viewer"})
|
||||
data = ws.receive_json()
|
||||
assert data["type"] == "status"
|
||||
assert data["subscribers"] == 0
|
||||
|
||||
|
||||
def test_ws_subscribe_with_invalid_token(app):
|
||||
|
||||
Reference in New Issue
Block a user