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

Its cases follow 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), which closes every stream of the account once the revoke commits (the handler's close, repeated by the audit guard on the session_revoke_all row). 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), which closes only the stream registered under that session's hash (the distinct close cases 2–3 don't reach).
  5. close on account delete (gated on rpc_path and capabilities.account_lifecycle) — the keeper soft-deletes a second admin whose stream is open; the delete revokes its credentials and closes its stream.
  6. close on the other account-wide revocations (gated on rpc_path; purge also on capabilities.account_lifecycle) — admin_token_revoke_all, POST /logout, POST /password, and account_purge of a second admin each close its stream — the rows create_account_revocations shares with the WS suite.
  7. per-session cap — one stream past max_per_scope on one session closes the oldest (evict-oldest, no final frame) and leaves every other stream open. Needs no RPC: the cap runs inside the subscribe itself.

The close-on-revoke matrix is layered: cases 3–6 exercise the account-wide and session-scoped paths cross-process; token_revoke (token-scoped — the stock stream admits sessions only, so its bearer close is covered on the WebSocket by describe_cross_process_ws_tests) 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.

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';

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 (): Promise<TestFixture>

readonly
returns Promise<TestFixture>

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

max_per_scope?

The backend's per-session audit-stream cap, which the cap case opens one stream past. Defaults to AUDIT_LOG_SSE_MAX_PER_SCOPE, the cap both spines apply unless overridden; null (a backend with the cap disabled) skips the case.

type number | null

readonly

logout_path?

REST logout route path, for the logout close case. Default /api/account/logout.

type string

readonly

password_path?

REST password-change route path, for its close case. Default /api/account/password.

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. Its cases run over a real streaming fetch: connected-comment, audit data frame, account-wide close-on-revoke, session-scoped close-on-revoke, close on account delete, close on admin token revoke-all, logout, password change and purge, and the per-session cap.

options

returns

void

Depends on
#

Imported by
#