feat: implement WebSocket handler and event system#118
feat: implement WebSocket handler and event system#1182witstudios wants to merge 3 commits intomainfrom
Conversation
Add WebSocket endpoint with token auth, client tracking, command dispatch, and typed discriminated union events for real-time server-client communication. - ws://<host>:<port>/ws?token=<token> endpoint via HTTP upgrade - Token validation from query parameter (sync and async) - Client set with per-client terminal subscription state - Command dispatch: ping, terminal:subscribe/unsubscribe, terminal:input - Server events: pong, manifest:updated, agent:status, terminal:output, error - broadcast() and sendEvent() helpers - Proper cleanup on disconnect and server shutdown - 26 tests covering auth, commands, broadcast, and cleanup Closes #73
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
P1: Remove upgrade listener from server on close() to prevent listener leak if handler is recreated on the same server. P2: Pre-serialize event once in broadcast() instead of per-client. P2: Add maxPayload (64KB) to WebSocketServer to prevent OOM. P2: Replace timer-based test synchronization (setTimeout 50ms) with deterministic ping/pong round-trip barriers. P3: Remove unused beforeEach import. P3: Strengthen sendEvent specificity test to verify ws2 does not receive. P3: Add sendEvent skip test for closed socket readyState guard. P3: Add tests for onTerminalInput not provided (no-op path). P3: Add tests for sync and async onTerminalInput throw/reject paths. P3: Add test verifying close() removes upgrade listener. P3: Fix close() ordering: close clients → close WSS → clear set. P3: Wrap synchronous onTerminalInput throws in try/catch.
Summary
ws://<host>:<port>/ws?token=<token>) with token-based auth via query parameterpong,manifest:updated,agent:status,terminal:output,error) and client→server commands (ping,terminal:subscribe,terminal:unsubscribe,terminal:input)broadcast()andsendEvent()helpers, and proper cleanup on disconnectFiles
src/server/ws/events.ts— Command/event type definitions, parser, serializersrc/server/ws/handler.ts— WebSocket handler with auth, client tracking, command dispatchsrc/server/ws/handler.test.ts— 26 tests covering auth, commands, broadcast, cleanupTest plan
npm run typecheckpasses (only pre-existing spawn.test.ts error)npm test— all 244 tests pass (22 files)close()terminates all clients and cleans upCloses #73