testing/sse_round_trip.ts

Schema-driven SSE route validation test suite.

Complements describe_round_trip_validation (which skips SSE routes). For each configured SSE route: 1. Open the stream with matching auth. 2. Assert the : connected comment is emitted. 3. Fire trigger() — expect one data: {...} frame. 4. Validate the payload as {method, params} against declared EventSpecs. 5. Fire session_revoke_all for the account and assert the stream closes (when assert_closes_on_revoke !== false).

Declarations
#

3 declarations

view source

describe_sse_route_tests
#

testing/sse_round_trip.ts view source

(options: SseRouteTestOptions): void

Run SSE route validation tests.

For each route: opens an authenticated SSE connection, asserts the connected comment, fires the trigger, validates the resulting payload, then asserts close-on-revoke (unless opted out).

options

returns

void

throws

  • Error - at setup time when `options.rpc_endpoints` is empty — the

SseRouteTestOptions
#

testing/sse_round_trip.ts view source

SseRouteTestOptions

session_options

Session config for cookie-based auth.

type SessionOptions<string>

create_route_specs

Route spec factory — same shape as production.

type (ctx: AppServerContext) => Array<RouteSpec>

app_options

Optional overrides for AppServerOptions.

db_factories

Database factories to run tests against. Default: pglite only.

type Array<DbFactory>

on_audit_event

Backend audit event callback — threaded to create_test_app_server. Use to wire a close-on-revoke guard for consumer SSE registries (e.g., via create_sse_auth_guard) so session_revoke_all actually closes the tested streams.

type (event: AuditLogEvent) => void

rpc_endpoints

RPC endpoint specs — required so the close-on-revoke assertion can dispatch account_session_revoke_all via RPC (the former REST route POST /api/account/sessions/revoke-all was removed in the 2026-04-23 migration). Hard-fails via require_rpc_endpoint_path on setup.

Accepts either an array (eager) or a factory (ctx: AppServerContext) => Array<RpcEndpointSpec> — the factory form is required when action handlers must close over the per-test ctx.app_settings / ctx.deps. The factory must return the same endpoint path regardless of ctx — it is invoked once at setup with a stub ctx for path lookup and again per-test by create_app_server for live dispatch.

routes

SSE routes to exercise.

type Array<SseRouteTestSpec>

SseRouteTestSpec
#

testing/sse_round_trip.ts view source

SseRouteTestSpec

Config for a single SSE route under test.

path

Full HTTP path of the SSE endpoint (e.g., '/api/tx/subscribe').

type string

trigger

Fire an event matching one of the declared event_specs that should reach the open stream. Called after the : connected comment is observed. The triggered frame must be a JSON-serializable {method, params} payload.

type (ctx: {test_app: TestApp; account: TestAccount}) => Promise<void>

event_specs

Event specs to validate the triggered payload against. When omitted, the payload is only asserted to be well-formed {method, params}.

type Array<EventSpec>

assert_closes_on_revoke

Whether to assert the stream closes after session_revoke_all. Default true. Set false for endpoints that don't wire a close-on-revoke guard (leaves a TODO to fix, rather than silently passing).

type boolean

Depends on
#