Problem
E2E test for WebSocket real-time updates is failing with ERR_CONNECTION_REFUSED, indicating the WebSocket connection is not being established properly.
Current Behavior
From test output:
[error] Failed to load resource: net::ERR_CONNECTION_REFUSED
[log] WebSocket connected
The frontend WebSocket client attempts to connect, shows "connected" in logs, but the connection is actually failing with ERR_CONNECTION_REFUSED.
Failed Test
File: tests/e2e/test_dashboard.spec.ts
Test: should receive real-time updates via WebSocket (line 221)
Expected: Dashboard receives real-time agent/task updates via WebSocket
Actual: Connection refused, no updates received
Root Cause Investigation
1. Verify WebSocket endpoint exists in backend
Check if backend has WebSocket route configured:
# Search for WebSocket route in backend
grep -r "websocket" codeframe/ui/server.py
grep -r "WebSocket" codeframe/ui/server.py
2. Check WebSocket connection URL
Frontend WebSocket client configuration:
// web-ui/src/lib/websocket.ts
const wsUrl = `ws://localhost:${port}/ws`;
Verify:
3. Test WebSocket manually
# Start backend
cd /home/frankbria/projects/codeframe
uv run uvicorn codeframe.ui.server:app --port 8080
# In another terminal, test WebSocket
wscat -c ws://localhost:8080/ws
Expected: Connection established
Actual: ?
4. Check backend WebSocket implementation
Expected FastAPI WebSocket route:
from fastapi import WebSocket
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
# ... send updates
Likely Causes
- WebSocket route missing - Backend doesn't have
/ws endpoint
- Wrong port - Frontend connecting to wrong port
- Wrong path - Frontend using
/websocket but backend expects /ws
- CORS issue - WebSocket blocked by CORS policy
- Backend not running - WebSocket server not started (unlikely, HTTP works)
Expected Behavior
- Frontend opens WebSocket connection to
ws://localhost:8080/ws
- Backend accepts connection
- Backend sends real-time events:
agent_created
agent_status_changed
task_assigned
task_status_changed
blocker_created
blocker_resolved
- etc.
- Frontend AgentStateProvider receives events and updates state
- Dashboard UI updates in real-time
Debugging Steps
-
Check if WebSocket endpoint exists:
grep -A 10 "websocket" codeframe/ui/server.py
-
Check frontend WebSocket URL:
grep -r "getWebSocketClient\|new WebSocket" web-ui/src/
-
Monitor network traffic during test:
- Open Chrome DevTools → Network tab
- Filter by "WS" (WebSocket)
- Run E2E test
- Check if WebSocket connection attempted and what error occurs
-
Add debug logging:
// web-ui/src/lib/websocket.ts
console.log('WebSocket connecting to:', wsUrl);
ws.onopen = () => console.log('WebSocket OPEN');
ws.onerror = (e) => console.error('WebSocket ERROR:', e);
ws.onclose = (e) => console.log('WebSocket CLOSE:', e.code, e.reason);
Impact
Blocks 1/12 failed E2E tests - lowest priority but important for real-time UX.
Acceptance Criteria
Related Files
web-ui/src/lib/websocket.ts - WebSocket client
web-ui/src/components/AgentStateProvider.tsx - WebSocket event handler
codeframe/ui/server.py - Backend WebSocket endpoint (if exists)
tests/e2e/test_dashboard.spec.ts:221 - Failing test
References
Problem
E2E test for WebSocket real-time updates is failing with
ERR_CONNECTION_REFUSED, indicating the WebSocket connection is not being established properly.Current Behavior
From test output:
The frontend WebSocket client attempts to connect, shows "connected" in logs, but the connection is actually failing with ERR_CONNECTION_REFUSED.
Failed Test
File:
tests/e2e/test_dashboard.spec.tsTest:
should receive real-time updates via WebSocket(line 221)Expected: Dashboard receives real-time agent/task updates via WebSocket
Actual: Connection refused, no updates received
Root Cause Investigation
1. Verify WebSocket endpoint exists in backend
Check if backend has WebSocket route configured:
2. Check WebSocket connection URL
Frontend WebSocket client configuration:
Verify:
/wsor similar)ws://(notwss://for local testing)3. Test WebSocket manually
Expected: Connection established
Actual: ?
4. Check backend WebSocket implementation
Expected FastAPI WebSocket route:
Likely Causes
/wsendpoint/websocketbut backend expects/wsExpected Behavior
ws://localhost:8080/wsagent_createdagent_status_changedtask_assignedtask_status_changedblocker_createdblocker_resolvedDebugging Steps
Check if WebSocket endpoint exists:
grep -A 10 "websocket" codeframe/ui/server.pyCheck frontend WebSocket URL:
grep -r "getWebSocketClient\|new WebSocket" web-ui/src/Monitor network traffic during test:
Add debug logging:
Impact
Blocks 1/12 failed E2E tests - lowest priority but important for real-time UX.
Acceptance Criteria
/wsin backendRelated Files
web-ui/src/lib/websocket.ts- WebSocket clientweb-ui/src/components/AgentStateProvider.tsx- WebSocket event handlercodeframe/ui/server.py- Backend WebSocket endpoint (if exists)tests/e2e/test_dashboard.spec.ts:221- Failing testReferences