Skip to main content

@flow-state-dev/engine/testing

Classes​

StateReadGateTimeoutError​

Thrown when a gated route never reaches its state read.

A distinct type because the only honest thing a gate can do on expiry is fail: it cannot tell "this route does not read" from "this read is slow", and every assertion downstream looks identical either way.

Extends​

  • Error

Constructors​

Constructor​
new StateReadGateTimeoutError(timeoutMs): StateReadGateTimeoutError;
Parameters​
timeoutMs​

number

Returns​

StateReadGateTimeoutError

Overrides​

Error.constructor

Properties​

cause?​
cause?: unknown;
Inherited from​

Error.cause

message​
message: string;
Inherited from​

Error.message

name​
name: string;
Inherited from​

Error.name

stack?​
stack?: string;
Inherited from​

Error.stack

Interfaces​

StateReadGate​

Handle returned by gateNextStateRead.

Methods​

release()​
release(): void;

Let the parked read return, resuming the request.

Returns​

void

whenRead()​
whenRead(): Promise<void>;

Resolve once the route has parked at its state read.

Returns​

Promise<void>

Throws​

if no read arrives in time.

Type Aliases​

AcrossSessionsUnderTest​

type AcrossSessionsUnderTest = object;

One backend under test: its resource-state store and the session store it joins to.

Properties​

resourceState​
resourceState: ResourceStateStore;
sessions​
sessions: Pick<SessionStore, "set">;

Where the suite writes the sessions the rows join to.

statements?​
statements?: string[];

SQL adapters only: every statement the resource-state store runs is pushed here, so the suite can check a page is one statement reading sessions.


CreateAcrossSessionsConformanceTestsOptions​

type CreateAcrossSessionsConformanceTestsOptions = object;

Properties​

cleanup?​
cleanup?: (store) => Promise<void> | void;

Optional teardown hook for backends with external resources.

Parameters​
store​

AcrossSessionsUnderTest

Returns​

Promise<void> | void

createStore​
createStore: () =>
| AcrossSessionsUnderTest
| Promise<AcrossSessionsUnderTest>;

Build a fresh, empty backend. Called per test.

Returns​

| AcrossSessionsUnderTest | Promise<AcrossSessionsUnderTest>

name​
name: string;

Display name surfaced in the describe block, e.g. "SQLite".


CreateContentStoreConformanceTestsOptions​

type CreateContentStoreConformanceTestsOptions = object;

Options for createContentStoreConformanceTests.

Properties​

cleanup?​
cleanup?: (store) => Promise<void> | void;

Optional teardown hook for adapters with external resources.

Parameters​
store​

ContentStore

Returns​

Promise<void> | void

createStore​
createStore: () =>
| ContentStore
| Promise<ContentStore>;

Build a fresh ContentStore. Called per-test.

Returns​

| ContentStore | Promise<ContentStore>

name​
name: string;

Display name surfaced in the describe block, e.g. "SQLiteContentStore".


CreateFindByConformanceTestsOptions​

type CreateFindByConformanceTestsOptions = object;

Options for createFindByConformanceTests.

Properties​

cleanup?​
cleanup?: (stores) => Promise<void> | void;

Optional teardown for adapters with external resources.

Parameters​
stores​

StoreRegistry

Returns​

Promise<void> | void

createStores​
createStores: () =>
| StoreRegistry
| Promise<StoreRegistry>;

Build a fresh, empty store registry. Called once per case.

Returns​

| StoreRegistry | Promise<StoreRegistry>

indexes​
indexes: boolean;

true when the resource-state store implements the index verbs.

name​
name: string;

Display name surfaced in the describe block.


CreateLeaseStoreConformanceTestsOptions​

type CreateLeaseStoreConformanceTestsOptions = object;

Properties​

cleanup?​
cleanup?: (store) => Promise<void> | void;

Optional teardown hook for backends with external resources.

Parameters​
store​

LeaseStore

Returns​

Promise<void> | void

createStore​
createStore: () =>
| LeaseStore
| Promise<LeaseStore>;

Build a fresh, empty lease store. Called per test.

Returns​

| LeaseStore | Promise<LeaseStore>

name​
name: string;

Display name surfaced in the describe block, e.g. "SQLite".


CreateParkedGateConformanceTestsOptions​

type CreateParkedGateConformanceTestsOptions = object;

Properties​

createStores​
createStores: () =>
| StoreRegistry
| Promise<StoreRegistry>;

A fresh registry on an empty store.

Returns​

| StoreRegistry | Promise<StoreRegistry>

name​
name: string;

CreatePendingUserSuspensionsConformanceTestsOptions​

type CreatePendingUserSuspensionsConformanceTestsOptions = object;

Properties​

cleanup?​
cleanup?: (store) => Promise<void> | void;

Optional teardown hook for backends with external resources.

Parameters​
store​

PendingUserSuspensionsUnderTest

Returns​

Promise<void> | void

createStore​
createStore: () =>
| PendingUserSuspensionsUnderTest
| Promise<PendingUserSuspensionsUnderTest>;

Build a fresh, empty backend. Called per test.

Returns​

| PendingUserSuspensionsUnderTest | Promise<PendingUserSuspensionsUnderTest>

name​
name: string;

Display name surfaced in the describe block, e.g. "SQLite".


CreateRequestRetentionConformanceTestsOptions​

type CreateRequestRetentionConformanceTestsOptions = object;

Properties​

cleanup?​
cleanup?: (stores) => Promise<void> | void;

Optional teardown hook for backends with external resources.

Parameters​
stores​

StoreRegistry

Returns​

Promise<void> | void

createStores​
createStores: () =>
| StoreRegistry
| Promise<StoreRegistry>;

Build a fresh, empty store registry. Called per test.

Returns​

| StoreRegistry | Promise<StoreRegistry>

name​
name: string;

Display name surfaced in the describe block, e.g. "SQLite stores".


CreateRequestStoreConformanceTestsOptions​

type CreateRequestStoreConformanceTestsOptions = object;

Properties​

cleanup?​
cleanup?: (store) => Promise<void> | void;

Optional teardown hook for adapters with external resources.

Parameters​
store​

RequestStore

Returns​

Promise<void> | void

createStore​
createStore: () =>
| RequestStore
| Promise<RequestStore>;

Build a fresh store. Called per-test so cases run against an empty backend.

Returns​

| RequestStore | Promise<RequestStore>

name​
name: string;

Display name surfaced in the describe block, e.g. "InMemoryRequestStore".

pollIntervalMs?​
pollIntervalMs?: number;

Effective subscription poll interval (ms). Polling backends should pass their configured interval so the live-phase tolerance windows are wide enough to be deterministic. Memory uses 0 (no polling).

skipLivenessTimeout?​
skipLivenessTimeout?: boolean;

If true, the suite skips the liveness-timeout case. Memory deliberately ignores livenessTimeoutMs (no cross-process death scenario) and should set this.


CreateResourceStateStoreConformanceTestsOptions​

type CreateResourceStateStoreConformanceTestsOptions = object;

Options for createResourceStateStoreConformanceTests.

Properties​

cleanup?​
cleanup?: (store) => Promise<void> | void;

Optional teardown hook for adapters with external resources.

Parameters​
store​

ResourceStateStore

Returns​

Promise<void> | void

createStore​
createStore: () =>
| ResourceStateStore
| Promise<ResourceStateStore>;

Build a fresh ResourceStateStore. Called per-test.

Returns​

| ResourceStateStore | Promise<ResourceStateStore>

indexes?​
indexes?: boolean;

Whether the store keeps index entries (store.indexes). When true, the index-verb cases run against it; when omitted or false, the suite asserts the store has no index verbs and only checks that a set carrying entries behaves exactly like one without.

name​
name: string;

Display name surfaced in the describe block, e.g. "SQLiteResourceStateStore".


CreateScopeStoreConformanceTestsOptions​

type CreateScopeStoreConformanceTestsOptions = object;

Properties​

cleanup?​
cleanup?: (store) => Promise<void> | void;

Optional teardown hook for adapters with external resources.

Parameters​
store​

ScopeStoreUnderTest

Returns​

Promise<void> | void

createSharedPair?​
createSharedPair?: () => Promise<{
a: ScopeStoreUnderTest;
b: ScopeStoreUnderTest;
cleanup?: () => Promise<void> | void;
}>;

Build two stores over one backing database, simulating two nodes.

Supply this wherever the backend can actually be shared. It is what distinguishes an atomic create-if-absent from a read-then-insert: a single-process Promise.all proves ordering, not atomicity. On better-sqlite3 in particular nothing yields between two statements inside one process, so the interleaving that breaks a non-atomic implementation cannot even occur in-process — a read-then-insert would pass every other case here and still lose the race in production.

Omit it only for adapters with no cross-connection notion (in-memory), or where the store's own guarantee is explicitly in-process (filesystem, whose lock is held on the instance).

Returns​

Promise<{ a: ScopeStoreUnderTest; b: ScopeStoreUnderTest; cleanup?: () => Promise<void> | void; }>

createStore​
createStore: () =>
| ScopeStoreUnderTest
| Promise<ScopeStoreUnderTest>;

Build a fresh store. Called per-test so cases run against an empty backend.

Returns​

| ScopeStoreUnderTest | Promise<ScopeStoreUnderTest>

name​
name: string;

Display name surfaced in the describe block, e.g. "SQLiteSessionStore".


CreateSessionStreamConformanceTestsOptions​

type CreateSessionStreamConformanceTestsOptions = object;

Properties​

cleanup?​
cleanup?: () => Promise<void> | void;

Called after each case, e.g. to close database handles.

Returns​

Promise<void> | void

createSharedPair?​
createSharedPair?: () => Promise<{
a: StoreRegistry;
b: StoreRegistry;
cleanup?: () => Promise<void> | void;
}>;

Two registries over one backing store, as two servers sharing a database would hold them. Omitted, the two-server case runs two routers over one registry, which is the only arrangement the in-memory store has.

Returns​

Promise<{ a: StoreRegistry; b: StoreRegistry; cleanup?: () => Promise<void> | void; }>

createStores​
createStores: () =>
| StoreRegistry
| Promise<StoreRegistry>;

Build fresh stores. Called per test so each case starts empty.

Returns​

| StoreRegistry | Promise<StoreRegistry>

itemsReadableWhileRunning​
itemsReadableWhileRunning: boolean;

Whether an item a running request keeps can be read before the request finishes. False for the in-memory store, which writes a request's items when it ends; the stream then sends them when it ends.

name​
name: string;

Display name surfaced in the describe block, e.g. "SQLite".


CreateTraceStoreConformanceTestsOptions​

type CreateTraceStoreConformanceTestsOptions = object;

Testing entry point for @flow-state-dev/engine. Imported as @flow-state-dev/engine/testing. Hosts conformance harnesses, fixture builders, and race-staging helpers for store-interface and route tests.

Properties​

cleanup?​
cleanup?: (store) => Promise<void> | void;

Optional teardown hook for adapters with external resources.

Parameters​
store​

TraceStore

Returns​

Promise<void> | void

createStore​
createStore: (options?) =>
| TraceStore
| Promise<TraceStore>;

Build a fresh store. Called per-test so eviction and cursor cases run against an empty backend. maxRequests lets eviction tests configure a small cap without leaking into the default-retention assertions.

Parameters​
options?​
maxRequests?​

number

Returns​

| TraceStore | Promise<TraceStore>

name​
name: string;

Display name surfaced in the describe block, e.g. "InMemoryTraceStore".


CreateWakeStoreConformanceTestsOptions​

type CreateWakeStoreConformanceTestsOptions = object;

Properties​

cleanup?​
cleanup?: (store) => Promise<void> | void;

Optional teardown hook for backends with external resources.

Parameters​
store​

WakeStore

Returns​

Promise<void> | void

createStore​
createStore: () =>
| WakeStore
| Promise<WakeStore>;

Build a fresh, empty wake store. Called per test.

Returns​

| WakeStore | Promise<WakeStore>

name​
name: string;

Display name surfaced in the describe block, e.g. "SQLite".


MakeTraceEventOptions​

type MakeTraceEventOptions = object;

Testing entry point for @flow-state-dev/engine. Imported as @flow-state-dev/engine/testing. Hosts conformance harnesses, fixture builders, and race-staging helpers for store-interface and route tests.

Properties​

payload?​
payload?: Record<string, unknown>;
ts?​
ts?: number;

PendingUserSuspensionsUnderTest​

type PendingUserSuspensionsUnderTest = object;

One backend under test: its suspension store and the request store it joins to.

Properties​

requests​
requests: Pick<RequestStore, "set">;

Where the suite writes the requests the suspensions join to.

statements?​
statements?: string[];

SQL adapters only: every statement the suspension store runs is pushed here, so the suite can check the read is one statement joining requests.

suspensions​
suspensions: SuspensionStore;

ScopeStoreUnderTest​

type ScopeStoreUnderTest = object;

The slice of a scope store this suite exercises. Structurally satisfied by every adapter's SessionStore; the delta verbs stay optional because the contract lets an adapter implement none of them.

Methods​

delete()​
delete(id): Promise<void>;
Parameters​
id​

string

Returns​

Promise<void>

deleteField()?​
deleteField?(
id,
path,
expectedVersion,
updatedAt
): Promise<SetResult<SessionRecord>>;
Parameters​
id​

string

path​

string[]

expectedVersion​

ExpectedVersion

updatedAt​

number

Returns​

Promise<SetResult<SessionRecord>>

get()​
get(id): Promise<SessionRecord | undefined>;
Parameters​
id​

string

Returns​

Promise<SessionRecord | undefined>

incField()?​
incField?(
id,
path,
delta,
expectedVersion,
updatedAt
): Promise<SetResult<SessionRecord>>;
Parameters​
id​

string

path​

string[]

delta​

number

expectedVersion​

ExpectedVersion

updatedAt​

number

Returns​

Promise<SetResult<SessionRecord>>

patchField()?​
patchField?(
id,
path,
value,
expectedVersion,
updatedAt
): Promise<SetResult<SessionRecord>>;
Parameters​
id​

string

path​

string[]

value​

unknown

expectedVersion​

ExpectedVersion

updatedAt​

number

Returns​

Promise<SetResult<SessionRecord>>

pushToArray()?​
pushToArray?(
id,
path,
values,
expectedVersion,
updatedAt
): Promise<SetResult<SessionRecord>>;
Parameters​
id​

string

path​

string[]

values​

unknown[]

expectedVersion​

ExpectedVersion

updatedAt​

number

Returns​

Promise<SetResult<SessionRecord>>

set()​
set(
id,
value,
expectedVersion
): Promise<SetResult<SessionRecord>>;
Parameters​
id​

string

value​

SessionRecord

expectedVersion​

ExpectedVersion

Returns​

Promise<SetResult<SessionRecord>>

Variables​

sessionStreamReads​

const sessionStreamReads: object;

The two ordered reads every connection repeats about once a second, as the list options it sends: one session's requests and one parent's runs, newest updated first. Each adapter's index tests measure these, so they measure exactly what the stream asks of the database.

Type Declaration​

recentRequests​
recentRequests: (sessionId, session, tenantId, limit) => RequestListOptions;
Parameters​
sessionId​

string

session​

SessionRecord

tenantId​

string | undefined

limit​

number

Returns​

RequestListOptions

recentRuns​
recentRuns: (sessionId, session, tenantId, limit) => SessionListOptions;
Parameters​
sessionId​

string

session​

SessionRecord

tenantId​

string | undefined

limit​

number

Returns​

SessionListOptions

Param​

sessionId

The bare session id the stream follows.

Param​

session

That session's record, as the stream opened on it.

Param​

tenantId

The caller's tenant.

Param​

limit

Rows to read, newest first.

Functions​

createAcrossSessionsConformanceTests()​

function createAcrossSessionsConformanceTests(options): void;

Parameters​

options​

CreateAcrossSessionsConformanceTestsOptions

Returns​

void


createContentStoreConformanceTests()​

function createContentStoreConformanceTests(options): void;

Register the shared ContentStore conformance cases against a backend. Call inside a test file's top-level scope.

Parameters​

options​

CreateContentStoreConformanceTestsOptions

Returns​

void


createFindByConformanceTests()​

function createFindByConformanceTests(options): void;

Register the findBy conformance cases against a store registry.

Parameters​

options​

CreateFindByConformanceTestsOptions

Returns​

void


createLeaseStoreConformanceTests()​

function createLeaseStoreConformanceTests(options): void;

Register the lease-store conformance cases against a backend. Call inside a test file's top-level scope.

Parameters​

options​

CreateLeaseStoreConformanceTestsOptions

Returns​

void


createParkedGateConformanceTests()​

function createParkedGateConformanceTests(options): void;

Parameters​

options​

CreateParkedGateConformanceTestsOptions

Returns​

void


createPendingUserSuspensionsConformanceTests()​

function createPendingUserSuspensionsConformanceTests(options): void;

Register the pending-suspensions conformance cases against a backend. Call inside a test file's top-level scope.

Parameters​

options​

CreatePendingUserSuspensionsConformanceTestsOptions

Returns​

void


createRequestRetentionConformanceTests()​

function createRequestRetentionConformanceTests(options): void;

Register the retention reused-id conformance cases against a backend. Call inside a test file's top-level scope.

Parameters​

options​

CreateRequestRetentionConformanceTestsOptions

Returns​

void


createRequestStoreConformanceTests()​

function createRequestStoreConformanceTests(options): void;

Register the shared RequestStore.subscribeToEvents conformance cases against a backend. Call inside a test file's top-level scope.

Parameters​

options​

CreateRequestStoreConformanceTestsOptions

Returns​

void


createResourceStateStoreConformanceTests()​

function createResourceStateStoreConformanceTests(options): void;

Register the shared ResourceStateStore conformance cases against a backend. Call inside a test file's top-level scope.

Covers the baseline keyed-store behaviour in versioned terms, then the CAS, lifecycle and ABA behaviour that is the whole point of this store being different from ContentStore. The contended cases matter most: a value-only design passes every happy-path CAS assertion, so ABA needs a delete between read and write, resurrection needs a delete racing a patch, and the deleteAll residual needs a purge racing a create.

Parameters​

options​

CreateResourceStateStoreConformanceTestsOptions

Returns​

void


createScopeStoreConformanceTests()​

function createScopeStoreConformanceTests(options): void;

Register the shared scope-store CAS conformance cases against a backend. Call inside a test file's top-level scope.

Parameters​

options​

CreateScopeStoreConformanceTestsOptions

Returns​

void


createSessionStreamConformanceTests()​

function createSessionStreamConformanceTests(options): void;

Register the session-stream conformance cases for one adapter.

Parameters​

options​

CreateSessionStreamConformanceTestsOptions

The adapter's stores, and what it can make readable when.

Returns​

void


createTraceStoreConformanceTests()​

function createTraceStoreConformanceTests(options): void;

Register the shared TraceStore conformance cases against a backend. Call inside a test file's top-level scope; the helper opens its own describe block so multiple suites can coexist.

Parameters​

options​

CreateTraceStoreConformanceTestsOptions

Returns​

void


createWakeStoreConformanceTests()​

function createWakeStoreConformanceTests(options): void;

Register the wake-store conformance cases against a backend. Call inside a test file's top-level scope.

Parameters​

options​

CreateWakeStoreConformanceTestsOptions

Returns​

void


gateNextStateRead()​

function gateNextStateRead(store): StateReadGate;

Park the next get on store until the returned gate is released.

Only the next read is gated; every later read passes through, so a route that reads more than once is not deadlocked. The store method is replaced in place, which suits a store built fresh per test — there is no restore.

whenRead waits for the read and throws if it does not arrive. An earlier version raced two event-loop turns and disarmed the gate when the timers won, which silently turned a slow read into an ungated one: the route then ran to completion while the test believed it was parked, so a race test could pass without ever staging its race. A gate that cannot prove it held the route has to fail rather than guess.

Parameters​

store​

ResourceStateStore

Returns​

StateReadGate


makeRequestCompletedEvent()​

function makeRequestCompletedEvent(requestId, sequenceNumber): RequestStreamEvent;

Build a terminal request.completed event.

Parameters​

requestId​

string

sequenceNumber​

number

Returns​

RequestStreamEvent


makeRequestStreamEvent()​

function makeRequestStreamEvent(requestId, sequenceNumber): RequestStreamEvent;

Build an item.added RequestStreamEvent with the given sequence number. Tests want a single valid shape they can stamp; this is it.

Parameters​

requestId​

string

sequenceNumber​

number

Returns​

RequestStreamEvent


makeTraceEvent()​

function makeTraceEvent(
requestId,
sequenceNumber,
options?
): TraceEvent;

Build a TraceEvent whose inner item is a fully-typed BlockTraceItem. Tests want one valid shape they can stamp with sequence numbers; this is it. ts defaults to a stable function of sequenceNumber so test logs don't churn between runs.

Parameters​

requestId​

string

sequenceNumber​

number

options?​

MakeTraceEventOptions

Returns​

TraceEvent