Skip to content

Comments

refactor: remove net-stubbing->server->net-stubbing cycle#33394

Merged
cacieprins merged 5 commits intodevelopfrom
refactor/net-server-errors-cycle
Feb 20, 2026
Merged

refactor: remove net-stubbing->server->net-stubbing cycle#33394
cacieprins merged 5 commits intodevelopfrom
refactor/net-server-errors-cycle

Conversation

@cacieprins
Copy link
Contributor

@cacieprins cacieprins commented Feb 20, 2026

  • Closes

Additional details

Small refactor to break the @packages/server <> @packages/net-stubbing cycle, informed by SOLID principles (dependency inversion,

  • @packages/net-stubbing now depends directly on @packages/errors, rather than importing @packages/errors via @packages/server re-exporting it
  • CyServer.Socket definition is removed, and SocketBroadcaster is added as a type that @packages/socket exports
  • @packages/net-stubbing and @packages/proxy import SocketBroadcaster from @packages/socket instead of CyServer.Socket from `@packagbes/server
  • @packages/server is dropped as a dependency of @packages/net-stubbing

Dependency Inversion - rather than net-stubbing and proxy depending on server to define their public interface, server purely depends on them. server depends on proxy for the same interface, to ensure that classes it implements conform to the contract.

Interface Segregation guides us to limit the scope of that interface to the "send message to driver" functionality: it is the bare minimum that net-stubbing and proxy need. It also guided us to import @packages/errors directly, so that it is not depending on the entirety of @packages/server when all it's using is the cloneErr utility method from @packages/errors.

Single Responsibility guided us to move the SocketBroadcaster interface to a neutral thematically-appropriate package; @packages/server implements it in SocketBase, and net-stubbing/proxy consume it.

Potential extensions:

  • Extract event wiring from socket-base into a separate function
  • Limit socket-base to a single responsibility: initializing and broadcasting to a tuple of socket.io connections
  • Try to update CDPSocketServer so that it implements socket-io.Server, so that the tuple is not two different types
  • move socket-base to @packages/socket, slim down its public interface
  • have net-stubbing and proxy depend on socket-io for the socket interface, rather than @packages/socket.
  • No longer inherit SocketBase in SocketCt and SocketE2E.

This is composition over inheritence. CT/E2E sockets implement a small interface and use the SocketBroadcaster instead of being a subtype of a large base class (single responsibility). net-stubbing and proxy receive the SocketBroadcaster implementation of the interface/contract (liskov substitution). If CT/E2E sockets implement a small interface (like TestCoordinator or similar) and hold SocketBroadcaster internally, server depends on that interface only. No inheritence from a large base class means no forced dependency on methods not used (interface segregation). Server can also depend on an abstraction (TestCoordinator) instead of the concrete SocketBase hierarchy. High level (server) depends on the interface; low-level (CT/E2E sockets) implement it and use the shared broadcaster (dependency inversion).

Note that in the case of this codebase and its constraints, SOLID principles should be a guide rather than a requirement/constraint. Going whole-hog on them can make things more difficult to grok; it's a balance. Using them to address circular dependencies helps to not create bigger issues in the future, while breaking circular dependencies.


Note

Low Risk
Type-only refactor to decouple packages; risk is mainly compile/runtime wiring mismatches around toDriver event emission.

Overview
Breaks the @packages/server@packages/net-stubbing circular dependency by replacing CyServer.Socket with a new SocketBroadcaster interface exported from @packages/socket.

Updates net-stubbing and proxy to type their socket dependency as SocketBroadcaster, makes server’s SocketBase implement that interface, and removes the CyServer.Socket type from packages/server/index.d.ts. net-stubbing also stops importing server re-exported errors by switching its middleware to import @packages/errors directly, and both net-stubbing and proxy add @packages/socket as a dependency (with net-stubbing dropping @packages/server).

Written by Cursor Bugbot for commit e96107f. This will update automatically on new commits. Configure here.

Steps to test

How has the user experience changed?

PR Tasks

@cacieprins cacieprins marked this pull request as ready for review February 20, 2026 15:47
@cacieprins cacieprins self-assigned this Feb 20, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@cypress
Copy link

cypress bot commented Feb 20, 2026

cypress    Run #69096

Run Properties:  status check passed Passed #69096  •  git commit e96107f94f: Update socket-broadcaster.ts - remove toRunner
Project cypress
Branch Review refactor/net-server-errors-cycle
Run status status check passed Passed #69096
Run duration 18m 55s
Commit git commit e96107f94f: Update socket-broadcaster.ts - remove toRunner
Committer Cacie Prins
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 10
Tests that did not run due to a developer annotating a test with .skip  Pending 1112
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 27185
View all changes introduced in this branch ↗︎
UI Coverage  61.04%
  Untested elements 28  
  Tested elements 47  
Accessibility  99%
  Failed rules  0 critical   3 serious   1 moderate   0 minor
  Failed elements 18  

@cacieprins cacieprins enabled auto-merge (squash) February 20, 2026 18:52
@cacieprins cacieprins merged commit fb6de82 into develop Feb 20, 2026
93 of 95 checks passed
@cacieprins cacieprins deleted the refactor/net-server-errors-cycle branch February 20, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants