testing/cross_backend/session_cap.ts

Cross-backend parity suite for the per-account concurrent-session cap over real HTTP.

Both spines cap concurrent sessions per account (the TS query_session_enforce_limit / DEFAULT_MAX_SESSIONS, the Rust create_capped_session). Each spine's own tests pin its half in-process; nothing in them crosses the wire, so a spine that lost the cap would fail no shared test. This suite is the pin that runs on *both*. It pins:

  • the cap bounds concurrent sessions, by eviction not refusal — logging in max_sessions + 1 times succeeds every time (a login is never denied for being the one over the line), and the newest cookie resolves afterward.
  • the evicted session is the oldest — the first login's cookie no longer authenticates once the cap is exceeded. A spine with no cap authenticates it fine, which is exactly the defect this catches.
  • the session list marks the caller's own session is_current — each login's account_session_list marks exactly one row, its own, over HTTP and (when ws mounts the account actions) over a socket the login opened, and a bearer or daemon-token caller's list marks none (no session authenticated it), even when a session cookie rides beside the daemon token. Computed per request, so two logins see different current rows.
  • an evicted session's socket is closed (when ws is supplied) — the cap deletes the session row, and a WebSocket never re-reads its session, so the login that evicts it must close the socket it opened (WS_CLOSE_SESSION_REVOKED), once the eviction has committed. A spine that only deletes the row leaves the socket running on a dead session.

Why max_sessions + 1 logins and not max_sessions. The starting session count isn't zero and isn't guaranteed equal across impls — create_account seeds its own session on the Rust cradle. Overshooting by one guarantees at least one eviction whatever the baseline is, and the *oldest* login is the first to go either way. Asserting on the first and last sessions rather than on a row count keeps the case wire-observable (no DB channel) and baseline-independent.

Both surfaces are flat REST (POST /api/account/login, GET /api/account/status) on every spine, so this is an imperative suite (not a conformance_table row) — the sibling of cookie_attributes.ts / origin.ts / login_security.ts. Cross-process only, and load-bearingly so: each login is held on its own fresh_transport and identified by that transport's cookie jar, which in-process is a jar-less passthrough. That also keeps the suite free of a fourth Set-Cookie parser — reading the raw header is cookie_attributes.ts's job, and this case only needs "does this login still authenticate".

What it does not pin: concurrent creators. Two simultaneous logins can each evict against a stale count under Read Committed and both commit above the cap — see query_session_enforce_limit's race note. That needs a barrier-based test against one backend, not a parity case.

view source

Declarations
#

2 declarations

describe_session_cap_cross_tests
#

SessionCapCrossTestOptions
#

testing/cross_backend/session_cap.ts view source

SessionCapCrossTestOptions import type {SessionCapCrossTestOptions} from '@fuzdev/fuz_app/testing/cross_backend/session_cap.js';

Options for the session-cap parity suite.

setup_test

Per-test fixture producer (cross-process only — see the module doc).

type (): Promise<TestFixture>

readonly
returns Promise<TestFixture>

max_sessions?

The cap both spines enforce. Defaults to DEFAULT_MAX_SESSIONS — the TS route default and the Rust const. A consumer that overrides max_sessions on the TS side passes its value here.

type number

readonly

login_path?

REST login route path. Default /api/account/login.

type string

readonly

status_path?

REST account-status route path. Default /api/account/status.

type string

readonly

rpc_path?

JSON-RPC endpoint path, for the session-list case. Default SPINE_RPC_PATH.

type string

readonly

ws?

Where the backend's WebSocket endpoint is, for the case that an evicted session's socket is closed. Pass it when the backend has a WS transport (capabilities.ws); omitted, that case is skipped.

type WsEndpointTarget

readonly

ws_account_actions?

Whether the ws endpoint mounts the self-service account actions (capabilities.ws_account_actions), so the session-list case also lists over a socket. Default false.

type boolean

readonly

ws_account_roles?

The roles the account whose socket the ws case watches is created with, for a backend whose WS upgrade requires a role (an admin-gated /api/ws refuses a roleless account's upgrade). Each must be admin-grantable — the fixture offers it. Default none.

type readonly string[]

readonly

Depends on
#

Imported by
#