@orkestrel/test 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -38
- package/dist/src/browser/index.d.ts +74 -37
- package/dist/src/browser/index.js +12 -22
- package/dist/src/browser/index.js.map +1 -1
- package/dist/src/core/index.cjs +63 -3
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +83 -7
- package/dist/src/core/index.d.ts +83 -7
- package/dist/src/core/index.js +63 -3
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +185 -4
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +194 -11
- package/dist/src/server/index.d.ts +194 -11
- package/dist/src/server/index.js +185 -4
- package/dist/src/server/index.js.map +1 -1
- package/package.json +5 -6
package/dist/src/core/index.cjs
CHANGED
|
@@ -66,6 +66,18 @@ var STATECHART_STATUSES = Object.freeze([
|
|
|
66
66
|
* wiring each recorder to exactly the event where it stores that recorder. A direct caller must
|
|
67
67
|
* establish the same pairing before it relies on the narrowing. This guard takes the listed events
|
|
68
68
|
* through a reference parameter rather than using the canonical single-value guard form.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { createRecorder, isRecorderMapComplete } from '@orkestrel/test'
|
|
73
|
+
*
|
|
74
|
+
* type ReadyEvents = { readonly ready: readonly [name: string, step: number] }
|
|
75
|
+
*
|
|
76
|
+
* const value: unknown = { ready: createRecorder<readonly [name: string, step: number]>() }
|
|
77
|
+
*
|
|
78
|
+
* isRecorderMapComplete<ReadyEvents, 'ready'>(value, ['ready']) // true
|
|
79
|
+
* isRecorderMapComplete<ReadyEvents, 'ready'>({ ready: 1 }, ['ready']) // false
|
|
80
|
+
* ```
|
|
69
81
|
*/
|
|
70
82
|
function isRecorderMapComplete(value, events) {
|
|
71
83
|
try {
|
|
@@ -92,6 +104,16 @@ function isRecorderMapComplete(value, events) {
|
|
|
92
104
|
* `<subject> interval must be finite and non-negative`.
|
|
93
105
|
* @remarks Every member of the wait family resolves its own defaults first and passes the resolved
|
|
94
106
|
* numbers here, so each keeps its own defaults while one contract states what a bound must be.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { checkBounds } from '@orkestrel/test'
|
|
111
|
+
*
|
|
112
|
+
* checkBounds('Wait', 1000, 10) // undefined
|
|
113
|
+
*
|
|
114
|
+
* // Throws Error: Retry budget must be finite and non-negative
|
|
115
|
+
* checkBounds('Retry', -1, 10)
|
|
116
|
+
* ```
|
|
95
117
|
*/
|
|
96
118
|
function checkBounds(subject, budget, interval) {
|
|
97
119
|
if (!Number.isFinite(budget) || budget < 0) throw new Error(`${subject} budget must be finite and non-negative`);
|
|
@@ -108,6 +130,16 @@ function checkBounds(subject, budget, interval) {
|
|
|
108
130
|
* @returns The exhaustion error, unthrown.
|
|
109
131
|
* @remarks Both of `retryUntil`'s elapsed checks raise this one message, so an edit to it lands in
|
|
110
132
|
* one place. The rendered value is appended only when the retry produced one.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* import { buildRetryExhausted } from '@orkestrel/test'
|
|
137
|
+
*
|
|
138
|
+
* const exhausted = buildRetryExhausted('registry answers', 30, 31, '"starting"', undefined)
|
|
139
|
+
*
|
|
140
|
+
* exhausted.message
|
|
141
|
+
* // 'Retry "registry answers" did not succeed within 30ms (waited 31ms) (last value: "starting")'
|
|
142
|
+
* ```
|
|
111
143
|
*/
|
|
112
144
|
function buildRetryExhausted(description, budget, elapsed, last, cause) {
|
|
113
145
|
return new Error(`Retry "${description}" did not succeed within ${budget}ms (waited ${elapsed}ms)${last === void 0 ? "" : ` (last value: ${last})`}`, { cause });
|
|
@@ -121,6 +153,21 @@ function buildRetryExhausted(description, budget, elapsed, last, cause) {
|
|
|
121
153
|
* @remarks The dropped registration's cleanup controller is aborted as it leaves, so the scope
|
|
122
154
|
* subscription installed beside it leaves with it. Removing the installed listener from the signal
|
|
123
155
|
* stays with the caller, because only the scope-abort path has one to remove.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import type { SignalRegistration } from '@orkestrel/test'
|
|
160
|
+
* import { dropRegistration } from '@orkestrel/test'
|
|
161
|
+
*
|
|
162
|
+
* const listener: EventListener = () => undefined
|
|
163
|
+
* const installed: EventListenerObject = { handleEvent: () => undefined }
|
|
164
|
+
* const cleanup = new AbortController()
|
|
165
|
+
* const registrations: SignalRegistration[] = [[listener, installed, true, cleanup]]
|
|
166
|
+
*
|
|
167
|
+
* dropRegistration(registrations, installed)?.[1] === installed // true
|
|
168
|
+
* cleanup.signal.aborted // true
|
|
169
|
+
* dropRegistration(registrations, installed) // undefined
|
|
170
|
+
* ```
|
|
124
171
|
*/
|
|
125
172
|
function dropRegistration(registrations, installed) {
|
|
126
173
|
const index = registrations.findIndex((registration) => registration[1] === installed);
|
|
@@ -133,7 +180,7 @@ function dropRegistration(registrations, installed) {
|
|
|
133
180
|
/**
|
|
134
181
|
* Waits for a host timer to elapse.
|
|
135
182
|
*
|
|
136
|
-
* @param ms - The delay in milliseconds.
|
|
183
|
+
* @param ms - The delay in milliseconds. Default: `0`.
|
|
137
184
|
* @returns A promise that resolves after the timer fires.
|
|
138
185
|
*/
|
|
139
186
|
function waitForDelay(ms = 0) {
|
|
@@ -339,6 +386,18 @@ async function waitForEvent(subscribe, description, options) {
|
|
|
339
386
|
* @returns The decoded values in physical-line order.
|
|
340
387
|
* @throws An `Error` naming the malformed physical line, with the native `SyntaxError` as its
|
|
341
388
|
* `cause`.
|
|
389
|
+
* @remarks An empty line contributes no value, and a trailing carriage return is dropped before the
|
|
390
|
+
* line is parsed, so text written with either line ending decodes the same.
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```ts
|
|
394
|
+
* import { decodeJSONLines } from '@orkestrel/test'
|
|
395
|
+
*
|
|
396
|
+
* decodeJSONLines('{"ready":true}\n7\n') // [{ ready: true }, 7]
|
|
397
|
+
*
|
|
398
|
+
* // Throws Error: Invalid JSON on line 3
|
|
399
|
+
* decodeJSONLines('{}\n\n{')
|
|
400
|
+
* ```
|
|
342
401
|
*/
|
|
343
402
|
function decodeJSONLines(text) {
|
|
344
403
|
const values = [];
|
|
@@ -368,12 +427,13 @@ function captureError(thunk) {
|
|
|
368
427
|
}
|
|
369
428
|
}
|
|
370
429
|
/**
|
|
371
|
-
*
|
|
430
|
+
* Narrows a value away from `null` and `undefined`, throwing when it is absent.
|
|
372
431
|
*
|
|
373
432
|
* @typeParam T - The required value type.
|
|
374
433
|
* @param value - The value to check.
|
|
375
|
-
* @param message - The error message used when the value is absent.
|
|
434
|
+
* @param message - The error message used when the value is absent. Default: `'Value is required'`.
|
|
376
435
|
* @returns The present value.
|
|
436
|
+
* @throws An `Error` carrying `message` when the value is `null` or `undefined`.
|
|
377
437
|
*/
|
|
378
438
|
function requireValue(value, message = "Value is required") {
|
|
379
439
|
if (value === null || value === void 0) throw new Error(message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/core/constants.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/factories.ts"],"sourcesContent":["/**\n * Names the attributes a statechart harness publishes, keyed by the fact each one carries.\n *\n * @remarks\n * A harness renders its own table and a gate outside the page polls the rendered markup, so these\n * names are the whole contract between the two. `status`, `passed`, `failed`, and `total` belong on\n * the harness root, because a gate finds the harness by `status` and reads the tally from the same\n * element. `scenario` and `result` belong on each row, so a failing row is found by `result` and\n * named by `scenario`. `state` belongs on the element rendering the entity's current state.\n *\n * The values are the attribute names themselves, so a harness writes `setAttribute` against this map\n * and a gate writes `querySelector` against it, and neither spells a `data-statechart-*` string of\n * its own.\n *\n * @example\n * ```ts\n * harness.getAttribute(STATECHART_ATTRIBUTES.status) // 'passed'\n * ```\n */\nexport const STATECHART_ATTRIBUTES = Object.freeze({\n\tstatus: 'data-statechart-status',\n\tpassed: 'data-statechart-passed',\n\tfailed: 'data-statechart-failed',\n\ttotal: 'data-statechart-total',\n\tscenario: 'data-statechart-scenario',\n\tresult: 'data-statechart-result',\n\tstate: 'data-statechart-state',\n})\n\n/**\n * Lists every value a statechart harness reports through its `status` attribute.\n *\n * @remarks\n * `pending` is what a harness carries before a run has produced a result for every row, `idle` is a\n * harness standing ready with nothing running, and `running` is a run in flight. `passed` and\n * `failed` are the two terminal readings, so a gate waits for membership in that pair rather than\n * for a fixed duration.\n *\n * The tuple's order is the order a run passes through, and its element type is the literal union, so\n * `(typeof STATECHART_STATUSES)[number]` is the status type a harness and its gate share.\n *\n * @example\n * ```ts\n * const terminal = new Set<string>([STATECHART_STATUSES[3], STATECHART_STATUSES[4]])\n * ```\n */\nexport const STATECHART_STATUSES = Object.freeze([\n\t'pending',\n\t'idle',\n\t'running',\n\t'passed',\n\t'failed',\n] as const)\n","import type { RecorderMap } from './types.js'\n\n/**\n * Checks whether a value contains a recorder for every listed event.\n *\n * @typeParam TMap - The source's event names and delivered argument tuples.\n * @typeParam TName - The event names represented in the map.\n * @param value - The value to inspect.\n * @param events - The events the completed map must contain.\n * @returns True if every listed event has a structurally valid recorder; false otherwise.\n * @remarks Per-key tuple precision is the predicate's claim. The factory proves that claim by\n * wiring each recorder to exactly the event where it stores that recorder. A direct caller must\n * establish the same pairing before it relies on the narrowing. This guard takes the listed events\n * through a reference parameter rather than using the canonical single-value guard form.\n */\nexport function isRecorderMapComplete<\n\tTMap extends Record<string, readonly unknown[]>,\n\tTName extends keyof TMap,\n>(value: unknown, events: readonly TName[]): value is RecorderMap<TMap, TName> {\n\ttry {\n\t\tif (typeof value !== 'object' || value === null) return false\n\t\treturn events.every((event) => {\n\t\t\tif (!Object.hasOwn(value, event)) return false\n\t\t\tconst recorder = Reflect.get(value, event)\n\t\t\tif (typeof recorder !== 'object' || recorder === null) return false\n\t\t\treturn (\n\t\t\t\ttypeof Reflect.get(recorder, 'handler') === 'function' &&\n\t\t\t\tArray.isArray(Reflect.get(recorder, 'calls'))\n\t\t\t)\n\t\t})\n\t} catch {\n\t\treturn false\n\t}\n}\n","import type {\n\tEventSubscriber,\n\tHeadersSource,\n\tJSONSafe,\n\tResult,\n\tRetryOptions,\n\tSignalRegistration,\n\tStateScenario,\n\tWaitOptions,\n} from './types.js'\n\n/**\n * Checks the resolved bounds one bounded wait runs under.\n *\n * @param subject - The bound's owner, which opens each refusal message.\n * @param budget - The resolved elapsed-time limit in milliseconds.\n * @param interval - The resolved delay between readings in milliseconds.\n * @throws An `Error` reading `<subject> budget must be finite and non-negative` or\n * `<subject> interval must be finite and non-negative`.\n * @remarks Every member of the wait family resolves its own defaults first and passes the resolved\n * numbers here, so each keeps its own defaults while one contract states what a bound must be.\n */\nexport function checkBounds(subject: string, budget: number, interval: number): void {\n\tif (!Number.isFinite(budget) || budget < 0) {\n\t\tthrow new Error(`${subject} budget must be finite and non-negative`)\n\t}\n\tif (!Number.isFinite(interval) || interval < 0) {\n\t\tthrow new Error(`${subject} interval must be finite and non-negative`)\n\t}\n}\n\n/**\n * Builds the error {@link retryUntil} raises when its elapsed-time budget runs out.\n *\n * @param description - The operation the retry was named for.\n * @param budget - The elapsed-time limit in milliseconds.\n * @param elapsed - The milliseconds the retry actually spent.\n * @param last - The rendered last unsatisfying value, or `undefined` when the retry produced none.\n * @param cause - The last producer error, which becomes the returned error's `cause`.\n * @returns The exhaustion error, unthrown.\n * @remarks Both of `retryUntil`'s elapsed checks raise this one message, so an edit to it lands in\n * one place. The rendered value is appended only when the retry produced one.\n */\nexport function buildRetryExhausted(\n\tdescription: string,\n\tbudget: number,\n\telapsed: number,\n\tlast: string | undefined,\n\tcause: unknown,\n): Error {\n\treturn new Error(\n\t\t`Retry \"${description}\" did not succeed within ${budget}ms (waited ${elapsed}ms)${last === undefined ? '' : ` (last value: ${last})`}`,\n\t\t{ cause },\n\t)\n}\n\n/**\n * Drops the registration an instrumented signal installed for one listener.\n *\n * @param registrations - The live registration list, spliced in place.\n * @param installed - The installed listener naming the registration to drop.\n * @returns The dropped registration, or `undefined` when the list holds none for that listener.\n * @remarks The dropped registration's cleanup controller is aborted as it leaves, so the scope\n * subscription installed beside it leaves with it. Removing the installed listener from the signal\n * stays with the caller, because only the scope-abort path has one to remove.\n */\nexport function dropRegistration(\n\tregistrations: SignalRegistration[],\n\tinstalled: EventListener | EventListenerObject,\n): SignalRegistration | undefined {\n\tconst index = registrations.findIndex((registration) => registration[1] === installed)\n\tconst registration = registrations[index]\n\tif (registration === undefined) return undefined\n\tregistrations.splice(index, 1)\n\tregistration[3]?.abort()\n\treturn registration\n}\n\n/**\n * Waits for a host timer to elapse.\n *\n * @param ms - The delay in milliseconds.\n * @returns A promise that resolves after the timer fires.\n */\nexport function waitForDelay(ms = 0): Promise<void> {\n\treturn new Promise((resolve) => setTimeout(resolve, ms))\n}\n\n/**\n * Waits until an abort signal is aborted.\n *\n * @param signal - The signal to observe.\n * @returns A promise that resolves when the signal is aborted.\n * @remarks An already-aborted signal resolves immediately. Otherwise the wait parks on a one-shot\n * abort listener without a timer or polling.\n */\nexport function waitForAbort(signal: AbortSignal): Promise<void> {\n\tif (signal.aborted) return Promise.resolve()\n\treturn new Promise((resolve) => signal.addEventListener('abort', () => resolve(), { once: true }))\n}\n\n/**\n * Waits until a condition holds within an elapsed-time budget.\n *\n * @param description - The condition described in a timeout error.\n * @param condition - The synchronous or asynchronous condition to read.\n * @param options - The time bounds and abort signal.\n * @returns A promise that resolves when the condition first returns `true`.\n * @throws The condition's thrown value, the abort reason, or an `Error` when a bound is invalid or\n * the condition does not hold within the budget.\n * @remarks The first read is immediate. Default budget: `1000` milliseconds. Default interval: `10`\n * milliseconds.\n */\nexport async function waitForCondition(\n\tdescription: string,\n\tcondition: () => boolean | Promise<boolean>,\n\toptions?: WaitOptions,\n): Promise<void> {\n\tconst budget = options?.budget ?? 1000\n\tconst interval = options?.interval ?? 10\n\tcheckBounds('Wait', budget, interval)\n\n\tconst start = performance.now()\n\twhile (true) {\n\t\toptions?.signal?.throwIfAborted()\n\t\tconst held = await condition()\n\t\toptions?.signal?.throwIfAborted()\n\t\tif (held) return\n\n\t\tconst elapsed = performance.now() - start\n\t\tif (elapsed >= budget) {\n\t\t\tthrow new Error(\n\t\t\t\t`Condition \"${description}\" did not hold within ${budget}ms (waited ${elapsed}ms)`,\n\t\t\t)\n\t\t}\n\t\tawait waitForDelay(interval)\n\t}\n}\n\n/**\n * Repeats a producer until one produced value satisfies a predicate.\n *\n * @typeParam T - The produced value type.\n * @param description - The operation described in an exhaustion error.\n * @param produce - The synchronous or asynchronous operation to repeat.\n * @param satisfied - The predicate that accepts a produced value.\n * @param options - The time, attempt, and abort bounds.\n * @returns The first produced value the predicate accepts.\n * @throws The predicate's thrown value, the abort reason, or an `Error` when a bound is invalid or\n * the retry exhausts its budget or attempts.\n * @remarks A producer throw counts as an unsatisfied attempt. The last producer error becomes the\n * exhaustion error's `cause`. Default budget: `1000` milliseconds. Default interval: `10`\n * milliseconds.\n */\nexport async function retryUntil<T>(\n\tdescription: string,\n\tproduce: () => T | Promise<T>,\n\tsatisfied: (value: T) => boolean,\n\toptions?: RetryOptions,\n): Promise<T> {\n\tconst budget = options?.budget ?? 1000\n\tconst interval = options?.interval ?? 10\n\tconst attempts = options?.attempts\n\tcheckBounds('Retry', budget, interval)\n\tif (attempts !== undefined && (!Number.isInteger(attempts) || attempts < 1)) {\n\t\tthrow new Error('Retry attempts must be a positive integer')\n\t}\n\n\tconst start = performance.now()\n\tlet count = 0\n\tlet cause: unknown\n\tlet last: string | undefined\n\twhile (true) {\n\t\toptions?.signal?.throwIfAborted()\n\t\tif (count > 0) {\n\t\t\tconst elapsed = performance.now() - start\n\t\t\tif (elapsed >= budget) {\n\t\t\t\tthrow buildRetryExhausted(description, budget, elapsed, last, cause)\n\t\t\t}\n\t\t}\n\t\tlet produced: Result<T, unknown>\n\t\ttry {\n\t\t\tproduced = { success: true, value: await produce() }\n\t\t} catch (error) {\n\t\t\tproduced = { success: false, error }\n\t\t}\n\t\tcount += 1\n\t\toptions?.signal?.throwIfAborted()\n\n\t\tif (produced.success) {\n\t\t\tif (satisfied(produced.value)) return produced.value\n\t\t\tlet rendered: string\n\t\t\ttry {\n\t\t\t\tconst serialized = JSON.stringify(produced.value)\n\t\t\t\trendered = serialized === undefined ? String(produced.value) : serialized\n\t\t\t} catch {\n\t\t\t\ttry {\n\t\t\t\t\trendered = String(produced.value)\n\t\t\t\t} catch {\n\t\t\t\t\trendered = '[unrenderable]'\n\t\t\t\t}\n\t\t\t}\n\t\t\tlast = rendered.length > 200 ? `${rendered.slice(0, 197)}...` : rendered\n\t\t} else {\n\t\t\tcause = produced.error\n\t\t}\n\n\t\tconst elapsed = performance.now() - start\n\t\tif (elapsed >= budget) {\n\t\t\tthrow buildRetryExhausted(description, budget, elapsed, last, cause)\n\t\t}\n\t\tif (attempts !== undefined && count >= attempts) {\n\t\t\tthrow new Error(\n\t\t\t\t`Retry \"${description}\" did not succeed within ${attempts} attempts${last === undefined ? '' : ` (last value: ${last})`}`,\n\t\t\t\t{ cause },\n\t\t\t)\n\t\t}\n\t\tawait waitForDelay(Math.min(interval, budget - elapsed))\n\t}\n}\n\n/**\n * Invokes an unknown method through an explicit unchecked result contract.\n *\n * @typeParam T - The result type claimed by the caller.\n * @param target - The value used as the method's `this` argument.\n * @param method - The unknown method to invoke.\n * @param args - The arguments to pass.\n * @returns The method's result under the caller's claimed type.\n * @throws A `TypeError` when `method` is not callable.\n * @remarks The caller owns the claim that the returned value has type `T`. The contained `any`\n * bridges the unchecked runtime result to that caller-owned claim.\n */\nexport function invokeUnchecked<T>(target: unknown, method: unknown, args: readonly unknown[]): T {\n\tif (typeof method !== 'function') throw new TypeError('Method must be callable')\n\tconst result: T = Reflect.apply(method, target, args)\n\treturn result\n}\n\n/**\n * Reads a property from an unknown object or function.\n *\n * @typeParam T - The property type claimed by the caller.\n * @param target - The unknown value to read.\n * @param key - The property key to read.\n * @returns The property value under the caller's claimed type.\n * @throws A `TypeError` when `target` is neither an object nor a function.\n * @remarks The caller owns the claim that the returned value has type `T`. The contained `any`\n * bridges the unchecked runtime result to that caller-owned claim.\n */\nexport function readProperty<T>(target: unknown, key: PropertyKey): T {\n\tif ((typeof target !== 'object' || target === null) && typeof target !== 'function') {\n\t\tthrow new TypeError('Target must be an object or function')\n\t}\n\tconst result: T = Reflect.get(target, key)\n\treturn result\n}\n\n/**\n * Normalizes headers into a frozen plain record.\n *\n * @param init - The platform header initializer to normalize.\n * @returns A frozen record of normalized header names and values.\n * @remarks Normalization follows the host `Headers` implementation, including lowercased names and\n * combined values.\n */\nexport function flattenHeaders(init: HeadersSource): Readonly<Record<string, string>> {\n\treturn Object.freeze(Object.fromEntries(new Headers(init).entries()))\n}\n\n/**\n * Waits for the first delivery from an event subscription.\n *\n * @typeParam TArgs - The delivered argument tuple.\n * @param subscribe - The function that installs the event listener and may return its cleanup.\n * @param description - The event described in a timeout error.\n * @param options - The time bounds and abort signal.\n * @returns The first delivered argument tuple.\n * @throws The subscription's thrown value, the abort reason, or an `Error` when a bound is invalid\n * or the event is not delivered within the budget.\n * @remarks Default budget: `1000` milliseconds. The interval is validated for consistency with the\n * wait family but is not used because this helper parks on the event.\n */\nexport async function waitForEvent<TArgs extends readonly unknown[]>(\n\tsubscribe: EventSubscriber<TArgs>,\n\tdescription: string,\n\toptions?: WaitOptions,\n): Promise<TArgs> {\n\tconst budget = options?.budget ?? 1000\n\tconst interval = options?.interval ?? 10\n\tcheckBounds('Event', budget, interval)\n\n\tconst signal = options?.signal\n\tsignal?.throwIfAborted()\n\tconst delivery = Promise.withResolvers<TArgs>()\n\tconst controller = new AbortController()\n\tlet timeout: ReturnType<typeof setTimeout> | undefined\n\tconst pending: Array<Promise<TArgs>> = [\n\t\tdelivery.promise,\n\t\tnew Promise((_resolve, reject) => {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\treject(new Error(`Event \"${description}\" was not delivered within ${budget}ms`))\n\t\t\t}, budget)\n\t\t}),\n\t]\n\tif (signal !== undefined) {\n\t\tpending.push(\n\t\t\tnew Promise((_resolve, reject) => {\n\t\t\t\tconst combined = AbortSignal.any([signal, controller.signal])\n\t\t\t\tcombined.addEventListener(\n\t\t\t\t\t'abort',\n\t\t\t\t\t() => {\n\t\t\t\t\t\tif (signal.aborted) reject(signal.reason)\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true },\n\t\t\t\t)\n\t\t\t}),\n\t\t)\n\t}\n\tconst result = Promise.race(pending)\n\tlet cleanup: (() => void) | void = undefined\n\ttry {\n\t\ttry {\n\t\t\tcleanup = subscribe((...args) => delivery.resolve(args))\n\t\t} catch (error) {\n\t\t\tdelivery.reject(error)\n\t\t}\n\t\treturn await result\n\t} finally {\n\t\tcontroller.abort()\n\t\tif (timeout !== undefined) clearTimeout(timeout)\n\t\tcleanup?.()\n\t}\n}\n\n/**\n * Decodes newline-delimited JSON values.\n *\n * @param text - The JSON Lines text to decode.\n * @returns The decoded values in physical-line order.\n * @throws An `Error` naming the malformed physical line, with the native `SyntaxError` as its\n * `cause`.\n */\nexport function decodeJSONLines(text: string): readonly unknown[] {\n\tconst values: unknown[] = []\n\tfor (const [index, physical] of text.split('\\n').entries()) {\n\t\tconst line = physical.endsWith('\\r') ? physical.slice(0, -1) : physical\n\t\tif (line.length === 0) continue\n\t\ttry {\n\t\t\tconst value: unknown = JSON.parse(line)\n\t\t\tvalues.push(value)\n\t\t} catch (cause) {\n\t\t\tthrow new Error(`Invalid JSON on line ${index + 1}`, { cause })\n\t\t}\n\t}\n\treturn values\n}\n\n/**\n * Captures the value thrown by a thunk.\n *\n * @param thunk - The work whose thrown value to capture.\n * @returns The thrown value, or `undefined` when the thunk completes.\n */\nexport function captureError(thunk: () => unknown): unknown {\n\ttry {\n\t\tthunk()\n\t} catch (error) {\n\t\treturn error\n\t}\n\treturn undefined\n}\n\n/**\n * Requires a value to be present.\n *\n * @typeParam T - The required value type.\n * @param value - The value to check.\n * @param message - The error message used when the value is absent.\n * @returns The present value.\n */\nexport function requireValue<T>(value: T | null | undefined, message = 'Value is required'): T {\n\tif (value === null || value === undefined) throw new Error(message)\n\treturn value\n}\n\n/**\n * Collects every value from an async iterable.\n *\n * @typeParam T - The yielded value type.\n * @param source - The async iterable to drain.\n * @returns The yielded values in iteration order.\n */\nexport async function collect<T>(source: AsyncIterable<T>): Promise<readonly T[]> {\n\tconst values: T[] = []\n\tfor await (const value of source) values.push(value)\n\treturn values\n}\n\n/**\n * Collects every value from a readable stream.\n *\n * @typeParam T - The streamed value type.\n * @param stream - The readable stream to drain.\n * @returns The streamed values in read order.\n */\nexport async function collectStream<T>(stream: ReadableStream<T>): Promise<readonly T[]> {\n\tconst reader = stream.getReader()\n\tconst values: T[] = []\n\ttry {\n\t\twhile (true) {\n\t\t\tconst result = await reader.read()\n\t\t\tif (result.done) return values\n\t\t\tvalues.push(result.value)\n\t\t}\n\t} finally {\n\t\treader.releaseLock()\n\t}\n}\n\n/**\n * Copies a JSON value through serialization and parsing.\n *\n * @typeParam T - The copied value's type, which the copy keeps.\n * @param value - The value to copy, bounded by its own `JSONSafe` projection.\n * @returns The parsed JSON copy.\n * @remarks Non-finite numbers throw because JSON would replace them with `null`. Negative zero is\n * normalized to zero by JSON serialization. The bound intersects `JSONSafe<T>` rather than\n * constraining `T` to `JSONValue`, so an interface-typed value round-trips.\n */\nexport function roundTripJSON<T>(value: T & JSONSafe<T>): T {\n\tconst serialized = JSON.stringify(value, (_key, current) => {\n\t\tif (current === undefined || typeof current === 'function' || typeof current === 'symbol') {\n\t\t\tthrow new Error('JSON values must not contain undefined, functions, or symbols')\n\t\t}\n\t\tif (typeof current === 'number' && !Number.isFinite(current)) {\n\t\t\tthrow new Error('JSON values must contain finite numbers')\n\t\t}\n\t\treturn current\n\t})\n\tconst parsed: T = JSON.parse(serialized)\n\tconst pending: unknown[] = [parsed]\n\twhile (pending.length > 0) {\n\t\tconst current = pending.pop()\n\t\tif (typeof current === 'number' && !Number.isFinite(current)) {\n\t\t\tthrow new Error('JSON values must contain finite numbers')\n\t\t}\n\t\tif (Array.isArray(current)) {\n\t\t\tfor (const child of current) pending.push(child)\n\t\t} else if (typeof current === 'object' && current !== null) {\n\t\t\tfor (const child of Object.values(current)) pending.push(child)\n\t\t}\n\t}\n\treturn parsed\n}\n\n/**\n * Resolves the parent directory of a calling module, which is the workspace root when called from\n * the conventional `tests/setup.ts` location.\n *\n * @param meta - The calling module metadata.\n * @returns The root URL one directory above the calling file.\n */\nexport function resolveRoot(meta: ImportMeta): URL {\n\treturn new URL('../', meta.url)\n}\n\n/**\n * Drives one statechart scenario through its arrange, act, and assert phases.\n *\n * @typeParam TState - The states the entity moves between.\n * @typeParam TEvent - The events the entity accepts.\n * @typeParam TContext - The fixture the phases drive.\n * @param scenario - The scenario to drive.\n * @param context - The fixture handed to each phase.\n * @returns A promise that resolves after the assert phase completes.\n * @throws An `Error` whose message opens with the transition's `name` and whose `cause` is the value\n * the failing phase threw.\n * @remarks Each phase is awaited before the next begins, so an asynchronous arrange settles before\n * the event is applied. The phases receive the transition's own parts: `arrange` receives `from`,\n * `act` receives `event`, and `assert` receives `to`.\n *\n * The row's name is prepended because a table's rows run under one test name, so a bare assertion\n * message says what failed and never which row. A thrown `Error` keeps its own message after the\n * name and arrives as the `cause`; anything else thrown is named by its type and arrives as the\n * `cause` unchanged.\n *\n * @example\n * ```ts\n * await executeScenario(scenarios[0], { disclosure: new Disclosure() })\n * ```\n */\nexport async function executeScenario<TState extends string, TEvent extends string, TContext>(\n\tscenario: StateScenario<TState, TEvent, TContext>,\n\tcontext: TContext,\n): Promise<void> {\n\tconst transition = scenario.transition\n\ttry {\n\t\tawait scenario.arrange(context, transition.from)\n\t\tawait scenario.act(context, transition.event)\n\t\tawait scenario.assert(context, transition.to)\n\t} catch (cause) {\n\t\tconst message =\n\t\t\tcause instanceof Error ? cause.message : `threw a non-error ${typeof cause} value`\n\t\tthrow new Error(`${transition.name}: ${message}`, { cause })\n\t}\n}\n\n/**\n * Drives a statechart table row by row, each row against a context of its own.\n *\n * @typeParam TState - The states the entity moves between.\n * @typeParam TEvent - The events the entity accepts.\n * @typeParam TContext - The fixture the phases drive.\n * @param scenarios - The table to drive, in the order it is written.\n * @param build - The fixture builder, called once per row and awaited when it returns a promise.\n * @returns A promise that resolves after the last row completes.\n * @throws An `Error` reading `<name>: build refused` when the row's builder throws or rejects, whose\n * `cause` is the value the builder refused with, or whatever {@link executeScenario} throws for the\n * first row whose phases fail. Either way the run stops at that row and the rows after it never\n * start.\n * @remarks The rows run one after another rather than together: a statechart's rows drive one\n * entity on one page, so a parallel run would have them arranging over each other. `build` receives\n * the row it is building for, which is what lets one table mix fixtures.\n *\n * A refusing builder is named for its row the way a failing phase is, because a table's rows build\n * under one test name too. The refusal itself arrives as the `cause`, by identity, so its own\n * message and stack survive the naming.\n *\n * @example\n * ```ts\n * await executeScenarios(SCENARIOS, () => ({ disclosure: new Disclosure() }))\n * ```\n */\nexport async function executeScenarios<TState extends string, TEvent extends string, TContext>(\n\tscenarios: ReadonlyArray<StateScenario<TState, TEvent, TContext>>,\n\tbuild: (scenario: StateScenario<TState, TEvent, TContext>) => TContext | Promise<TContext>,\n): Promise<void> {\n\tfor (const scenario of scenarios) {\n\t\tlet context: TContext\n\t\ttry {\n\t\t\tcontext = await build(scenario)\n\t\t} catch (cause) {\n\t\t\tthrow new Error(`${scenario.transition.name}: build refused`, { cause })\n\t\t}\n\t\tawait executeScenario(scenario, context)\n\t}\n}\n","import type {\n\tEventSourceInterface,\n\tRecorderInterface,\n\tRecorderMap,\n\tResourceFactoryInterface,\n\tSignalInterface,\n\tSignalRegistration,\n\tTeardownHandler,\n\tTeardownInterface,\n} from './types.js'\nimport { dropRegistration } from './helpers.js'\nimport { isRecorderMapComplete } from './validators.js'\n\n/**\n * Creates values that make common object readers throw or violate their assumptions.\n *\n * @returns A frozen array whose values are fresh on every call.\n * @remarks Every member makes a naive read throw or violates a naive structural assumption. A total\n * guard survives every member without throwing. Whether it accepts or refuses one is that guard's\n * own contract. Membership may grow in a release, so test the whole returned set in a loop and\n * include the index in each failure.\n *\n * - The self-referential record makes JSON record serialization throw.\n * - The revoked object proxy makes reflective object access throw.\n * - The property proxy makes a named property read throw.\n * - The key proxy makes key enumeration throw.\n * - The prototype proxy makes a prototype read throw.\n * - The null-prototype record breaks a direct `hasOwnProperty` call.\n * - The array-target proxy passes an array check and makes an index read throw.\n * - The self-referential array makes JSON collection serialization throw.\n * - The sparse array violates the assumption that every index is enumerable.\n * - The hidden-key record violates the assumption that every own key is enumerable.\n * - The named getter makes its property read throw.\n * @example\n * ```ts\n * import { expect } from 'vitest'\n * import { createHostileValues } from '@orkestrel/test'\n *\n * function isWireRecord(value: unknown): value is Readonly<Record<string, string>> {\n * \tif (typeof value !== 'object' || value === null) return false\n * \ttry {\n * \t\tif (Object.getPrototypeOf(value) !== Object.prototype) return false\n * \t\tReflect.get(value, 'value')\n * \t\tif (Reflect.ownKeys(value).length === 0) return false\n * \t\treturn Object.values(value).every((member) => typeof member === 'string')\n * \t} catch {\n * \t\treturn false\n * \t}\n * }\n *\n * for (const [index, value] of createHostileValues().entries()) {\n * \tlet accepted: boolean | undefined\n * \texpect(() => {\n * \t\taccepted = isWireRecord(value)\n * \t}, `hostile value ${index}`).not.toThrow()\n * \texpect(accepted, `hostile value ${index}`).toBe(false)\n * }\n * ```\n */\nexport function createHostileValues(): readonly unknown[] {\n\tconst cyclic: Record<string, unknown> = {}\n\tcyclic.self = cyclic\n\tconst revoked = Proxy.revocable({}, {})\n\trevoked.revoke()\n\tconst cyclicArray: unknown[] = []\n\tcyclicArray.push(cyclicArray)\n\tconst sparseArray = Array<unknown>(2)\n\tsparseArray[1] = 'present'\n\tconst hidden = {}\n\tObject.defineProperty(hidden, 'hidden', { value: true })\n\tReflect.set(hidden, 'self', hidden)\n\tconst getter = {}\n\tObject.defineProperty(getter, 'danger', {\n\t\tenumerable: true,\n\t\tget() {\n\t\t\tthrow new Error('Hostile named getter read')\n\t\t},\n\t})\n\n\treturn Object.freeze([\n\t\tcyclic,\n\t\trevoked.proxy,\n\t\tnew Proxy(\n\t\t\t{},\n\t\t\t{\n\t\t\t\tget() {\n\t\t\t\t\tthrow new Error('Hostile property read')\n\t\t\t\t},\n\t\t\t},\n\t\t),\n\t\tnew Proxy(\n\t\t\t{},\n\t\t\t{\n\t\t\t\townKeys() {\n\t\t\t\t\tthrow new Error('Hostile key enumeration')\n\t\t\t\t},\n\t\t\t},\n\t\t),\n\t\tnew Proxy(\n\t\t\t{},\n\t\t\t{\n\t\t\t\tgetPrototypeOf() {\n\t\t\t\t\tthrow new Error('Hostile prototype read')\n\t\t\t\t},\n\t\t\t},\n\t\t),\n\t\tObject.create(null),\n\t\tnew Proxy([], {\n\t\t\tget() {\n\t\t\t\tthrow new Error('Hostile array index read')\n\t\t\t},\n\t\t}),\n\t\tcyclicArray,\n\t\tsparseArray,\n\t\thidden,\n\t\tgetter,\n\t])\n}\n\n/**\n * Creates a recorder for callback arguments.\n *\n * @typeParam TArgs - The argument tuple to record.\n * @returns A recorder whose handler appends calls in order.\n */\nexport function createRecorder<\n\tTArgs extends readonly unknown[] = readonly unknown[],\n>(): RecorderInterface<TArgs> {\n\tconst calls: TArgs[] = []\n\treturn {\n\t\tcalls,\n\t\tget count() {\n\t\t\treturn calls.length\n\t\t},\n\t\thandler(...args) {\n\t\t\tcalls.push(args)\n\t\t},\n\t\tclear() {\n\t\t\tcalls.length = 0\n\t\t},\n\t}\n}\n\n/**\n * Creates event recorders and subscribes them to the source.\n *\n * @typeParam TMap - The source's event names and delivered argument tuples.\n * @typeParam TName - The requested event names.\n * @param source - The source to subscribe to.\n * @param events - The events to record.\n * @returns A map from each requested event name to its recorder.\n * @throws Thrown when a listed event has no recorder, which a well-formed events array cannot\n * produce.\n * @remarks A duplicate event name installs a fresh recorder for every occurrence. The returned map\n * keeps the recorder installed for the last occurrence. `TName` derives from the array's element\n * type. An array declared with a wider union than its contents widens `TName` beyond the listed\n * events. The omitted key reads `undefined` at runtime under a non-optional type, and the guard\n * reports `true` because it checks the listed events. Pass a literal array or a tuple.\n */\nexport function createRecorders<\n\tTMap extends Record<string, readonly unknown[]>,\n\tTName extends keyof TMap,\n>(source: EventSourceInterface<TMap>, events: readonly TName[]): RecorderMap<TMap, TName> {\n\tconst building: { -readonly [K in TName]?: RecorderInterface<TMap[TName]> } = {}\n\tfor (const event of events) {\n\t\tconst recorder = createRecorder<TMap[TName]>()\n\t\tsource.on(event, recorder.handler)\n\t\tbuilding[event] = recorder\n\t}\n\tif (!isRecorderMapComplete<TMap, TName>(building, events)) {\n\t\tthrow new Error('Emitter recorder map is incomplete')\n\t}\n\treturn building\n}\n\n/**\n * Creates a real abort controller whose signal reports its live abort listeners.\n *\n * @returns The controller, its instrumented signal, and the current listener tally.\n * @remarks Instrumentation is installed on the created signal instance. A one-shot listener leaves\n * the tally when it fires, and removal accepts the original listener supplied by the caller. A\n * listener scoped by another signal leaves when that signal aborts. An already-aborted scope\n * installs and records nothing.\n */\nexport function createSignal(): SignalInterface {\n\tconst controller = new AbortController()\n\tconst signal = controller.signal\n\tconst add = signal.addEventListener.bind(signal)\n\tconst remove = signal.removeEventListener.bind(signal)\n\tconst registrations: SignalRegistration[] = []\n\n\tObject.defineProperty(signal, 'addEventListener', {\n\t\tconfigurable: true,\n\t\tvalue(\n\t\t\ttype: string,\n\t\t\tlistener: EventListener | EventListenerObject | null,\n\t\t\toptions?: boolean | AddEventListenerOptions,\n\t\t) {\n\t\t\tif (listener === null) return\n\t\t\tif (type !== 'abort') {\n\t\t\t\tadd(type, listener, options)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst capture = typeof options === 'boolean' ? options : (options?.capture ?? false)\n\t\t\tconst scope = typeof options === 'object' ? options?.signal : undefined\n\t\t\tif (scope?.aborted === true) return\n\t\t\tif (\n\t\t\t\tregistrations.some(\n\t\t\t\t\t(registration) => registration[0] === listener && registration[2] === capture,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst once = typeof options === 'object' && options?.once === true\n\t\t\tconst cleanup = scope === undefined ? undefined : new AbortController()\n\t\t\tconst installed: EventListenerObject = {\n\t\t\t\thandleEvent(event) {\n\t\t\t\t\tif (once) dropRegistration(registrations, installed)\n\t\t\t\t\tif (typeof listener === 'function') listener.call(signal, event)\n\t\t\t\t\telse listener.handleEvent(event)\n\t\t\t\t},\n\t\t\t}\n\t\t\tadd(\n\t\t\t\ttype,\n\t\t\t\tinstalled,\n\t\t\t\ttypeof options === 'object'\n\t\t\t\t\t? options?.passive === undefined\n\t\t\t\t\t\t? { capture, once }\n\t\t\t\t\t\t: { capture, once, passive: options.passive }\n\t\t\t\t\t: options,\n\t\t\t)\n\t\t\tregistrations.push([listener, installed, capture, cleanup])\n\t\t\tif (scope !== undefined && cleanup !== undefined) {\n\t\t\t\tscope.addEventListener(\n\t\t\t\t\t'abort',\n\t\t\t\t\t() => {\n\t\t\t\t\t\tconst registration = dropRegistration(registrations, installed)\n\t\t\t\t\t\tif (registration === undefined) return\n\t\t\t\t\t\tremove(type, registration[1], { capture })\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true, signal: cleanup.signal },\n\t\t\t\t)\n\t\t\t}\n\t\t},\n\t})\n\tObject.defineProperty(signal, 'removeEventListener', {\n\t\tconfigurable: true,\n\t\tvalue(\n\t\t\ttype: string,\n\t\t\tlistener: EventListener | EventListenerObject | null,\n\t\t\toptions?: boolean | EventListenerOptions,\n\t\t) {\n\t\t\tif (listener === null) return\n\t\t\tif (type !== 'abort') {\n\t\t\t\tremove(type, listener, options)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst capture = typeof options === 'boolean' ? options : (options?.capture ?? false)\n\t\t\tconst index = registrations.findIndex(\n\t\t\t\t(registration) => registration[0] === listener && registration[2] === capture,\n\t\t\t)\n\t\t\tconst registration = registrations[index]\n\t\t\tif (registration === undefined) {\n\t\t\t\tremove(type, listener, options)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tregistrations.splice(index, 1)\n\t\t\tregistration[3]?.abort()\n\t\t\tremove(type, registration[1], options)\n\t\t},\n\t})\n\n\treturn {\n\t\tcontroller,\n\t\tsignal,\n\t\tget count() {\n\t\t\treturn registrations.length\n\t\t},\n\t}\n}\n\n/**\n * Creates a monotonically numbered resource factory with creation and destruction records.\n *\n * @returns A resource factory whose recorders retain every affected id in order.\n */\nexport function createResourceFactory(): ResourceFactoryInterface {\n\tconst created = createRecorder<readonly [id: number]>()\n\tconst destroyed = createRecorder<readonly [id: number]>()\n\treturn {\n\t\tcreated,\n\t\tdestroyed,\n\t\tcreate() {\n\t\t\tconst id = created.calls.length + 1\n\t\t\tcreated.handler(id)\n\t\t\treturn id\n\t\t},\n\t\tdestroy(id) {\n\t\t\tdestroyed.handler(id)\n\t\t},\n\t}\n}\n\n/**\n * Creates a teardown list that runs registered handlers newest-first.\n *\n * @returns A teardown list that awaits every handler and collects failures.\n */\nexport function createTeardown(): TeardownInterface {\n\tlet handlers: TeardownHandler[] = []\n\treturn {\n\t\tget count() {\n\t\t\treturn handlers.length\n\t\t},\n\t\tadd(handler) {\n\t\t\thandlers.push(handler)\n\t\t},\n\t\tasync destroy() {\n\t\t\tconst snapshot = handlers\n\t\t\thandlers = []\n\t\t\tconst failures: unknown[] = []\n\t\t\tfor (const handler of snapshot.reverse()) {\n\t\t\t\ttry {\n\t\t\t\t\tawait handler()\n\t\t\t\t} catch (error) {\n\t\t\t\t\tfailures.push(error)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (failures.length === 1) throw failures[0]\n\t\t\tif (failures.length > 1) throw new AggregateError(failures)\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,IAAa,wBAAwB,OAAO,OAAO;CAClD,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,OAAO;CACP,UAAU;CACV,QAAQ;CACR,OAAO;AACR,CAAC;;;;;;;;;;;;;;;;;;AAmBD,IAAa,sBA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WAAW,CAAC;GACZ,MAAM,WAAsB,CAAC;GAC7B,KAAK,MAAM,WAAW,SAAS,QAAQ,GACtC,IAAI;IACH,MAAM,QAAQ;GACf,SAAS,OAAO;IACf,SAAS,KAAK,KAAK;GACpB;GAED,IAAI,SAAS,WAAW,GAAG,MAAM,SAAS;GAC1C,IAAI,SAAS,SAAS,GAAG,MAAM,IAAI,eAAe,QAAQ;EAC3D;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/core/constants.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/factories.ts"],"sourcesContent":["/**\n * Names the attributes a statechart harness publishes, keyed by the fact each one carries.\n *\n * @remarks\n * A harness renders its own table and a gate outside the page polls the rendered markup, so these\n * names are the whole contract between the two. `status`, `passed`, `failed`, and `total` belong on\n * the harness root, because a gate finds the harness by `status` and reads the tally from the same\n * element. `scenario` and `result` belong on each row, so a failing row is found by `result` and\n * named by `scenario`. `state` belongs on the element rendering the entity's current state.\n *\n * The values are the attribute names themselves, so a harness writes `setAttribute` against this map\n * and a gate writes `querySelector` against it, and neither spells a `data-statechart-*` string of\n * its own.\n *\n * @example\n * ```ts\n * harness.getAttribute(STATECHART_ATTRIBUTES.status) // 'passed'\n * ```\n */\nexport const STATECHART_ATTRIBUTES = Object.freeze({\n\tstatus: 'data-statechart-status',\n\tpassed: 'data-statechart-passed',\n\tfailed: 'data-statechart-failed',\n\ttotal: 'data-statechart-total',\n\tscenario: 'data-statechart-scenario',\n\tresult: 'data-statechart-result',\n\tstate: 'data-statechart-state',\n})\n\n/**\n * Lists every value a statechart harness reports through its `status` attribute.\n *\n * @remarks\n * `pending` is what a harness carries before a run has produced a result for every row, `idle` is a\n * harness standing ready with nothing running, and `running` is a run in flight. `passed` and\n * `failed` are the two terminal readings, so a gate waits for membership in that pair rather than\n * for a fixed duration.\n *\n * The tuple's order is the order a run passes through, and its element type is the literal union, so\n * `(typeof STATECHART_STATUSES)[number]` is the status type a harness and its gate share.\n *\n * @example\n * ```ts\n * const terminal = new Set<string>([STATECHART_STATUSES[3], STATECHART_STATUSES[4]])\n * ```\n */\nexport const STATECHART_STATUSES = Object.freeze([\n\t'pending',\n\t'idle',\n\t'running',\n\t'passed',\n\t'failed',\n] as const)\n","import type { RecorderMap } from './types.js'\n\n/**\n * Checks whether a value contains a recorder for every listed event.\n *\n * @typeParam TMap - The source's event names and delivered argument tuples.\n * @typeParam TName - The event names represented in the map.\n * @param value - The value to inspect.\n * @param events - The events the completed map must contain.\n * @returns True if every listed event has a structurally valid recorder; false otherwise.\n * @remarks Per-key tuple precision is the predicate's claim. The factory proves that claim by\n * wiring each recorder to exactly the event where it stores that recorder. A direct caller must\n * establish the same pairing before it relies on the narrowing. This guard takes the listed events\n * through a reference parameter rather than using the canonical single-value guard form.\n *\n * @example\n * ```ts\n * import { createRecorder, isRecorderMapComplete } from '@orkestrel/test'\n *\n * type ReadyEvents = { readonly ready: readonly [name: string, step: number] }\n *\n * const value: unknown = { ready: createRecorder<readonly [name: string, step: number]>() }\n *\n * isRecorderMapComplete<ReadyEvents, 'ready'>(value, ['ready']) // true\n * isRecorderMapComplete<ReadyEvents, 'ready'>({ ready: 1 }, ['ready']) // false\n * ```\n */\nexport function isRecorderMapComplete<\n\tTMap extends Record<string, readonly unknown[]>,\n\tTName extends keyof TMap,\n>(value: unknown, events: readonly TName[]): value is RecorderMap<TMap, TName> {\n\ttry {\n\t\tif (typeof value !== 'object' || value === null) return false\n\t\treturn events.every((event) => {\n\t\t\tif (!Object.hasOwn(value, event)) return false\n\t\t\tconst recorder = Reflect.get(value, event)\n\t\t\tif (typeof recorder !== 'object' || recorder === null) return false\n\t\t\treturn (\n\t\t\t\ttypeof Reflect.get(recorder, 'handler') === 'function' &&\n\t\t\t\tArray.isArray(Reflect.get(recorder, 'calls'))\n\t\t\t)\n\t\t})\n\t} catch {\n\t\treturn false\n\t}\n}\n","import type {\n\tEventSubscriber,\n\tHeadersSource,\n\tJSONSafe,\n\tResult,\n\tRetryOptions,\n\tSignalRegistration,\n\tStateScenario,\n\tWaitOptions,\n} from './types.js'\n\n/**\n * Checks the resolved bounds one bounded wait runs under.\n *\n * @param subject - The bound's owner, which opens each refusal message.\n * @param budget - The resolved elapsed-time limit in milliseconds.\n * @param interval - The resolved delay between readings in milliseconds.\n * @throws An `Error` reading `<subject> budget must be finite and non-negative` or\n * `<subject> interval must be finite and non-negative`.\n * @remarks Every member of the wait family resolves its own defaults first and passes the resolved\n * numbers here, so each keeps its own defaults while one contract states what a bound must be.\n *\n * @example\n * ```ts\n * import { checkBounds } from '@orkestrel/test'\n *\n * checkBounds('Wait', 1000, 10) // undefined\n *\n * // Throws Error: Retry budget must be finite and non-negative\n * checkBounds('Retry', -1, 10)\n * ```\n */\nexport function checkBounds(subject: string, budget: number, interval: number): void {\n\tif (!Number.isFinite(budget) || budget < 0) {\n\t\tthrow new Error(`${subject} budget must be finite and non-negative`)\n\t}\n\tif (!Number.isFinite(interval) || interval < 0) {\n\t\tthrow new Error(`${subject} interval must be finite and non-negative`)\n\t}\n}\n\n/**\n * Builds the error {@link retryUntil} raises when its elapsed-time budget runs out.\n *\n * @param description - The operation the retry was named for.\n * @param budget - The elapsed-time limit in milliseconds.\n * @param elapsed - The milliseconds the retry actually spent.\n * @param last - The rendered last unsatisfying value, or `undefined` when the retry produced none.\n * @param cause - The last producer error, which becomes the returned error's `cause`.\n * @returns The exhaustion error, unthrown.\n * @remarks Both of `retryUntil`'s elapsed checks raise this one message, so an edit to it lands in\n * one place. The rendered value is appended only when the retry produced one.\n *\n * @example\n * ```ts\n * import { buildRetryExhausted } from '@orkestrel/test'\n *\n * const exhausted = buildRetryExhausted('registry answers', 30, 31, '\"starting\"', undefined)\n *\n * exhausted.message\n * // 'Retry \"registry answers\" did not succeed within 30ms (waited 31ms) (last value: \"starting\")'\n * ```\n */\nexport function buildRetryExhausted(\n\tdescription: string,\n\tbudget: number,\n\telapsed: number,\n\tlast: string | undefined,\n\tcause: unknown,\n): Error {\n\treturn new Error(\n\t\t`Retry \"${description}\" did not succeed within ${budget}ms (waited ${elapsed}ms)${last === undefined ? '' : ` (last value: ${last})`}`,\n\t\t{ cause },\n\t)\n}\n\n/**\n * Drops the registration an instrumented signal installed for one listener.\n *\n * @param registrations - The live registration list, spliced in place.\n * @param installed - The installed listener naming the registration to drop.\n * @returns The dropped registration, or `undefined` when the list holds none for that listener.\n * @remarks The dropped registration's cleanup controller is aborted as it leaves, so the scope\n * subscription installed beside it leaves with it. Removing the installed listener from the signal\n * stays with the caller, because only the scope-abort path has one to remove.\n *\n * @example\n * ```ts\n * import type { SignalRegistration } from '@orkestrel/test'\n * import { dropRegistration } from '@orkestrel/test'\n *\n * const listener: EventListener = () => undefined\n * const installed: EventListenerObject = { handleEvent: () => undefined }\n * const cleanup = new AbortController()\n * const registrations: SignalRegistration[] = [[listener, installed, true, cleanup]]\n *\n * dropRegistration(registrations, installed)?.[1] === installed // true\n * cleanup.signal.aborted // true\n * dropRegistration(registrations, installed) // undefined\n * ```\n */\nexport function dropRegistration(\n\tregistrations: SignalRegistration[],\n\tinstalled: EventListener | EventListenerObject,\n): SignalRegistration | undefined {\n\tconst index = registrations.findIndex((registration) => registration[1] === installed)\n\tconst registration = registrations[index]\n\tif (registration === undefined) return undefined\n\tregistrations.splice(index, 1)\n\tregistration[3]?.abort()\n\treturn registration\n}\n\n/**\n * Waits for a host timer to elapse.\n *\n * @param ms - The delay in milliseconds. Default: `0`.\n * @returns A promise that resolves after the timer fires.\n */\nexport function waitForDelay(ms = 0): Promise<void> {\n\treturn new Promise((resolve) => setTimeout(resolve, ms))\n}\n\n/**\n * Waits until an abort signal is aborted.\n *\n * @param signal - The signal to observe.\n * @returns A promise that resolves when the signal is aborted.\n * @remarks An already-aborted signal resolves immediately. Otherwise the wait parks on a one-shot\n * abort listener without a timer or polling.\n */\nexport function waitForAbort(signal: AbortSignal): Promise<void> {\n\tif (signal.aborted) return Promise.resolve()\n\treturn new Promise((resolve) => signal.addEventListener('abort', () => resolve(), { once: true }))\n}\n\n/**\n * Waits until a condition holds within an elapsed-time budget.\n *\n * @param description - The condition described in a timeout error.\n * @param condition - The synchronous or asynchronous condition to read.\n * @param options - The time bounds and abort signal.\n * @returns A promise that resolves when the condition first returns `true`.\n * @throws The condition's thrown value, the abort reason, or an `Error` when a bound is invalid or\n * the condition does not hold within the budget.\n * @remarks The first read is immediate. Default budget: `1000` milliseconds. Default interval: `10`\n * milliseconds.\n */\nexport async function waitForCondition(\n\tdescription: string,\n\tcondition: () => boolean | Promise<boolean>,\n\toptions?: WaitOptions,\n): Promise<void> {\n\tconst budget = options?.budget ?? 1000\n\tconst interval = options?.interval ?? 10\n\tcheckBounds('Wait', budget, interval)\n\n\tconst start = performance.now()\n\twhile (true) {\n\t\toptions?.signal?.throwIfAborted()\n\t\tconst held = await condition()\n\t\toptions?.signal?.throwIfAborted()\n\t\tif (held) return\n\n\t\tconst elapsed = performance.now() - start\n\t\tif (elapsed >= budget) {\n\t\t\tthrow new Error(\n\t\t\t\t`Condition \"${description}\" did not hold within ${budget}ms (waited ${elapsed}ms)`,\n\t\t\t)\n\t\t}\n\t\tawait waitForDelay(interval)\n\t}\n}\n\n/**\n * Repeats a producer until one produced value satisfies a predicate.\n *\n * @typeParam T - The produced value type.\n * @param description - The operation described in an exhaustion error.\n * @param produce - The synchronous or asynchronous operation to repeat.\n * @param satisfied - The predicate that accepts a produced value.\n * @param options - The time, attempt, and abort bounds.\n * @returns The first produced value the predicate accepts.\n * @throws The predicate's thrown value, the abort reason, or an `Error` when a bound is invalid or\n * the retry exhausts its budget or attempts.\n * @remarks A producer throw counts as an unsatisfied attempt. The last producer error becomes the\n * exhaustion error's `cause`. Default budget: `1000` milliseconds. Default interval: `10`\n * milliseconds.\n */\nexport async function retryUntil<T>(\n\tdescription: string,\n\tproduce: () => T | Promise<T>,\n\tsatisfied: (value: T) => boolean,\n\toptions?: RetryOptions,\n): Promise<T> {\n\tconst budget = options?.budget ?? 1000\n\tconst interval = options?.interval ?? 10\n\tconst attempts = options?.attempts\n\tcheckBounds('Retry', budget, interval)\n\tif (attempts !== undefined && (!Number.isInteger(attempts) || attempts < 1)) {\n\t\tthrow new Error('Retry attempts must be a positive integer')\n\t}\n\n\tconst start = performance.now()\n\tlet count = 0\n\tlet cause: unknown\n\tlet last: string | undefined\n\twhile (true) {\n\t\toptions?.signal?.throwIfAborted()\n\t\tif (count > 0) {\n\t\t\tconst elapsed = performance.now() - start\n\t\t\tif (elapsed >= budget) {\n\t\t\t\tthrow buildRetryExhausted(description, budget, elapsed, last, cause)\n\t\t\t}\n\t\t}\n\t\tlet produced: Result<T, unknown>\n\t\ttry {\n\t\t\tproduced = { success: true, value: await produce() }\n\t\t} catch (error) {\n\t\t\tproduced = { success: false, error }\n\t\t}\n\t\tcount += 1\n\t\toptions?.signal?.throwIfAborted()\n\n\t\tif (produced.success) {\n\t\t\tif (satisfied(produced.value)) return produced.value\n\t\t\tlet rendered: string\n\t\t\ttry {\n\t\t\t\tconst serialized = JSON.stringify(produced.value)\n\t\t\t\trendered = serialized === undefined ? String(produced.value) : serialized\n\t\t\t} catch {\n\t\t\t\ttry {\n\t\t\t\t\trendered = String(produced.value)\n\t\t\t\t} catch {\n\t\t\t\t\trendered = '[unrenderable]'\n\t\t\t\t}\n\t\t\t}\n\t\t\tlast = rendered.length > 200 ? `${rendered.slice(0, 197)}...` : rendered\n\t\t} else {\n\t\t\tcause = produced.error\n\t\t}\n\n\t\tconst elapsed = performance.now() - start\n\t\tif (elapsed >= budget) {\n\t\t\tthrow buildRetryExhausted(description, budget, elapsed, last, cause)\n\t\t}\n\t\tif (attempts !== undefined && count >= attempts) {\n\t\t\tthrow new Error(\n\t\t\t\t`Retry \"${description}\" did not succeed within ${attempts} attempts${last === undefined ? '' : ` (last value: ${last})`}`,\n\t\t\t\t{ cause },\n\t\t\t)\n\t\t}\n\t\tawait waitForDelay(Math.min(interval, budget - elapsed))\n\t}\n}\n\n/**\n * Invokes an unknown method through an explicit unchecked result contract.\n *\n * @typeParam T - The result type claimed by the caller.\n * @param target - The value used as the method's `this` argument.\n * @param method - The unknown method to invoke.\n * @param args - The arguments to pass.\n * @returns The method's result under the caller's claimed type.\n * @throws A `TypeError` when `method` is not callable.\n * @remarks The caller owns the claim that the returned value has type `T`. The contained `any`\n * bridges the unchecked runtime result to that caller-owned claim.\n */\nexport function invokeUnchecked<T>(target: unknown, method: unknown, args: readonly unknown[]): T {\n\tif (typeof method !== 'function') throw new TypeError('Method must be callable')\n\tconst result: T = Reflect.apply(method, target, args)\n\treturn result\n}\n\n/**\n * Reads a property from an unknown object or function.\n *\n * @typeParam T - The property type claimed by the caller.\n * @param target - The unknown value to read.\n * @param key - The property key to read.\n * @returns The property value under the caller's claimed type.\n * @throws A `TypeError` when `target` is neither an object nor a function.\n * @remarks The caller owns the claim that the returned value has type `T`. The contained `any`\n * bridges the unchecked runtime result to that caller-owned claim.\n */\nexport function readProperty<T>(target: unknown, key: PropertyKey): T {\n\tif ((typeof target !== 'object' || target === null) && typeof target !== 'function') {\n\t\tthrow new TypeError('Target must be an object or function')\n\t}\n\tconst result: T = Reflect.get(target, key)\n\treturn result\n}\n\n/**\n * Normalizes headers into a frozen plain record.\n *\n * @param init - The platform header initializer to normalize.\n * @returns A frozen record of normalized header names and values.\n * @remarks Normalization follows the host `Headers` implementation, including lowercased names and\n * combined values.\n */\nexport function flattenHeaders(init: HeadersSource): Readonly<Record<string, string>> {\n\treturn Object.freeze(Object.fromEntries(new Headers(init).entries()))\n}\n\n/**\n * Waits for the first delivery from an event subscription.\n *\n * @typeParam TArgs - The delivered argument tuple.\n * @param subscribe - The function that installs the event listener and may return its cleanup.\n * @param description - The event described in a timeout error.\n * @param options - The time bounds and abort signal.\n * @returns The first delivered argument tuple.\n * @throws The subscription's thrown value, the abort reason, or an `Error` when a bound is invalid\n * or the event is not delivered within the budget.\n * @remarks Default budget: `1000` milliseconds. The interval is validated for consistency with the\n * wait family but is not used because this helper parks on the event.\n */\nexport async function waitForEvent<TArgs extends readonly unknown[]>(\n\tsubscribe: EventSubscriber<TArgs>,\n\tdescription: string,\n\toptions?: WaitOptions,\n): Promise<TArgs> {\n\tconst budget = options?.budget ?? 1000\n\tconst interval = options?.interval ?? 10\n\tcheckBounds('Event', budget, interval)\n\n\tconst signal = options?.signal\n\tsignal?.throwIfAborted()\n\tconst delivery = Promise.withResolvers<TArgs>()\n\tconst controller = new AbortController()\n\tlet timeout: ReturnType<typeof setTimeout> | undefined\n\tconst pending: Array<Promise<TArgs>> = [\n\t\tdelivery.promise,\n\t\tnew Promise((_resolve, reject) => {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\treject(new Error(`Event \"${description}\" was not delivered within ${budget}ms`))\n\t\t\t}, budget)\n\t\t}),\n\t]\n\tif (signal !== undefined) {\n\t\tpending.push(\n\t\t\tnew Promise((_resolve, reject) => {\n\t\t\t\tconst combined = AbortSignal.any([signal, controller.signal])\n\t\t\t\tcombined.addEventListener(\n\t\t\t\t\t'abort',\n\t\t\t\t\t() => {\n\t\t\t\t\t\tif (signal.aborted) reject(signal.reason)\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true },\n\t\t\t\t)\n\t\t\t}),\n\t\t)\n\t}\n\tconst result = Promise.race(pending)\n\tlet cleanup: (() => void) | void = undefined\n\ttry {\n\t\ttry {\n\t\t\tcleanup = subscribe((...args) => delivery.resolve(args))\n\t\t} catch (error) {\n\t\t\tdelivery.reject(error)\n\t\t}\n\t\treturn await result\n\t} finally {\n\t\tcontroller.abort()\n\t\tif (timeout !== undefined) clearTimeout(timeout)\n\t\tcleanup?.()\n\t}\n}\n\n/**\n * Decodes newline-delimited JSON values.\n *\n * @param text - The JSON Lines text to decode.\n * @returns The decoded values in physical-line order.\n * @throws An `Error` naming the malformed physical line, with the native `SyntaxError` as its\n * `cause`.\n * @remarks An empty line contributes no value, and a trailing carriage return is dropped before the\n * line is parsed, so text written with either line ending decodes the same.\n *\n * @example\n * ```ts\n * import { decodeJSONLines } from '@orkestrel/test'\n *\n * decodeJSONLines('{\"ready\":true}\\n7\\n') // [{ ready: true }, 7]\n *\n * // Throws Error: Invalid JSON on line 3\n * decodeJSONLines('{}\\n\\n{')\n * ```\n */\nexport function decodeJSONLines(text: string): readonly unknown[] {\n\tconst values: unknown[] = []\n\tfor (const [index, physical] of text.split('\\n').entries()) {\n\t\tconst line = physical.endsWith('\\r') ? physical.slice(0, -1) : physical\n\t\tif (line.length === 0) continue\n\t\ttry {\n\t\t\tconst value: unknown = JSON.parse(line)\n\t\t\tvalues.push(value)\n\t\t} catch (cause) {\n\t\t\tthrow new Error(`Invalid JSON on line ${index + 1}`, { cause })\n\t\t}\n\t}\n\treturn values\n}\n\n/**\n * Captures the value thrown by a thunk.\n *\n * @param thunk - The work whose thrown value to capture.\n * @returns The thrown value, or `undefined` when the thunk completes.\n */\nexport function captureError(thunk: () => unknown): unknown {\n\ttry {\n\t\tthunk()\n\t} catch (error) {\n\t\treturn error\n\t}\n\treturn undefined\n}\n\n/**\n * Narrows a value away from `null` and `undefined`, throwing when it is absent.\n *\n * @typeParam T - The required value type.\n * @param value - The value to check.\n * @param message - The error message used when the value is absent. Default: `'Value is required'`.\n * @returns The present value.\n * @throws An `Error` carrying `message` when the value is `null` or `undefined`.\n */\nexport function requireValue<T>(value: T | null | undefined, message = 'Value is required'): T {\n\tif (value === null || value === undefined) throw new Error(message)\n\treturn value\n}\n\n/**\n * Collects every value from an async iterable.\n *\n * @typeParam T - The yielded value type.\n * @param source - The async iterable to drain.\n * @returns The yielded values in iteration order.\n */\nexport async function collect<T>(source: AsyncIterable<T>): Promise<readonly T[]> {\n\tconst values: T[] = []\n\tfor await (const value of source) values.push(value)\n\treturn values\n}\n\n/**\n * Collects every value from a readable stream.\n *\n * @typeParam T - The streamed value type.\n * @param stream - The readable stream to drain.\n * @returns The streamed values in read order.\n */\nexport async function collectStream<T>(stream: ReadableStream<T>): Promise<readonly T[]> {\n\tconst reader = stream.getReader()\n\tconst values: T[] = []\n\ttry {\n\t\twhile (true) {\n\t\t\tconst result = await reader.read()\n\t\t\tif (result.done) return values\n\t\t\tvalues.push(result.value)\n\t\t}\n\t} finally {\n\t\treader.releaseLock()\n\t}\n}\n\n/**\n * Copies a JSON value through serialization and parsing.\n *\n * @typeParam T - The copied value's type, which the copy keeps.\n * @param value - The value to copy, bounded by its own `JSONSafe` projection.\n * @returns The parsed JSON copy.\n * @remarks Non-finite numbers throw because JSON would replace them with `null`. Negative zero is\n * normalized to zero by JSON serialization. The bound intersects `JSONSafe<T>` rather than\n * constraining `T` to `JSONValue`, so an interface-typed value round-trips.\n */\nexport function roundTripJSON<T>(value: T & JSONSafe<T>): T {\n\tconst serialized = JSON.stringify(value, (_key, current) => {\n\t\tif (current === undefined || typeof current === 'function' || typeof current === 'symbol') {\n\t\t\tthrow new Error('JSON values must not contain undefined, functions, or symbols')\n\t\t}\n\t\tif (typeof current === 'number' && !Number.isFinite(current)) {\n\t\t\tthrow new Error('JSON values must contain finite numbers')\n\t\t}\n\t\treturn current\n\t})\n\tconst parsed: T = JSON.parse(serialized)\n\tconst pending: unknown[] = [parsed]\n\twhile (pending.length > 0) {\n\t\tconst current = pending.pop()\n\t\tif (typeof current === 'number' && !Number.isFinite(current)) {\n\t\t\tthrow new Error('JSON values must contain finite numbers')\n\t\t}\n\t\tif (Array.isArray(current)) {\n\t\t\tfor (const child of current) pending.push(child)\n\t\t} else if (typeof current === 'object' && current !== null) {\n\t\t\tfor (const child of Object.values(current)) pending.push(child)\n\t\t}\n\t}\n\treturn parsed\n}\n\n/**\n * Resolves the parent directory of a calling module, which is the workspace root when called from\n * the conventional `tests/setup.ts` location.\n *\n * @param meta - The calling module metadata.\n * @returns The root URL one directory above the calling file.\n */\nexport function resolveRoot(meta: ImportMeta): URL {\n\treturn new URL('../', meta.url)\n}\n\n/**\n * Drives one statechart scenario through its arrange, act, and assert phases.\n *\n * @typeParam TState - The states the entity moves between.\n * @typeParam TEvent - The events the entity accepts.\n * @typeParam TContext - The fixture the phases drive.\n * @param scenario - The scenario to drive.\n * @param context - The fixture handed to each phase.\n * @returns A promise that resolves after the assert phase completes.\n * @throws An `Error` whose message opens with the transition's `name` and whose `cause` is the value\n * the failing phase threw.\n * @remarks Each phase is awaited before the next begins, so an asynchronous arrange settles before\n * the event is applied. The phases receive the transition's own parts: `arrange` receives `from`,\n * `act` receives `event`, and `assert` receives `to`.\n *\n * The row's name is prepended because a table's rows run under one test name, so a bare assertion\n * message says what failed and never which row. A thrown `Error` keeps its own message after the\n * name and arrives as the `cause`; anything else thrown is named by its type and arrives as the\n * `cause` unchanged.\n *\n * @example\n * ```ts\n * await executeScenario(scenarios[0], { disclosure: new Disclosure() })\n * ```\n */\nexport async function executeScenario<TState extends string, TEvent extends string, TContext>(\n\tscenario: StateScenario<TState, TEvent, TContext>,\n\tcontext: TContext,\n): Promise<void> {\n\tconst transition = scenario.transition\n\ttry {\n\t\tawait scenario.arrange(context, transition.from)\n\t\tawait scenario.act(context, transition.event)\n\t\tawait scenario.assert(context, transition.to)\n\t} catch (cause) {\n\t\tconst message =\n\t\t\tcause instanceof Error ? cause.message : `threw a non-error ${typeof cause} value`\n\t\tthrow new Error(`${transition.name}: ${message}`, { cause })\n\t}\n}\n\n/**\n * Drives a statechart table row by row, each row against a context of its own.\n *\n * @typeParam TState - The states the entity moves between.\n * @typeParam TEvent - The events the entity accepts.\n * @typeParam TContext - The fixture the phases drive.\n * @param scenarios - The table to drive, in the order it is written.\n * @param build - The fixture builder, called once per row and awaited when it returns a promise.\n * @returns A promise that resolves after the last row completes.\n * @throws An `Error` reading `<name>: build refused` when the row's builder throws or rejects, whose\n * `cause` is the value the builder refused with, or whatever {@link executeScenario} throws for the\n * first row whose phases fail. Either way the run stops at that row and the rows after it never\n * start.\n * @remarks The rows run one after another rather than together: a statechart's rows drive one\n * entity on one page, so a parallel run would have them arranging over each other. `build` receives\n * the row it is building for, which is what lets one table mix fixtures.\n *\n * A refusing builder is named for its row the way a failing phase is, because a table's rows build\n * under one test name too. The refusal itself arrives as the `cause`, by identity, so its own\n * message and stack survive the naming.\n *\n * @example\n * ```ts\n * await executeScenarios(SCENARIOS, () => ({ disclosure: new Disclosure() }))\n * ```\n */\nexport async function executeScenarios<TState extends string, TEvent extends string, TContext>(\n\tscenarios: ReadonlyArray<StateScenario<TState, TEvent, TContext>>,\n\tbuild: (scenario: StateScenario<TState, TEvent, TContext>) => TContext | Promise<TContext>,\n): Promise<void> {\n\tfor (const scenario of scenarios) {\n\t\tlet context: TContext\n\t\ttry {\n\t\t\tcontext = await build(scenario)\n\t\t} catch (cause) {\n\t\t\tthrow new Error(`${scenario.transition.name}: build refused`, { cause })\n\t\t}\n\t\tawait executeScenario(scenario, context)\n\t}\n}\n","import type {\n\tEventSourceInterface,\n\tRecorderInterface,\n\tRecorderMap,\n\tResourceFactoryInterface,\n\tSignalInterface,\n\tSignalRegistration,\n\tTeardownHandler,\n\tTeardownInterface,\n} from './types.js'\nimport { dropRegistration } from './helpers.js'\nimport { isRecorderMapComplete } from './validators.js'\n\n/**\n * Creates values that make common object readers throw or violate their assumptions.\n *\n * @returns A frozen array whose values are fresh on every call.\n * @remarks Every member makes a naive read throw or violates a naive structural assumption. A total\n * guard survives every member without throwing. Whether it accepts or refuses one is that guard's\n * own contract. Membership may grow in a release, so test the whole returned set in a loop and\n * include the index in each failure.\n *\n * - The self-referential record makes JSON record serialization throw.\n * - The revoked object proxy makes reflective object access throw.\n * - The property proxy makes a named property read throw.\n * - The key proxy makes key enumeration throw.\n * - The prototype proxy makes a prototype read throw.\n * - The null-prototype record breaks a direct `hasOwnProperty` call.\n * - The array-target proxy passes an array check and makes an index read throw.\n * - The self-referential array makes JSON collection serialization throw.\n * - The sparse array violates the assumption that every index is enumerable.\n * - The hidden-key record violates the assumption that every own key is enumerable.\n * - The named getter makes its property read throw.\n * @example\n * ```ts\n * import { expect } from 'vitest'\n * import { createHostileValues } from '@orkestrel/test'\n *\n * function isWireRecord(value: unknown): value is Readonly<Record<string, string>> {\n * \tif (typeof value !== 'object' || value === null) return false\n * \ttry {\n * \t\tif (Object.getPrototypeOf(value) !== Object.prototype) return false\n * \t\tReflect.get(value, 'value')\n * \t\tif (Reflect.ownKeys(value).length === 0) return false\n * \t\treturn Object.values(value).every((member) => typeof member === 'string')\n * \t} catch {\n * \t\treturn false\n * \t}\n * }\n *\n * for (const [index, value] of createHostileValues().entries()) {\n * \tlet accepted: boolean | undefined\n * \texpect(() => {\n * \t\taccepted = isWireRecord(value)\n * \t}, `hostile value ${index}`).not.toThrow()\n * \texpect(accepted, `hostile value ${index}`).toBe(false)\n * }\n * ```\n */\nexport function createHostileValues(): readonly unknown[] {\n\tconst cyclic: Record<string, unknown> = {}\n\tcyclic.self = cyclic\n\tconst revoked = Proxy.revocable({}, {})\n\trevoked.revoke()\n\tconst cyclicArray: unknown[] = []\n\tcyclicArray.push(cyclicArray)\n\tconst sparseArray = Array<unknown>(2)\n\tsparseArray[1] = 'present'\n\tconst hidden = {}\n\tObject.defineProperty(hidden, 'hidden', { value: true })\n\tReflect.set(hidden, 'self', hidden)\n\tconst getter = {}\n\tObject.defineProperty(getter, 'danger', {\n\t\tenumerable: true,\n\t\tget() {\n\t\t\tthrow new Error('Hostile named getter read')\n\t\t},\n\t})\n\n\treturn Object.freeze([\n\t\tcyclic,\n\t\trevoked.proxy,\n\t\tnew Proxy(\n\t\t\t{},\n\t\t\t{\n\t\t\t\tget() {\n\t\t\t\t\tthrow new Error('Hostile property read')\n\t\t\t\t},\n\t\t\t},\n\t\t),\n\t\tnew Proxy(\n\t\t\t{},\n\t\t\t{\n\t\t\t\townKeys() {\n\t\t\t\t\tthrow new Error('Hostile key enumeration')\n\t\t\t\t},\n\t\t\t},\n\t\t),\n\t\tnew Proxy(\n\t\t\t{},\n\t\t\t{\n\t\t\t\tgetPrototypeOf() {\n\t\t\t\t\tthrow new Error('Hostile prototype read')\n\t\t\t\t},\n\t\t\t},\n\t\t),\n\t\tObject.create(null),\n\t\tnew Proxy([], {\n\t\t\tget() {\n\t\t\t\tthrow new Error('Hostile array index read')\n\t\t\t},\n\t\t}),\n\t\tcyclicArray,\n\t\tsparseArray,\n\t\thidden,\n\t\tgetter,\n\t])\n}\n\n/**\n * Creates a recorder for callback arguments.\n *\n * @typeParam TArgs - The argument tuple to record.\n * @returns A recorder whose handler appends calls in order.\n */\nexport function createRecorder<\n\tTArgs extends readonly unknown[] = readonly unknown[],\n>(): RecorderInterface<TArgs> {\n\tconst calls: TArgs[] = []\n\treturn {\n\t\tcalls,\n\t\tget count() {\n\t\t\treturn calls.length\n\t\t},\n\t\thandler(...args) {\n\t\t\tcalls.push(args)\n\t\t},\n\t\tclear() {\n\t\t\tcalls.length = 0\n\t\t},\n\t}\n}\n\n/**\n * Creates event recorders and subscribes them to the source.\n *\n * @typeParam TMap - The source's event names and delivered argument tuples.\n * @typeParam TName - The requested event names.\n * @param source - The source to subscribe to.\n * @param events - The events to record.\n * @returns A map from each requested event name to its recorder.\n * @throws Thrown when a listed event has no recorder, which a well-formed events array cannot\n * produce.\n * @remarks A duplicate event name installs a fresh recorder for every occurrence. The returned map\n * keeps the recorder installed for the last occurrence. `TName` derives from the array's element\n * type. An array declared with a wider union than its contents widens `TName` beyond the listed\n * events. The omitted key reads `undefined` at runtime under a non-optional type, and the guard\n * reports `true` because it checks the listed events. Pass a literal array or a tuple.\n */\nexport function createRecorders<\n\tTMap extends Record<string, readonly unknown[]>,\n\tTName extends keyof TMap,\n>(source: EventSourceInterface<TMap>, events: readonly TName[]): RecorderMap<TMap, TName> {\n\tconst building: { -readonly [K in TName]?: RecorderInterface<TMap[TName]> } = {}\n\tfor (const event of events) {\n\t\tconst recorder = createRecorder<TMap[TName]>()\n\t\tsource.on(event, recorder.handler)\n\t\tbuilding[event] = recorder\n\t}\n\tif (!isRecorderMapComplete<TMap, TName>(building, events)) {\n\t\tthrow new Error('Emitter recorder map is incomplete')\n\t}\n\treturn building\n}\n\n/**\n * Creates a real abort controller whose signal reports its live abort listeners.\n *\n * @returns The controller, its instrumented signal, and the current listener tally.\n * @remarks Instrumentation is installed on the created signal instance. A one-shot listener leaves\n * the tally when it fires, and removal accepts the original listener supplied by the caller. A\n * listener scoped by another signal leaves when that signal aborts. An already-aborted scope\n * installs and records nothing.\n */\nexport function createSignal(): SignalInterface {\n\tconst controller = new AbortController()\n\tconst signal = controller.signal\n\tconst add = signal.addEventListener.bind(signal)\n\tconst remove = signal.removeEventListener.bind(signal)\n\tconst registrations: SignalRegistration[] = []\n\n\tObject.defineProperty(signal, 'addEventListener', {\n\t\tconfigurable: true,\n\t\tvalue(\n\t\t\ttype: string,\n\t\t\tlistener: EventListener | EventListenerObject | null,\n\t\t\toptions?: boolean | AddEventListenerOptions,\n\t\t) {\n\t\t\tif (listener === null) return\n\t\t\tif (type !== 'abort') {\n\t\t\t\tadd(type, listener, options)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst capture = typeof options === 'boolean' ? options : (options?.capture ?? false)\n\t\t\tconst scope = typeof options === 'object' ? options?.signal : undefined\n\t\t\tif (scope?.aborted === true) return\n\t\t\tif (\n\t\t\t\tregistrations.some(\n\t\t\t\t\t(registration) => registration[0] === listener && registration[2] === capture,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst once = typeof options === 'object' && options?.once === true\n\t\t\tconst cleanup = scope === undefined ? undefined : new AbortController()\n\t\t\tconst installed: EventListenerObject = {\n\t\t\t\thandleEvent(event) {\n\t\t\t\t\tif (once) dropRegistration(registrations, installed)\n\t\t\t\t\tif (typeof listener === 'function') listener.call(signal, event)\n\t\t\t\t\telse listener.handleEvent(event)\n\t\t\t\t},\n\t\t\t}\n\t\t\tadd(\n\t\t\t\ttype,\n\t\t\t\tinstalled,\n\t\t\t\ttypeof options === 'object'\n\t\t\t\t\t? options?.passive === undefined\n\t\t\t\t\t\t? { capture, once }\n\t\t\t\t\t\t: { capture, once, passive: options.passive }\n\t\t\t\t\t: options,\n\t\t\t)\n\t\t\tregistrations.push([listener, installed, capture, cleanup])\n\t\t\tif (scope !== undefined && cleanup !== undefined) {\n\t\t\t\tscope.addEventListener(\n\t\t\t\t\t'abort',\n\t\t\t\t\t() => {\n\t\t\t\t\t\tconst registration = dropRegistration(registrations, installed)\n\t\t\t\t\t\tif (registration === undefined) return\n\t\t\t\t\t\tremove(type, registration[1], { capture })\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true, signal: cleanup.signal },\n\t\t\t\t)\n\t\t\t}\n\t\t},\n\t})\n\tObject.defineProperty(signal, 'removeEventListener', {\n\t\tconfigurable: true,\n\t\tvalue(\n\t\t\ttype: string,\n\t\t\tlistener: EventListener | EventListenerObject | null,\n\t\t\toptions?: boolean | EventListenerOptions,\n\t\t) {\n\t\t\tif (listener === null) return\n\t\t\tif (type !== 'abort') {\n\t\t\t\tremove(type, listener, options)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst capture = typeof options === 'boolean' ? options : (options?.capture ?? false)\n\t\t\tconst index = registrations.findIndex(\n\t\t\t\t(registration) => registration[0] === listener && registration[2] === capture,\n\t\t\t)\n\t\t\tconst registration = registrations[index]\n\t\t\tif (registration === undefined) {\n\t\t\t\tremove(type, listener, options)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tregistrations.splice(index, 1)\n\t\t\tregistration[3]?.abort()\n\t\t\tremove(type, registration[1], options)\n\t\t},\n\t})\n\n\treturn {\n\t\tcontroller,\n\t\tsignal,\n\t\tget count() {\n\t\t\treturn registrations.length\n\t\t},\n\t}\n}\n\n/**\n * Creates a monotonically numbered resource factory with creation and destruction records.\n *\n * @returns A resource factory whose recorders retain every affected id in order.\n */\nexport function createResourceFactory(): ResourceFactoryInterface {\n\tconst created = createRecorder<readonly [id: number]>()\n\tconst destroyed = createRecorder<readonly [id: number]>()\n\treturn {\n\t\tcreated,\n\t\tdestroyed,\n\t\tcreate() {\n\t\t\tconst id = created.calls.length + 1\n\t\t\tcreated.handler(id)\n\t\t\treturn id\n\t\t},\n\t\tdestroy(id) {\n\t\t\tdestroyed.handler(id)\n\t\t},\n\t}\n}\n\n/**\n * Creates a teardown list that runs registered handlers newest-first.\n *\n * @returns A teardown list that awaits every handler and collects failures.\n */\nexport function createTeardown(): TeardownInterface {\n\tlet handlers: TeardownHandler[] = []\n\treturn {\n\t\tget count() {\n\t\t\treturn handlers.length\n\t\t},\n\t\tadd(handler) {\n\t\t\thandlers.push(handler)\n\t\t},\n\t\tasync destroy() {\n\t\t\tconst snapshot = handlers\n\t\t\thandlers = []\n\t\t\tconst failures: unknown[] = []\n\t\t\tfor (const handler of snapshot.reverse()) {\n\t\t\t\ttry {\n\t\t\t\t\tawait handler()\n\t\t\t\t} catch (error) {\n\t\t\t\t\tfailures.push(error)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (failures.length === 1) throw failures[0]\n\t\t\tif (failures.length > 1) throw new AggregateError(failures)\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,IAAa,wBAAwB,OAAO,OAAO;CAClD,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,OAAO;CACP,UAAU;CACV,QAAQ;CACR,OAAO;AACR,CAAC;;;;;;;;;;;;;;;;;;AAmBD,IAAa,sBAAsB,OAAO,OAAO;CAChD;CACA;CACA;CACA;CACA;AACD,CAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACzBV,SAAgB,sBAGd,OAAgB,QAA6D;CAC9E,IAAI;EACH,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;EACxD,OAAO,OAAO,OAAO,UAAU;GAC9B,IAAI,CAAC,OAAO,OAAO,OAAO,KAAK,GAAG,OAAO;GACzC,MAAM,WAAW,QAAQ,IAAI,OAAO,KAAK;GACzC,IAAI,OAAO,aAAa,YAAY,aAAa,MAAM,OAAO;GAC9D,OACC,OAAO,QAAQ,IAAI,UAAU,SAAS,MAAM,cAC5C,MAAM,QAAQ,QAAQ,IAAI,UAAU,OAAO,CAAC;EAE9C,CAAC;CACF,QAAQ;EACP,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UAAW,SAAS,WAAW;GAC9E,MAAM,QAAQ,cAAc,WAC1B,iBAAiB,aAAa,OAAO,YAAY,aAAa,OAAO,OACvE;GACA,MAAM,eAAe,cAAc;GACnC,IAAI,iBAAiB,KAAA,GAAW;IAC/B,OAAO,MAAM,UAAU,OAAO;IAC9B;GACD;GACA,cAAc,OAAO,OAAO,CAAC;GAC7B,aAAa,EAAE,EAAE,MAAM;GACvB,OAAO,MAAM,aAAa,IAAI,OAAO;EACtC;CACD,CAAC;CAED,OAAO;EACN;EACA;EACA,IAAI,QAAQ;GACX,OAAO,cAAc;EACtB;CACD;AACD;;;;;;AAOA,SAAgB,wBAAkD;CACjE,MAAM,UAAU,eAAsC;CACtD,MAAM,YAAY,eAAsC;CACxD,OAAO;EACN;EACA;EACA,SAAS;GACR,MAAM,KAAK,QAAQ,MAAM,SAAS;GAClC,QAAQ,QAAQ,EAAE;GAClB,OAAO;EACR;EACA,QAAQ,IAAI;GACX,UAAU,QAAQ,EAAE;EACrB;CACD;AACD;;;;;;AAOA,SAAgB,iBAAoC;CACnD,IAAI,WAA8B,CAAC;CACnC,OAAO;EACN,IAAI,QAAQ;GACX,OAAO,SAAS;EACjB;EACA,IAAI,SAAS;GACZ,SAAS,KAAK,OAAO;EACtB;EACA,MAAM,UAAU;GACf,MAAM,WAAW;GACjB,WAAW,CAAC;GACZ,MAAM,WAAsB,CAAC;GAC7B,KAAK,MAAM,WAAW,SAAS,QAAQ,GACtC,IAAI;IACH,MAAM,QAAQ;GACf,SAAS,OAAO;IACf,SAAS,KAAK,KAAK;GACpB;GAED,IAAI,SAAS,WAAW,GAAG,MAAM,SAAS;GAC1C,IAAI,SAAS,SAAS,GAAG,MAAM,IAAI,eAAe,QAAQ;EAC3D;CACD;AACD"}
|
|
@@ -9,6 +9,16 @@
|
|
|
9
9
|
* @returns The exhaustion error, unthrown.
|
|
10
10
|
* @remarks Both of `retryUntil`'s elapsed checks raise this one message, so an edit to it lands in
|
|
11
11
|
* one place. The rendered value is appended only when the retry produced one.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { buildRetryExhausted } from '@orkestrel/test'
|
|
16
|
+
*
|
|
17
|
+
* const exhausted = buildRetryExhausted('registry answers', 30, 31, '"starting"', undefined)
|
|
18
|
+
*
|
|
19
|
+
* exhausted.message
|
|
20
|
+
* // 'Retry "registry answers" did not succeed within 30ms (waited 31ms) (last value: "starting")'
|
|
21
|
+
* ```
|
|
12
22
|
*/
|
|
13
23
|
export declare function buildRetryExhausted(description: string, budget: number, elapsed: number, last: string | undefined, cause: unknown): Error;
|
|
14
24
|
|
|
@@ -30,6 +40,16 @@ export declare function captureError(thunk: () => unknown): unknown;
|
|
|
30
40
|
* `<subject> interval must be finite and non-negative`.
|
|
31
41
|
* @remarks Every member of the wait family resolves its own defaults first and passes the resolved
|
|
32
42
|
* numbers here, so each keeps its own defaults while one contract states what a bound must be.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { checkBounds } from '@orkestrel/test'
|
|
47
|
+
*
|
|
48
|
+
* checkBounds('Wait', 1000, 10) // undefined
|
|
49
|
+
*
|
|
50
|
+
* // Throws Error: Retry budget must be finite and non-negative
|
|
51
|
+
* checkBounds('Retry', -1, 10)
|
|
52
|
+
* ```
|
|
33
53
|
*/
|
|
34
54
|
export declare function checkBounds(subject: string, budget: number, interval: number): void;
|
|
35
55
|
|
|
@@ -157,6 +177,18 @@ export declare function createTeardown(): TeardownInterface;
|
|
|
157
177
|
* @returns The decoded values in physical-line order.
|
|
158
178
|
* @throws An `Error` naming the malformed physical line, with the native `SyntaxError` as its
|
|
159
179
|
* `cause`.
|
|
180
|
+
* @remarks An empty line contributes no value, and a trailing carriage return is dropped before the
|
|
181
|
+
* line is parsed, so text written with either line ending decodes the same.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* import { decodeJSONLines } from '@orkestrel/test'
|
|
186
|
+
*
|
|
187
|
+
* decodeJSONLines('{"ready":true}\n7\n') // [{ ready: true }, 7]
|
|
188
|
+
*
|
|
189
|
+
* // Throws Error: Invalid JSON on line 3
|
|
190
|
+
* decodeJSONLines('{}\n\n{')
|
|
191
|
+
* ```
|
|
160
192
|
*/
|
|
161
193
|
export declare function decodeJSONLines(text: string): readonly unknown[];
|
|
162
194
|
|
|
@@ -169,6 +201,21 @@ export declare function decodeJSONLines(text: string): readonly unknown[];
|
|
|
169
201
|
* @remarks The dropped registration's cleanup controller is aborted as it leaves, so the scope
|
|
170
202
|
* subscription installed beside it leaves with it. Removing the installed listener from the signal
|
|
171
203
|
* stays with the caller, because only the scope-abort path has one to remove.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* import type { SignalRegistration } from '@orkestrel/test'
|
|
208
|
+
* import { dropRegistration } from '@orkestrel/test'
|
|
209
|
+
*
|
|
210
|
+
* const listener: EventListener = () => undefined
|
|
211
|
+
* const installed: EventListenerObject = { handleEvent: () => undefined }
|
|
212
|
+
* const cleanup = new AbortController()
|
|
213
|
+
* const registrations: SignalRegistration[] = [[listener, installed, true, cleanup]]
|
|
214
|
+
*
|
|
215
|
+
* dropRegistration(registrations, installed)?.[1] === installed // true
|
|
216
|
+
* cleanup.signal.aborted // true
|
|
217
|
+
* dropRegistration(registrations, installed) // undefined
|
|
218
|
+
* ```
|
|
172
219
|
*/
|
|
173
220
|
export declare function dropRegistration(registrations: SignalRegistration[], installed: EventListener | EventListenerObject): SignalRegistration | undefined;
|
|
174
221
|
|
|
@@ -176,6 +223,8 @@ export declare function dropRegistration(registrations: SignalRegistration[], in
|
|
|
176
223
|
* Subscribes handlers to a typed event source.
|
|
177
224
|
*
|
|
178
225
|
* @typeParam TMap - The event names and argument tuples the source delivers.
|
|
226
|
+
* @remarks The subscribe half is all this asks for, so a source that also removes handlers, emits,
|
|
227
|
+
* or counts subscriptions satisfies it unchanged.
|
|
179
228
|
*/
|
|
180
229
|
export declare interface EventSourceInterface<TMap extends Record<string, readonly unknown[]>> {
|
|
181
230
|
/**
|
|
@@ -308,6 +357,18 @@ export declare function invokeUnchecked<T>(target: unknown, method: unknown, arg
|
|
|
308
357
|
* wiring each recorder to exactly the event where it stores that recorder. A direct caller must
|
|
309
358
|
* establish the same pairing before it relies on the narrowing. This guard takes the listed events
|
|
310
359
|
* through a reference parameter rather than using the canonical single-value guard form.
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```ts
|
|
363
|
+
* import { createRecorder, isRecorderMapComplete } from '@orkestrel/test'
|
|
364
|
+
*
|
|
365
|
+
* type ReadyEvents = { readonly ready: readonly [name: string, step: number] }
|
|
366
|
+
*
|
|
367
|
+
* const value: unknown = { ready: createRecorder<readonly [name: string, step: number]>() }
|
|
368
|
+
*
|
|
369
|
+
* isRecorderMapComplete<ReadyEvents, 'ready'>(value, ['ready']) // true
|
|
370
|
+
* isRecorderMapComplete<ReadyEvents, 'ready'>({ ready: 1 }, ['ready']) // false
|
|
371
|
+
* ```
|
|
311
372
|
*/
|
|
312
373
|
export declare function isRecorderMapComplete<TMap extends Record<string, readonly unknown[]>, TName extends keyof TMap>(value: unknown, events: readonly TName[]): value is RecorderMap<TMap, TName>;
|
|
313
374
|
|
|
@@ -374,7 +435,11 @@ export declare interface RecorderInterface<TArgs extends readonly unknown[]> {
|
|
|
374
435
|
readonly count: number;
|
|
375
436
|
/** Holds the callback to hand to the code under test. */
|
|
376
437
|
readonly handler: (...args: TArgs) => void;
|
|
377
|
-
/**
|
|
438
|
+
/**
|
|
439
|
+
* Discards the recorded calls and keeps the recorder usable.
|
|
440
|
+
*
|
|
441
|
+
* @remarks The list is truncated in place, so a `calls` reference taken earlier empties too.
|
|
442
|
+
*/
|
|
378
443
|
clear(): void;
|
|
379
444
|
}
|
|
380
445
|
|
|
@@ -389,12 +454,13 @@ export declare type RecorderMap<TMap extends Record<string, readonly unknown[]>,
|
|
|
389
454
|
};
|
|
390
455
|
|
|
391
456
|
/**
|
|
392
|
-
*
|
|
457
|
+
* Narrows a value away from `null` and `undefined`, throwing when it is absent.
|
|
393
458
|
*
|
|
394
459
|
* @typeParam T - The required value type.
|
|
395
460
|
* @param value - The value to check.
|
|
396
|
-
* @param message - The error message used when the value is absent.
|
|
461
|
+
* @param message - The error message used when the value is absent. Default: `'Value is required'`.
|
|
397
462
|
* @returns The present value.
|
|
463
|
+
* @throws An `Error` carrying `message` when the value is `null` or `undefined`.
|
|
398
464
|
*/
|
|
399
465
|
export declare function requireValue<T>(value: T | null | undefined, message?: string): T;
|
|
400
466
|
|
|
@@ -417,12 +483,17 @@ export declare interface ResourceFactoryInterface {
|
|
|
417
483
|
* Creates a numbered resource.
|
|
418
484
|
*
|
|
419
485
|
* @returns The next monotonically increasing id.
|
|
486
|
+
* @remarks The id is the creation record's length plus one, so it counts allocations rather than
|
|
487
|
+
* live resources: a destroyed id is never reissued, and clearing `created` restarts the numbering
|
|
488
|
+
* at `1`.
|
|
420
489
|
*/
|
|
421
490
|
create(): number;
|
|
422
491
|
/**
|
|
423
492
|
* Destroys a numbered resource.
|
|
424
493
|
*
|
|
425
494
|
* @param id - The resource id to destroy.
|
|
495
|
+
* @remarks It records the id and nothing else: it frees nothing, refuses nothing, and accepts an
|
|
496
|
+
* id that was never created, so a suite asserts on the record rather than on a refusal.
|
|
426
497
|
*/
|
|
427
498
|
destroy(id: number): void;
|
|
428
499
|
}
|
|
@@ -434,11 +505,12 @@ export declare interface ResourceFactoryInterface {
|
|
|
434
505
|
* @typeParam E - The failure type. Defaults to `Error`.
|
|
435
506
|
* @remarks `success` is the discriminant, so a caller narrows on it before reading `value` or
|
|
436
507
|
* `error`. This package declares no runtime dependency, so this is the one outcome contract its own
|
|
437
|
-
* members read rather than an anonymous union written at each call site.
|
|
508
|
+
* members read rather than an anonymous union written at each call site. `E` defaults to `Error`,
|
|
509
|
+
* where `@orkestrel/contract` publishes the same name defaulting to `unknown`.
|
|
438
510
|
*/
|
|
439
511
|
export declare type Result<T, E = Error> = Success<T> | Failure<E>;
|
|
440
512
|
|
|
441
|
-
/** Configures a bounded retry. */
|
|
513
|
+
/** Configures a bounded retry, adding an optional producer-call limit to a bounded wait's bounds. */
|
|
442
514
|
export declare interface RetryOptions extends WaitOptions {
|
|
443
515
|
/** Caps the number of producer calls. When omitted, only the time budget bounds the retry. */
|
|
444
516
|
readonly attempts?: number;
|
|
@@ -579,6 +651,7 @@ export declare interface StateScenario<TState extends string, TEvent extends str
|
|
|
579
651
|
*
|
|
580
652
|
* @param context - The fixture this row drives.
|
|
581
653
|
* @param state - The transition's `to` state.
|
|
654
|
+
* @remarks Whatever it throws is renamed with the row's name and rethrown.
|
|
582
655
|
*/
|
|
583
656
|
assert(context: TContext, state: TState): Promise<void> | void;
|
|
584
657
|
}
|
|
@@ -626,6 +699,8 @@ export declare interface TeardownInterface {
|
|
|
626
699
|
* Registers a handler to run when the list is destroyed.
|
|
627
700
|
*
|
|
628
701
|
* @param handler - The work to perform.
|
|
702
|
+
* @remarks Registration order is what `destroy` reverses, so the newest registration is undone
|
|
703
|
+
* first.
|
|
629
704
|
*/
|
|
630
705
|
add(handler: TeardownHandler): void;
|
|
631
706
|
/**
|
|
@@ -668,7 +743,7 @@ export declare function waitForCondition(description: string, condition: () => b
|
|
|
668
743
|
/**
|
|
669
744
|
* Waits for a host timer to elapse.
|
|
670
745
|
*
|
|
671
|
-
* @param ms - The delay in milliseconds.
|
|
746
|
+
* @param ms - The delay in milliseconds. Default: `0`.
|
|
672
747
|
* @returns A promise that resolves after the timer fires.
|
|
673
748
|
*/
|
|
674
749
|
export declare function waitForDelay(ms?: number): Promise<void>;
|
|
@@ -689,7 +764,8 @@ export declare function waitForDelay(ms?: number): Promise<void>;
|
|
|
689
764
|
export declare function waitForEvent<TArgs extends readonly unknown[]>(subscribe: EventSubscriber<TArgs>, description: string, options?: WaitOptions): Promise<TArgs>;
|
|
690
765
|
|
|
691
766
|
/**
|
|
692
|
-
* Configures a bounded asynchronous wait
|
|
767
|
+
* Configures a bounded asynchronous wait with an elapsed-time limit, a delay between readings, and
|
|
768
|
+
* an abort signal.
|
|
693
769
|
*
|
|
694
770
|
* @remarks
|
|
695
771
|
* A default belongs to the function that reads these bounds rather than to the shape, because the
|