feat: add mock websocket requests#35
Open
cryptotavares wants to merge 10 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The existing
mock_networktool only intercepts HTTP requests. WebSocket connections — used heavily by dApps for real-time data (price feeds, order books, streaming state) — pass through unintercepted. This makes it impossible to test WebSocket-dependent flows without a live server, or to simulate specific server-to-client message sequences.This PR adds a
mock_websockettool that intercepts WebSocket connections via Playwright'srouteWebSocketAPI, enabling targeted message matching, scripted responses, and full connection lifecycle control.Changes
New tool:
mock_websocketMirrors the
mock_networktool's action-based API (add,clear,list,messages) adapted for WebSocket semantics:ws://orwss://endpoint (no wildcards, since WebSocket routing in Playwright uses exact URL matching)includes: string | string[]). Matched messages trigger scriptedrespondand/orfollowUpResponsepayloads with optional delayspassthrough: false) operates without a real connectionArchitecture
tool-inputs.ts,tool-outputs.ts,errors.tsWebSocketMockDefinition,WebSocketMockMessageRule,MockWebSocketInput/Result,MM_MOCK_WEBSOCKET_FAILEDerror codeschemas.tsws:///wss://only), wildcard rejection, exclusivemock/mocksconstraint onaddactionmock-websocket.tsWebSocketMockRouteManagerclass (per-BrowserContextviaWeakMap) andmockWebSocketToolentry pointregistry.tsmock_websocket, categorized asmutating(tool count: 30 → 31)mm.tsmm mock-websocket {add,clear,list,messages}subcommandsREADME.md,SKILL.mdOther changes
mock-networktests: improved type narrowing in result assertions (replacing broad type checks with discriminated union narrowing viaresult.action)branches,functions, andstatementsthresholds invitest.config.mtsto reflect the new codeTesting
Comprehensive test suite in
mock-websocket.test.tscovering: