testing/cross_backend/ws_round_trip.ts

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. Every 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.

The first three cases mirror the upgrade stack register_ws_endpoint wires (origin check → require_auth → dispatch): an authenticated upgrade round-trips heartbeat; an anonymous upgrade is refused; a disallowed-origin upgrade is refused. 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.

A fourth case (gated on rpc_path) covers server-initiated close: an authenticated socket is dropped when the account's sessions are revoked mid-connection. Per-message dispatch never re-checks credential validity, so the live socket survives on the audit-fed create_ws_auth_guard seam — firing account_session_revoke_all over the keeper's session channel emits session_revoke_all, which closes the socket. Omit rpc_path to skip it (consumers without the standard account actions on their RPC endpoint).

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.

view source

Declarations
#

2 declarations

CrossProcessWsTestOptions
#

testing/cross_backend/ws_round_trip.ts view source

CrossProcessWsTestOptions import type {CrossProcessWsTestOptions} from '@fuzdev/fuz_app/testing/cross_backend/ws_round_trip.js';

Configuration for .

setup_test

Per-test fixture producer (default_cross_process_setup(handle)). The authenticated case reads the fresh-per-test keeper's session cookies from fixture.transport.cookies() to thread onto the upgrade.

type SetupTest

readonly

capabilities

Backend capability flags; every case gates on capabilities.ws.

type BackendCapabilities

readonly

base_url

Base URL the backend is reachable at (e.g. http://localhost:1178).

type string

readonly

ws_path

WebSocket endpoint path on the backend (e.g. /api/ws).

type string

readonly

origin?

Origin for the authenticated upgrade. Defaults to base_url.

type string

readonly

rpc_path?

RPC endpoint path (e.g. /api/rpc) used by the close-on-revoke case to fire account_session_revoke_all over the keeper's session channel. When omitted, that case is skipped — it depends on the standard account actions being mounted on the RPC endpoint.

type string

readonly

describe_cross_process_ws_tests
#

testing/cross_backend/ws_round_trip.ts view source

(options: CrossProcessWsTestOptions): void import {describe_cross_process_ws_tests} from '@fuzdev/fuz_app/testing/cross_backend/ws_round_trip.js';

Register the cross-process WS round-trip suite. Up to four cases over a real upgrade: authed heartbeat round-trip, anonymous-upgrade refusal, disallowed-origin refusal, and — when rpc_path is supplied — session-revocation closing the live socket.

options

returns

void

Depends on
#