Add dev-only mock WebSocket for Duo Chat
What does this MR do and why?
Adds a development-only mock WebSocket so Duo Chat's connection-error handling can be exercised locally.
Duo Chat branches on WebSocket close codes such as 1006, 1008 and 1013. A real Duo Workflow Service will not produce those on demand, so the paths that react to them could previously only be reached by editing the client by hand.
DwsMockWebSocket wraps the real socket and forwards every event untouched, so chat still talks to a live backend and streams real replies. On top of that it can synthesise open, message, close and error events, driven from the browser console.
Merge request series
Note
This MR is part of a series to improve the reliability of websocket connection in Duo Chat.
- This MR — the mock WebSocket (targets
master) - !247787 (merged) — the
WorkflowStreamservice - !245705 (merged) — integration into Duo Agentic Chat, where the whole thing is validated
Key changes
dws_mock_websocket.js— the wrapper. ProxiesreadyState,sendandclose, forwards the fouron*handlers, and addsdispatchMockEvent.stream_worker.js— swaps the socket class behind aNODE_ENVguard and gains onemockEventmessage case.stream_manager.js— exposesgl.dwsMockSocket, which postsmockEventmessages to the worker.README.md— usage, when the mock is active, and the two constraints below.
A synthetic close also tears down the wrapped socket. Otherwise the client reconnects while the old connection is still open, and the real close arrives later as a second, unexpected event.
Demo
How to set up and validate locally
Open Duo Agentic Chat in your GDK against the real backend, send a prompt, and confirm the reply streams normally.
Then, from the browser console:
gl.dwsMockSocket.close(1013) // non-retryable
gl.dwsMockSocket.close(1001) // retryable
gl.dwsMockSocket.error()
gl.dwsMockSocket.message('{"newCheckpoint":{"status":"running"}}')MR acceptance checklist
- Tests for the wrapper, the worker command and the console global
- No changelog trailer — development tooling, no user-facing change
- Verified the mock is stripped from production bundles
- No new dependency, no bundler or CSP configuration
References
Make Duo Chat WebSocket stream more resilient a... (#605829 - closed)