testing/cross_backend/sse_round_trip.ts

Cross-process SSE round-trip suite — the cross-process counterpart to the in-process testing/sse_round_trip.ts harness.

Where the in-process harness reads a Hono Response.body directly, this suite opens a real streaming fetch against a spawned backend's audit-log SSE endpoint via create_sse_transport, threading the fresh-per-test keeper's session cookie. It is the only coverage of the spawned binary's live SSE path — the standard cross-process bundle (describe_standard_cross_process_tests) omits SSE by design, so consumers call this alongside it (paralleling describe_cross_process_ws_tests).

Four cases, mirroring the in-process SSE self-test against fuz_app's standard audit-log stream:

  1. connects — the stream opens and emits the : connected comment.
  2. data frame (gated on rpc_path) — a minted secondary's sessions are revoked over the keeper's admin channel (admin_session_revoke_all), broadcasting a session_revoke_all audit event as one data: frame to the subscribed keeper without closing its stream (the event targets the secondary, not the subscriber). The secondary is minted *before* the stream opens so create_account's own audit events (invite / signup / login / token) don't land on it.
  3. close-on-revoke, account-wide (gated on rpc_path) — the subscriber's *own* sessions are revoked (account_session_revoke_all), so the session_revoke_all event targets the keeper and the audit guard drops the live stream via the account-wide close_for_account path. Asserted via SseTransport.wait_for_close.
  4. close-on-revoke, session-scoped (gated on rpc_path) — the subscriber's *own* single session is revoked (account_session_revoke), so the session_revoke event drops the stream via the session-hash-scoped close_for_session path (the distinct primitive cases 2–3 don't reach).

The close-on-revoke matrix is layered: cases 3–4 exercise the account-wide and session-scoped paths cross-process; the remaining union events (token_revoke_all / logout / password_change, all account-wide; and role_grant_revoke, role-matched) are covered by the spine's fuz_realtime SSE-registry unit tests and the in-process guard self-test, so a cross-process token_revoke_all-with-zero-tokens case (which may emit no audit row) stays out to keep the spawned-backend suite non-flaky.

Gated on capabilities.sse — backends without an end-to-end SSE stream skip (the cases still surface as .skip in the report). Cross-process only: create_sse_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

CrossProcessSseTestOptions
#

testing/cross_backend/sse_round_trip.ts view source

CrossProcessSseTestOptions import type {CrossProcessSseTestOptions} from '@fuzdev/fuz_app/testing/cross_backend/sse_round_trip.js';

Configuration for .

setup_test

Per-test fixture producer (default_cross_process_setup(handle)). Each case reads the fresh-per-test keeper's session cookies from fixture.transport.cookies() to thread onto the stream. The keeper holds ROLE_ADMIN by default, so it can subscribe to the admin-gated audit stream and drive admin_session_revoke_all.

type SetupTest

readonly

capabilities

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

type BackendCapabilities

readonly

base_url

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

type string

readonly

sse_path?

SSE stream path on the backend. Defaults to /api/admin/audit/stream.

type string

readonly

rpc_path?

RPC endpoint path (e.g. /api/rpc) used by the data-frame and close-on-revoke cases to fire admin_session_revoke_all / account_session_revoke_all over the keeper's session channel. When omitted, those cases are skipped — they depend on the standard account + admin actions being mounted on the RPC endpoint.

type string

readonly

origin?

Origin for the stream request. Defaults to base_url.

type string

readonly

describe_cross_process_sse_tests
#

testing/cross_backend/sse_round_trip.ts view source

(options: CrossProcessSseTestOptions): void import {describe_cross_process_sse_tests} from '@fuzdev/fuz_app/testing/cross_backend/sse_round_trip.js';

Register the cross-process SSE round-trip suite. Up to four cases over a real streaming fetch: connected-comment, audit data frame, account-wide close-on-revoke, and session-scoped close-on-revoke.

options

returns

void

Depends on
#