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:
cottongin
2026-03-12 07:51:55 -04:00
parent 658c0d4a15
commit d6d5ac10e6
8 changed files with 184 additions and 35 deletions

View File

@@ -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):