testing/cross_backend/role_grant_offer_notification_ws.ts

Cross-process role-grant-offer lifecycle WS notification suite — the machinery proof for the consentful-role-grants notification fan-out across any spine backend. Covers every server-initiated notification of the lifecycle:

  • role_grant_offer_received → recipient (offer created)
  • role_grant_offer_accepted → grantor (recipient accepts)
  • role_grant_offer_declined → grantor (recipient declines)
  • role_grant_offer_retracted → recipient (grantor retracts)
  • role_grant_revoked (flat, omits revoked_by) → revokee (active grant revoked by the role_grant_revoke action), for a global grant and a scoped one unless scope_kind is null
  • role_grant_offer_supersede → each superseded sibling's grantor, fired on BOTH the accept-cascade (reason: 'sibling_accepted') and the revoke-cascade (reason: 'role_grant_revoked')

These exercise only spine primitives (accounts, role-grants, offers, WS notifications) — zero consumer domain — so the suite lives here and runs against any backend that wires the standard RPC actions' notification_sender and mounts a registered WS socket: fuz_app's own spine self-tests (testing_spine_server + the Rust testing_spine_stub) and downstream twin-impl consumers (the fuz_forge Deno/Hono + Rust fuz_forge_server backends) alike.

Each case is a *targeted* server-initiated notification (vs the broadcast in a repo_updated-style suite), so it opens the affected counterparty's socket, drives the lifecycle RPC over HTTP, then asserts the frame lands on that socket and strict-parses against the canonical wire schema — the guard against serialization drift (field / null / datetime / the flat revoke shape / the supersede reason + cause_id). Every case also holds a third account's admitted socket open — a bystander, party to nothing the case drives — and, once the targeted frame has landed, asserts the bystander received nothing but the answers to its own requests, behind a heartbeat barrier on its socket (assert_bystander_heard_nothing says why the barrier makes the silence meaningful). A fan-out that reached past its target account fails there.

Sends are queued on the post-commit drain (handler-emit, not audit-derived), so a frame may land a beat after the RPC resolves — WsClient.wait_for polls already-received messages then waits, absorbing the fan-out latency without a sleep, and its method+predicate filter ignores unrelated frames (e.g. the received push the recipient also gets). ROLE_ADMIN is the only admin-grantable role; accounts that already hold it can still be offered it again (a fresh pending row — the prior accept is terminal, no already-granted guard), and accept stays idempotent on the role_grant while still superseding pending siblings. Gated on capabilities.ws.

The revoke case revokes the revokee's only ROLE_ADMIN grant. On an endpoint gated on that role (ws_required_roles) the revokee's socket loses its access by the same revoke: it is closed with WS_CLOSE_PERMISSION_REVOKED, and the notification may or may not reach it first (nothing orders the two), so the case asserts the close there and the frame on an ungated endpoint.

Cross-process only: create_admitted_ws_transport needs a real bound socket, so wire it from a *.cross.test.ts file, never an in-process setup. Authed cookies come from the per-account session minted by fixture.create_account / fixture.create_session_headers.

view source

Declarations
#

2 declarations

describe_role_grant_offer_notification_ws_tests
#

testing/cross_backend/role_grant_offer_notification_ws.ts view source

(options: RoleGrantOfferNotificationWsTestOptions): void import {describe_role_grant_offer_notification_ws_tests} from '@fuzdev/fuz_app/testing/cross_backend/role_grant_offer_notification_ws.js';

Register the role-grant-offer WS notification suite — cases over a real upgrade, one per server-initiated notification (received / accepted / declined / retracted / revoke, global and scoped, + supersede on both the accept and revoke cascades). Each opens the affected counterparty's socket, drives the lifecycle RPC, and strict-parses the delivered frame against its canonical params schema. Gated on capabilities.ws.

options

returns

void

RoleGrantOfferNotificationWsTestOptions
#

testing/cross_backend/role_grant_offer_notification_ws.ts view source

RoleGrantOfferNotificationWsTestOptions import type {RoleGrantOfferNotificationWsTestOptions} from '@fuzdev/fuz_app/testing/cross_backend/role_grant_offer_notification_ws.js';

inheritance

setup_test

Per-test fixture producer (default_cross_process_setup(handle, ...)).

type (): Promise<TestFixture>

readonly
returns Promise<TestFixture>

capabilities

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

type BackendCapabilities

readonly

ws_required_roles?

The roles ws_path gates its upgrade on (its required_roles), or omitted / [] for an ungated endpoint. Declare them for a backend whose socket is role-gated: revoking ROLE_ADMIN then closes the revokee's socket with WS_CLOSE_PERMISSION_REVOKED, and the revoke case asserts that close instead of the notification frame.

type readonly string[]

readonly

scoped_role?

The role the scoped-revoke case assigns in a scope and revokes — one the backend's registry holds with the admin grant path. Default SPINE_PARTICIPANT_ROLE, the spine's own.

type string

readonly

scope_kind?

A scope kind scoped_role applies to, for the scoped-revoke case; null skips that case. Default 'space' (the spine participant's), or null for a builtin role, which is global-only.

type string | null

readonly

Depends on
#

Imported by
#