refactor(mesh): serve the control channel over the neutral WsSocket

The mesh control channel was the last consumer speaking the `ws` EventEmitter
API directly: http/ws.ts handed meshControl.handle a raw socket, while every
@Ws route already went through nodeSocket() to get a neutral WsSocket. Mesh did
not lack an abstraction — it skipped the one the codebase already had.

handle() now takes a WsSocket and consumes `inbound`, so both feeds work: Node
via the existing nodeSocket, and Deno/Bun via app.upgrade, where the socket is
already neutral. That is what unblocks mounting the control channel off Node.

RPCs are still dispatched without awaiting. The old `ws.on('message')` listener
overlapped them, and the peer's id-keyed pending map exists for exactly that —
awaiting inside the receive loop would have silently serialized every mesh call.
A test now pins the overlap.

The unused `http` import in http/types.ts fell out with MeshControl's req
parameter: nothing in that module is Node-shaped any more.

Node behaviour is unchanged — the teapot↔teacup integration tests pass
untouched. teapot.test.ts drives handle() directly, so its fake moved from a raw
EventEmitter to a fake WsSocket.

Refs .specs/2026-07-15-green-tea-mesh-cross-runtime-plan.md Task 3

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-15 14:53:09 -05:00
1 parent 87772868ab
commit 71b59e7c25
3 files changed
+128 -58

No files matched your search

+6 -3
View File
@@ -1,9 +1,8 @@
import type http from 'http';
import type { Transport } from '../metadata';
import type { PipelineResult } from '../pipeline';
import type { ErrorRenderer } from '../transformers';
import type { TlsOptions, SecurityOptions, CorsOptions } from '../security';
import type { WsRequest } from './ws-core';
import type { WsRequest, WsSocket } from './ws-core';
import type { StaticResolver } from '../views';
/** Per-request size and timeout ceilings applied by the server. */
@@ -74,5 +73,9 @@ export interface WsRouteDef {
/** Hook for a mesh gateway to take over WebSocket upgrades on a fixed path. */
export interface MeshControl {
path: string;
handle(ws: any, req: http.IncomingMessage): void;
/**
* Serves one control connection over the neutral socket — the same capability every other ws
* consumer takes, so Node (via `nodeSocket`) and Deno/Bun (via `app.upgrade`) both feed it.
*/
handle(socket: WsSocket): void;
}
+3 -1
View File
@@ -38,7 +38,9 @@ function handleMeshUpgrade(
return true;
}
wss.handleUpgrade(req, socket, head, (ws: any) => meshControl.handle(ws, req));
// nodeSocket, not the raw ws: the control channel is the last consumer that spoke the
// `ws` EventEmitter API directly. It now takes the same neutral socket every route does.
wss.handleUpgrade(req, socket, head, (ws: any) => meshControl.handle(nodeSocket(ws)));
return true;
}