testing/cross_backend/testing_reset_actions.ts

Test-binary RPC actions for cross-process integration tests.

The daemon-token-authed actions bundled by create_testing_actions: _testing_reset (DB wipe + keeper re-seed), _testing_drain_effects (audit barrier), _testing_mint_session (forge an expired-by-construction server-side session for the expiry conformance cases), _testing_put_fact (seed an embedded fact for the fact-serving suite), _testing_schema_snapshot (introspect the live schema for cross-impl parity diffing against a Rust backend's fuz_db snapshot), _testing_migration_tracker (dump the schema_version tracker rows for cross-impl migration-identity parity — the provenance half the snapshot gate excludes by design), and _testing_flood_notifications (queue a burst of notifications onto the caller's own WebSocket connection, to push its outbound queue past its byte budget).

Two further daemon-token actions live here but are not bundled by create_testing_actions, and are appended at the full-mount layer (build_full_spine_rpc_actions) instead: _testing_action_manifest (dump the live RPC registry for cross-impl method-set + auth-shape parity — it must enumerate *every* mounted method, so it goes where the complete list exists) and _testing_shorten_credential_expiry (pull an account's credential expiries in to seconds from now, shorten-only, for the credential-deadline cases) — the latter kept out of the bundle so a consumer whose Rust binary doesn't mount its mirror keeps a green manifest gate. _testing_origin_check, mounted the same way, lives in the hono-free testing_origin_check.ts.

_testing_reset — full DB wipe + keeper re-seed + optional secondary-account seeding. The handler first fires the consumer-supplied domain-state callback (domain rows depend on auth rows, so a domain table with a restricting FK to actor empties before the rows it references go), then wipes every auth-namespace row (no keeper-preserve filter), flips bootstrap_lock back to its post-bootstrap shape, seeds a fresh keeper account inline (reusing create_test_account_with_credentials so cross-process matches in-process write semantics), queues the daemon-token cache refresh to point at the new keeper once the reset commits, and seeds any caller-requested extra_accounts (also direct-inserted at this setup step). The new keeper + secondary credentials return as the action output so the per-test fixture closes over them.

In-process and cross-process keeper lifetimes match: both modes run against a freshly bootstrapped keeper per test, so mutation-cascade tests (password change, revoke-all, hardcoded-username signup uniqueness) and direct keeper-vs-admin probes work uniformly cross-process.

Keeper ≠ admin. The keeper and admin roles are independent. Keeper authorizes daemon-token / bootstrap paths; admin authorizes the user-facing admin RPC surface. _testing_reset seeds the keeper account with [ROLE_KEEPER, ROLE_ADMIN] by default — matching the production bootstrap_account flow — plus any roles passed via extra_keeper_roles. Tests probing the keeper-vs-admin separation (a keeper-only account must 403 on admin RPCs) declare a secondary via extra_accounts: [{username, roles: [ROLE_KEEPER]}] so the account is seeded at this same bootstrap-equivalent step.

No free-form runtime bypass. There is no action for arbitrary direct role grants: a runtime bypass would let tests skip the production consent flow's side-effects (audit emit, WS fan-out) and silently mask bugs in those paths. The bypass that does exist — extra_accounts — is framed as bootstrap-time seeding, the same shape bootstrap_account itself uses to grant the initial KEEPER + ADMIN pair. Tests that want a role on a *post-bootstrap* account must route through role_grant_offer_create + role_grant_offer_accept (the production path); they observe the full event chain.

Production safety: this module lives under cross_backend/ and starts with import '../assert_dev_env.ts'; — production bundles either tree-shake the module out or throw at startup. The Rust mirror (fuz_testing crate) ships a parallel action; `cargo xtask check-release blocks fuz_testing` from entering production dep graphs.

view source

Declarations
#

24 declarations

create_testing_action_manifest_action
#

testing/cross_backend/testing_reset_actions.ts view source

(mounted: readonly RpcAction[]): RpcAction import {create_testing_action_manifest_action} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

Build the _testing_action_manifest action over a backend's full live RPC mount. The handler closes over a manifest computed once at assembly time from every mounted spec except the protocol methods (PROTOCOL_METHODS) plus this action's own spec — the manifest action is itself a live method, so it must appear in the dump it serves. mounted excludes it (it's appended to the mount *after* the rest is assembled, in build_full_spine_rpc_actions), so its static spec is folded in here; the Rust mirror folds in its own descriptor the same way.

mounted

every other action on the backend's live RPC mount

type readonly RpcAction[]

returns

RpcAction

create_testing_actions
#

testing/cross_backend/testing_reset_actions.ts view source

(deps: AppDeps, options: CreateTestingActionsOptions): RpcAction[] import {create_testing_actions} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

Build the testing RPC actions for a test binary's registry.

Returns the bundled _testing_* actions (module doc). The test binary calls this at server-assembly time and registers the result on its dispatcher. _testing_drain_effects drains deps.audit, so the binary's audit_factory builds the emitter with track_inflight: true.

The reset action's table-wipe list mirrors auth_integration_truncate_tables from testing/db.ts — the canonical "auth tables a between-test reset must clear" set. testing_reset_actions.coverage.test.ts enforces the set-equality invariant so a future auth migration that adds a table to that list without updating this handler fails CI.

deps

type AppDeps

options

returns

RpcAction[]

create_testing_drain_effects_action
#

testing/cross_backend/testing_reset_actions.ts view source

(audit: AuditEmitter): RpcAction import {create_testing_drain_effects_action} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

Build the standalone _testing_drain_effects action over audit — the emitter the backend's handlers emit through (deps.audit), built with track_inflight: true (see the spec doc). Mount it on any test endpoint whose suite asserts on audit rows (the spine binary bundles it via create_testing_actions; in-process suites mount it directly). Answers {ok: true, tracked}, tracked read from audit.is_tracking_inflight().

audit

the backend's emitter, whose in-flight writes the action awaits

returns

RpcAction

create_testing_flood_notifications_action
#

testing/cross_backend/testing_reset_actions.ts view source

(): RpcAction import {create_testing_flood_notifications_action} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

Build the standalone _testing_flood_notifications action (see the spec doc). The spine binary bundles it via create_testing_actions; mount it directly on an in-process WS endpoint whose suite drives an outbound overflow.

returns

RpcAction

create_testing_migration_tracker_action
#

create_testing_schema_snapshot_action
#

create_testing_shorten_credential_expiry_action
#

testing/cross_backend/testing_reset_actions.ts view source

(): RpcAction import {create_testing_shorten_credential_expiry_action} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

Build the standalone _testing_shorten_credential_expiry action (see the spec doc).

returns

RpcAction

CreateTestingActionsOptions
#

testing/cross_backend/testing_reset_actions.ts view source

CreateTestingActionsOptions import type {CreateTestingActionsOptions} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

session_options

Session cookie options — the reset action uses these when signing the fresh keeper's (and any extra accounts') session cookies. Pass the same SessionOptions the live create_app_server call was wired with.

type SessionOptions<string>

readonly

daemon_token_state

Daemon-token runtime state — the reset action points state.keeper_account_id at the freshly seeded keeper once its transaction commits (a post-commit effect, so a reset that rolls back leaves the previous keeper cached). Pass the same DaemonTokenState instance the daemon-token middleware reads.

type DaemonTokenState

readonly

reset_state?

Consumer-supplied callback invoked first, before the auth-table wipe and keeper re-seed, passed the same transactional Db the auth wipes then run on. It runs while the previous test's accounts and actors still exist, so a domain table with a restricting FK to actor / account empties before the auth wipe deletes what it references; it must not depend on the fresh keeper, which doesn't exist yet. DB-domain consumers (e.g. fuz_forge truncating its cell / fact / file tables) MUST use this db rather than a separately-pooled connection — under the in-memory drivers' single connection (pglet, PGlite) a second connection deadlocks against this still-open transaction. testing_zzz_server clears in-memory workspace registry + terminals + scoped-FS scratch (ignores db); the spine binaries (testing/cross_backend/full_spine_mount.ts and the Rust testing_spine_stub) empty the cell and fact tables. Runs inside the same RPC dispatch as the auth-table writes, so a throw rolls the whole reset back and surfaces to the caller as a JSON-RPC error and the per-test fixture short-circuits.

type (db: Db): void | Promise<void>

readonly

db

type Db
returns Promise<void> | void

ERROR_TESTING_FLOOD_NO_CONNECTION
#

testing_action_manifest_action_spec
#

testing/cross_backend/testing_reset_actions.ts view source

{ readonly method: "_testing_action_manifest"; readonly kind: "request_response"; readonly initiator: "frontend"; readonly auth: { readonly account: "required"; readonly actor: "none"; readonly credential_types: readonly [...]; }; ... 4 more ...; readonly description: string; } import {testing_action_manifest_action_spec} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

_testing_action_manifest — dump the backend's live RPC method set as a normalized ActionManifest (one entry per method: `{method, input, side_effects, account, actor, roles, credential_types, rate_limit}`) for cross-impl parity diffing. The action-surface twin of _testing_schema_snapshot: where that introspects the live *database*, this introspects the live *RPC registry*. The cross-backend harness calls it on each backend, then assert_action_manifests_equals the results (the Rust mirror is fuz_testing::create_testing_action_manifest_action_spec, whose normalization matches by design). Complements the in-repo spine_method_coverage gate (mounted ⟹ covered) by proving the TS mount-set ≡ the Rust mount-set, method-for-method and auth-shape-for-shape.

Unlike its _testing_* siblings this action is not bundled by create_testing_actions — the manifest must enumerate *every* mounted method, which create_testing_actions (one sub-factory among many) can't see. It's appended at the full-mount layer (build_full_spine_rpc_actions) via create_testing_action_manifest_action, where the complete list exists.

auth gates on the daemon-token credential, matching _testing_reset.

testing_drain_effects_action_spec
#

testing/cross_backend/testing_reset_actions.ts view source

{ readonly method: "_testing_drain_effects"; readonly kind: "request_response"; readonly initiator: "frontend"; readonly auth: { readonly account: "required"; readonly actor: "none"; readonly credential_types: readonly [...]; }; ... 4 more ...; readonly description: "Test-binary only — await in-flight fire-and-forge... import {testing_drain_effects_action_spec} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

_testing_drain_effects — await in-flight fire-and-forget audit writes so a following audit_log_list is authoritative. The deterministic barrier the cross-backend conformance suite uses in place of a poll/sleep before asserting on audit rows.

The handler awaits AuditEmitter.drain_inflight, which waits until no tracked emit write is outstanding — so the binary's emitter must be built with track_inflight: true, or the drain resolves at once and is no barrier. Tracking is what makes it a barrier whatever the transport: an HTTP mutation on a binary running await_pending_effects: true has its writes settled by the time it responds, but a WS mutation is answered before its effects flush (reply-then-close for a self-revocation), so its audit write can still be in flight when the caller reads the reply. The Rust spine does the same await in AuditEmitter::drain_inflight, over an emitter built with new_with_inflight_tracking.

Covered: every emit that ran before the drain was dispatched, and any started while it waits. A write that starts after the drain resolves is not — nor are eager writes outside emit (session touch, token usage), which only the dispatching transport's own flush awaits.

The output's tracked is AuditEmitter.is_tracking_inflight — whether the drain could wait on anything. cross_drain_effects refuses tracked: false, so a binary whose emitter was built without tracking fails its first audit read instead of racing it. The Rust twin answers the same shape.

auth gates on the daemon-token credential, matching _testing_reset.

TESTING_FLOOD_MAX_COUNT
#

testing/cross_backend/testing_reset_actions.ts view source

65536 import {TESTING_FLOOD_MAX_COUNT} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

The most notifications one _testing_flood_notifications call queues. Empty ones at this count are charged more than DEFAULT_WS_OUTBOUND_QUEUE_BYTES between them — each frame's envelope and its overhead — so a burst of tiny frames can overflow a connection on a default transport too. Same value as the Rust spine's.

TESTING_FLOOD_MAX_SIZE
#

TESTING_FLOOD_MAX_TOTAL_BYTES
#

testing/cross_backend/testing_reset_actions.ts view source

number import {TESTING_FLOOD_MAX_TOTAL_BYTES} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

The most payload bytes one _testing_flood_notifications call builds across all its notifications — the bound on count × size. The handler serializes each notification without yielding, so the product is how long one call holds the event loop.

TESTING_FLOOD_NOTIFICATION_METHOD
#

testing_flood_notifications_action_spec
#

testing/cross_backend/testing_reset_actions.ts view source

{ readonly method: "_testing_flood_notifications"; readonly kind: "request_response"; readonly initiator: "frontend"; readonly auth: { readonly account: "required"; readonly actor: "none"; readonly credential_types: readonly [...]; }; ... 5 more ...; readonly description: string; } import {testing_flood_notifications_action_spec} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

_testing_flood_notifications — queue a burst of notifications onto the caller's own WebSocket connection, all in one synchronous run, so a suite driving the server from outside can push a connection's outbound queue past its byte budget deterministically — without a second producer, and whether or not its client is reading: the connection's write pump gets no turn while the handler runs, so the burst waits at once. Past the budget the server closes the socket with WS_CLOSE_OUTBOUND_OVERFLOW.

Each notification is {"jsonrpc":"2.0","method":"_testing_flood","params":{"index":<i>,"payload":"<size × 'x'>"}} with index counting from 0, so every frame is a little longer than size bytes and a client can tell which frames reached it.

The result is {queued: count} — the number asked for, not the number that fit: when the burst overflows the queue the connection is closed and this response is never written. A burst that fits arrives in order, ahead of the response.

A call past TESTING_FLOOD_MAX_COUNT, TESTING_FLOOD_MAX_SIZE, or TESTING_FLOOD_MAX_TOTAL_BYTES (count × size) is refused with invalid_params and queues nothing. Over HTTP there is no connection to queue onto, so the call is refused with invalid_params, reason ERROR_TESTING_FLOOD_NO_CONNECTION, rather than answering as though it had flooded something.

auth gates on the daemon-token credential, matching _testing_reset. The Rust mirror is fuz_testing::create_testing_flood_notifications_action_spec.

testing_migration_tracker_action_spec
#

testing/cross_backend/testing_reset_actions.ts view source

{ readonly method: "_testing_migration_tracker"; readonly kind: "request_response"; readonly initiator: "frontend"; readonly auth: { readonly account: "required"; readonly actor: "none"; readonly credential_types: readonly [...]; }; ... 4 more ...; readonly description: string; } import {testing_migration_tracker_action_spec} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

_testing_migration_tracker — dump the schema_version tracker rows as a normalized MigrationTracker ([{namespace, name, sequence}]) for cross-impl migration-identity diffing. The provenance half of _testing_schema_snapshot: where that captures the resulting *schema* (and excludes the tracker by design), this captures the tracker *itself*, so the cross-backend harness can assert the two spines record byte-identical migration identity. This closes the gap that let the cell/fact migration-name divergence reach the visiones cutover undetected (name-divergence-at-N — same schema, divergent recorded names).

auth gates on the daemon-token credential, matching _testing_reset. The Rust mirror is fuz_testing::create_testing_migration_tracker_action_spec.

testing_mint_session_action_spec
#

testing/cross_backend/testing_reset_actions.ts view source

{ readonly method: "_testing_mint_session"; readonly kind: "request_response"; readonly initiator: "frontend"; readonly auth: { readonly account: "required"; readonly actor: "none"; readonly credential_types: readonly [...]; }; ... 4 more ...; readonly description: string; } import {testing_mint_session_action_spec} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

_testing_mint_session — mint an expired-by-construction server-side session for an existing account and return its signed cookie value.

expires_in_seconds is constrained negative (a safe integer at most -1) so the action is structurally incapable of minting a *usable* session: it can only produce an already-backdated, already-dead auth_session row. The daemon-token gate + loopback binding already fence the backdoor, but the negative constraint is the make-impossible-states floor — even a misuse can't forge a valid session for an arbitrary account_id. The Rust mirror (fuz_testing::create_testing_mint_session_action_spec) enforces the same floor.

The minted auth_session row's expires_at is backdated while the returned cookie's own signed payload stays valid (future). Cross-process auth resolution therefore passes the cookie-payload gate (parse_session) and is refused by the authoritative DB-row gate (query_session_get_valid — WHERE expires_at > NOW()) — the gate the in-process payload-expiry tests never reach and the one that structurally needs a server-side mint (the cross-process driver has no keyring / DB access). The expired_session conformance principal drives this.

auth gates on the daemon-token credential, matching _testing_reset — effectively keeper-only. Like its siblings the action is internally privileged (a direct auth_session insert the production wire never exposes); daemon-token auth is the structural fence and the module's assert_dev_env import (TS) plus the Rust cargo xtask check-release dep-graph audit keep the _testing_ surface out of every shipped build.

testing_put_fact_action_spec
#

testing/cross_backend/testing_reset_actions.ts view source

{ readonly method: "_testing_put_fact"; readonly kind: "request_response"; readonly initiator: "frontend"; readonly auth: { readonly account: "required"; readonly actor: "none"; readonly credential_types: readonly [...]; }; ... 4 more ...; readonly description: string; } import {testing_put_fact_action_spec} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

_testing_put_fact — seed an embedded fact (fact.bytes) for the cross-process fact-serving suite, which drives over real HTTP and has no PgFactStore to call. Hashes the UTF-8 content (blake3, via fact_hash_bytes — the same hash the Rust _testing_put_fact computes), inserts the row idempotently, and returns {hash}. holder names the actor the put is on behalf of — recorded in fact_holder (deduplicated puts included), as a real upload records its uploader, so the suites can drive cell ref admission; absent, the put is a system put with no holder. The referencing cell is seeded separately via the cell_create RPC. Embedded is enough for the authz assertions (cell-scoped admit, cross-owner-no-leak, 404-mask, bare-hash admin-only); external / X-Accel parity stays covered by the forge's own gate. external_url, when given, writes the row the way a writer past the store could — no bytes, that URL verbatim, unvalidated — so the suite can prove a serve refuses a URL that is not its hash's own address.

auth gates on the daemon-token credential, matching _testing_reset — the action does a direct fact insert the production wire never exposes. The Rust mirror is fuz_testing::create_testing_put_fact_action_spec.

testing_reset_action_spec
#

testing/cross_backend/testing_reset_actions.ts view source

{ readonly method: "_testing_reset"; readonly kind: "request_response"; readonly initiator: "frontend"; readonly auth: { readonly account: "required"; readonly actor: "none"; readonly credential_types: readonly [...]; }; ... 4 more ...; readonly description: "Test-binary only — wipe auth tables, re-bootstrap a fresh... import {testing_reset_action_spec} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

The _testing_reset action spec.

Input:

  • extra_keeper_roles — roles to grant the fresh keeper *in addition to* [ROLE_KEEPER, ROLE_ADMIN] (matching production bootstrap).
  • extra_accounts — additional accounts to seed at this same bootstrap-equivalent step. Each entry's roles are direct-granted (bypassing offer/accept) because the seed is *part of bootstrap*, not a post-bootstrap action. Use this for accounts whose required roles aren't admin-grantable via offer/accept (e.g. ROLE_KEEPER, whose RoleSpec.grant_paths is bootstrap-only). For admin-grantable roles, prefer fixture.create_account({roles}) (offer/accept production path).

Output: keeper credentials plus a parallel array of seeded extra_accounts (same order as input). The per-test fixture closes over the returned values; subsequent calls in the same test see the fresh keeper and any requested secondaries.

auth gates on the daemon-token credential — the keeper holds it exclusively. The action is internally privileged (it runs direct DB writes the production wire never exposes); daemon-token auth is the structural fence.

testing_schema_snapshot_action_spec
#

testing/cross_backend/testing_reset_actions.ts view source

{ readonly method: "_testing_schema_snapshot"; readonly kind: "request_response"; readonly initiator: "frontend"; readonly auth: { readonly account: "required"; readonly actor: "none"; readonly credential_types: readonly [...]; }; ... 4 more ...; readonly description: "Test-binary only — introspect the live schema i... import {testing_schema_snapshot_action_spec} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

_testing_schema_snapshot — introspect the live database into a normalized SchemaSnapshot for cross-impl parity diffing. The cross-backend harness calls this on each backend, then assert_schema_snapshots_equals the results (a Rust backend answers from fuz_db::query_schema_snapshot; the shapes match by design). Optional exclude_tables drops documented divergences from both sides before comparison.

A backend running on pglet (a TS backend config's memory:// default) answers with an error when its schema holds an index: the snapshot exists to be compared, and pglet's index definitions omit the modifiers a comparison needs (query_schema_snapshot). Run the backend on PostgreSQL.

auth gates on the daemon-token credential, matching _testing_reset.

testing_shorten_credential_expiry_action_spec
#

testing/cross_backend/testing_reset_actions.ts view source

{ readonly method: "_testing_shorten_credential_expiry"; readonly kind: "request_response"; readonly initiator: "frontend"; readonly auth: { readonly account: "required"; readonly actor: "none"; readonly credential_types: readonly [...]; }; ... 4 more ...; readonly description: string; } import {testing_shorten_credential_expiry_action_spec} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

_testing_shorten_credential_expiry — pull the expiry of an account's stored credentials (every auth_session and api_token row it owns) in to seconds from now, so the cross-backend credential-deadline suite can open a WebSocket or audit stream on a credential that expires a moment later and watch it close at the deadline (ResolvedAuth.credential_deadline) without waiting out a real lifetime.

Applied before the open: it rewrites the stored rows, and a connection reads its deadline when its credential resolves, so only one opened afterwards sees the near deadline.

Shorten-only. The new expiry is LEAST(expires_at, NOW() + seconds) — an eternal token gains one, and nothing already due sooner moves later, so the action can neither extend a credential's life nor revive an expired one; seconds is an integer from TESTING_SHORTEN_CREDENTIAL_EXPIRY_MIN_SECONDS to TESTING_SHORTEN_CREDENTIAL_EXPIRY_MAX_SECONDS. The Rust mirror is fuz_testing::create_testing_shorten_credential_expiry_action_spec.

Like _testing_origin_check, it is not bundled by create_testing_actions: a consumer whose Rust binary doesn't mount the mirror would fail its action-manifest parity gate. The spine test binary appends it at the full-mount layer (build_full_spine_rpc_actions).

auth gates on the daemon-token credential, matching _testing_reset.

TESTING_SHORTEN_CREDENTIAL_EXPIRY_MAX_SECONDS
#

testing/cross_backend/testing_reset_actions.ts view source

60 import {TESTING_SHORTEN_CREDENTIAL_EXPIRY_MAX_SECONDS} from '@fuzdev/fuz_app/testing/cross_backend/testing_reset_actions.js';

The longest expiry _testing_shorten_credential_expiry sets, in seconds from now — a minute: the action exists to make a deadline arrive inside a test.

TESTING_SHORTEN_CREDENTIAL_EXPIRY_MIN_SECONDS
#

Depends on
#

Imported by
#