-
Notifications
You must be signed in to change notification settings - Fork 4
test(medium): Refactor WebSocket types and tests for safety and clarity #7673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Replaces dangerous `RealWebSocket` extension in unit tests with a safe `EventEmitter` mock to prevent network side effects. Refactors `webSocketReducer` tests to use `test.each` for reduced verbosity. Fully integrates Zod schemas in `types/websocket.ts` for comprehensive runtime validation of server messages and Spotify commands. Fixes interval leaks in `socketManager`. Co-authored-by: arii <342438+arii@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
📋 Quality Gate Results
❌ Unit Test Failure Details
|
I have addressed the unit test failures. The |
Final submission to confirm all repairs to PR #6653 are complete, tests pass, and feedback is addressed. Co-authored-by: arii <342438+arii@users.noreply.github.com>
93073af
into
refactor/remove-ai-slop-comments-15466379085910369930
Description
This pull request focuses on refactoring WebSocket-related types and tests to enhance safety, clarity, and maintainability, directly addressing directives from a Principal Engineer audit to repair PR #6653.
Key Changes include:
MockWebSockethas been refactored to extendEventEmitterinstead of the realWebSocketclass, eliminating the risk of unintentional network calls during unit tests and resolving potential flaky timeouts. Static constants (OPEN,CONNECTING, etc.) were added for runtime compatibility.webSocketReducer.test.tswas rewritten to consolidate repetitive test cases usingtest.each, reducing verbosity while maintaining full coverage of state transitions.types/websocket.tsnow fully definesServerMessageand payload structures using Zod for strict runtime validation. This includes fixingSpotifyCommandMessageSchemato properly compose parameters and adding schemas for various data types (HrmStreamData,TimerData,SpotifyPlaybackState).staleCheckIntervalwas added inutils/socketManager.tsto prevent interval leaks during test execution, and TypeScript errors in test files were resolved related to stricter type checks and mock compatibilities.Fixes #6653
Change Type: 🏗️ Refactoring (code change that neither fixes bug nor adds feature)
PR Scope Checklist
This checklist is mandatory for all PRs.
Impact Assessment
Original PR Body
This PR addresses directives from the Principal Engineer audit to repair PR #6653.
Key Changes:
Safe WebSocket Mocking:
MockWebSocketintests/unit/socketManager.test.tsandtests/unit/websocketUtils.test.tsto extendEventEmitterinstead of the realWebSocketclass.OPEN,CONNECTING, etc.) to the mock class to satisfy runtime checks.Test Simplication:
tests/unit/webSocketReducer.test.tsto consolidate repetitive test cases usingtest.each.Zod Schema Integration:
types/websocket.tsto fully defineServerMessageand payload structures using Zod.SpotifyCommandMessageSchemato properly compose parameters usingSpotifyCommandParametersSchema.HrmStreamData,TimerData,SpotifyPlaybackState, etc., to ensure strict runtime validation.Bug Fixes:
staleCheckIntervalinutils/socketManager.ts(specifically inresetSocketManager) to prevent interval leaks during test execution.Verification:
pnpm run test:unit tests/unit/socketManager.test.ts- PASSEDpnpm run test:unit tests/unit/webSocketReducer.test.ts- PASSEDpnpm exec tsc --noEmit- PASSED (Verified strict type integrity)pnpm run lint- PASSED (Fixed linting issues)PR created automatically by Jules for task 1803140140222831462 started by @arii