Cross-process WebSocket round-trip suite — the cross-process counterpart
to the in-process testing/ws_round_trip.ts harness.
Where the in-process harness drives register_action_ws against a fake
Hono upgrade (no wire), this suite performs a real WebSocket
upgrade against a spawned backend via create_ws_transport (the ws
npm package), so the actual upgrade handshake + per-connection auth +
JSON-RPC dispatch over the socket are exercised end-to-end. It is the
only coverage of the spawned binary's live WS path — the standard
cross-process bundle (describe_standard_cross_process_tests) omits WS
by design, so consumers call this alongside it.
Consumer-agnostic, apart from the cases rpc_path and
capabilities.ws_account_actions gate. Every other case drives the
heartbeat protocol action, which
assert_ws_endpoints_include_protocol_actions guarantees is present on
every WS endpoint — so the suite needs no knowledge of a consumer's domain
WS methods. It validates the transport, not the domain.
Three cases mirror the upgrade route register_action_ws mounts (origin
check → require_auth → dispatch): an authenticated upgrade round-trips
heartbeat (the first case), and an anonymous upgrade and a
disallowed-origin upgrade are refused (after the spine-parity cases).
Per-connection auth is enforced at upgrade time (not per message), so the
negative cases assert the upgrade itself rejects rather than a per-message
error frame.
Spine-parity cases follow the first. Both spines admit a connection only after
re-reading its credential, and requests that arrive first wait for that
rather than being dropped: requests sent the moment the socket opens are all
answered, and — gated on capabilities.ws_handshake_pipelining, with the
ordering forced — so are frames written in the same TCP write as the upgrade
request (driven through connect_raw_ws, since a client library sends
nothing before its open event). heartbeat answers the parameterless
shapes (absent, {}) and refuses a declared param with invalid_params, and a
message over the backend's cap (max_message_bytes, default
DEFAULT_WS_MAX_MESSAGE_BYTES) closes the socket with
WS_CLOSE_MESSAGE_TOO_BIG and WS_CLOSE_MESSAGE_TOO_BIG_REASON.
The cases after the refused upgrades (gated on rpc_path) cover
server-initiated close.
Per-message dispatch never re-checks credential validity, so an open socket
ends only when a revocation closes it — which every revocation does, once
its transaction commits, and every close here is asserted with
WS_CLOSE_SESSION_REVOKED and WS_CLOSE_SESSION_REVOKED_REASON, so a
dropped connection can't pass for one. An authenticated socket is dropped
when the account's sessions are revoked over the keeper's session channel
(account_session_revoke_all), and when its account is deleted
(account_delete, also gated on capabilities.account_lifecycle). The
rest of the revocation table follows, each closing a second account's
socket:
account_token_revoke closes the revoked token's bearer socket and leaves
a socket on the account's other token open; admin_token_revoke_all,
POST /logout, POST /password, and account_purge (also gated on
capabilities.account_lifecycle) close the account's bearer and session
sockets — the rows create_account_revocations shares with the SSE suite;
and a token the per-account cap evicts (max_tokens further mints) has its
bearer socket closed. Omit rpc_path to skip them
(consumers without the standard account and admin actions on their RPC
endpoint).
The last cases are gated on capabilities.ws_account_actions — the backend's
WS endpoint mounts the self-service account actions: a socket that revokes
its own sessions *over that socket* is closed with
WS_CLOSE_SESSION_REVOKED after reading the reply to its request — both
spines answer the revoking request ahead of the close, so the caller is
never left without an answer. Under the same gate (and
rpc_path), a socket mints an API token over WS and the token's
token_create audit row is read back after _testing_drain_effects — the
barrier a WS mutation needs, since a WS reply can precede its audit write.
The binary's create_testing_actions mount provides the drain.
Gated on capabilities.ws — backends without an end-to-end WS transport
skip (the cases still surface as .skip in the report). Cross-process
only: create_ws_transport needs a real bound socket, so wire it from a
*.cross.test.ts file, never an in-process setup.