@crvouga/mockingbird-service-workos 1.1.0 → 1.2.0
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/CHANGELOG.md +6 -4
- package/DISCOVERY.md +23 -0
- package/README.md +28 -3
- package/dist/chunk-LE5B6IJG.js +5417 -0
- package/dist/chunk-LE5B6IJG.js.map +7 -0
- package/dist/{chunk-BIGV6FI5.js → chunk-X5OR3IYU.js} +136 -25
- package/dist/chunk-X5OR3IYU.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +339 -40
- package/dist/index.js +1 -1
- package/dist/server.d.ts +678 -80
- package/dist/server.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-BIGV6FI5.js.map +0 -7
- package/dist/chunk-JITNKKHL.js +0 -3626
- package/dist/chunk-JITNKKHL.js.map +0 -7
package/dist/server.d.ts
CHANGED
|
@@ -146,7 +146,7 @@ type ClockState$1 = {
|
|
|
146
146
|
now: number;
|
|
147
147
|
/** True while time does not advance on its own. */
|
|
148
148
|
frozen: boolean;
|
|
149
|
-
/** Milliseconds
|
|
149
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
150
150
|
offsetMs: number;
|
|
151
151
|
};
|
|
152
152
|
type Clock$1 = {
|
|
@@ -182,7 +182,10 @@ type Rng$1 = {
|
|
|
182
182
|
state(): number;
|
|
183
183
|
/** Restore a state previously returned by {@link state}. */
|
|
184
184
|
setState(state: number): void;
|
|
185
|
-
seed
|
|
185
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
186
|
+
reseed(seed: number | string): void;
|
|
187
|
+
/** The seed the stream currently starts from. */
|
|
188
|
+
readonly seed: number;
|
|
186
189
|
};
|
|
187
190
|
|
|
188
191
|
/**
|
|
@@ -191,44 +194,83 @@ type Rng$1 = {
|
|
|
191
194
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
192
195
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
193
196
|
* appears under load, the 5xx that proves a retry path works.
|
|
197
|
+
*
|
|
198
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
199
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
200
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
194
201
|
*/
|
|
195
202
|
type FaultRule$1 = {
|
|
196
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
203
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
197
204
|
id: string;
|
|
198
205
|
/** Fault only this operation. Omit to match every operation. */
|
|
199
206
|
operationId?: string;
|
|
200
207
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
201
208
|
method?: string;
|
|
209
|
+
/** Fault only this exact path. */
|
|
210
|
+
path?: string;
|
|
202
211
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
203
212
|
pathPrefix?: string;
|
|
213
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
214
|
+
pathPattern?: string;
|
|
215
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
216
|
+
requestHeaders?: Record<string, string>;
|
|
217
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
218
|
+
query?: Record<string, string>;
|
|
204
219
|
/**
|
|
205
220
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
206
221
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
207
222
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
208
223
|
*/
|
|
209
224
|
namespace?: string;
|
|
225
|
+
/** Let this many matching requests through first. */
|
|
226
|
+
after?: number;
|
|
227
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
228
|
+
every?: number;
|
|
229
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
230
|
+
count?: number;
|
|
231
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
232
|
+
rate?: number;
|
|
233
|
+
/**
|
|
234
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
235
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
236
|
+
*/
|
|
237
|
+
from?: Instant$1 | Duration$1;
|
|
238
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
239
|
+
until?: Instant$1 | Duration$1;
|
|
210
240
|
/**
|
|
211
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
212
|
-
*
|
|
213
|
-
* the request then still reaches the service.
|
|
241
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
242
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
214
243
|
*/
|
|
215
244
|
status?: number;
|
|
216
245
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
217
246
|
body?: unknown;
|
|
247
|
+
/** Response headers. */
|
|
218
248
|
headers?: Record<string, string>;
|
|
219
|
-
/**
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
rate?: number;
|
|
223
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
249
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
250
|
+
delay?: Duration$1;
|
|
251
|
+
/** `delay`, in milliseconds. */
|
|
224
252
|
delayMs?: number;
|
|
225
253
|
/** Alias of `delayMs`. */
|
|
226
254
|
latencyMs?: number;
|
|
255
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
256
|
+
jitter?: Duration$1;
|
|
257
|
+
jitterMs?: number;
|
|
258
|
+
/**
|
|
259
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
260
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
261
|
+
*/
|
|
262
|
+
timeout?: Duration$1;
|
|
263
|
+
timeoutMs?: number;
|
|
227
264
|
/**
|
|
228
265
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
229
266
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
230
267
|
*/
|
|
231
268
|
drop?: boolean;
|
|
269
|
+
/**
|
|
270
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
271
|
+
* the connection dies mid-body.
|
|
272
|
+
*/
|
|
273
|
+
truncate?: number;
|
|
232
274
|
/**
|
|
233
275
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
234
276
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -237,8 +279,8 @@ type FaultRule$1 = {
|
|
|
237
279
|
effect?: string;
|
|
238
280
|
/** Parameters for `effect`. */
|
|
239
281
|
params?: Record<string, unknown>;
|
|
240
|
-
/**
|
|
241
|
-
|
|
282
|
+
/** The preset this rule was expanded from, if any. */
|
|
283
|
+
fromPreset?: string;
|
|
242
284
|
};
|
|
243
285
|
/** A fault that fired for one request. */
|
|
244
286
|
type FaultHit$1 = {
|
|
@@ -246,6 +288,10 @@ type FaultHit$1 = {
|
|
|
246
288
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
247
289
|
response?: Response;
|
|
248
290
|
drop?: boolean;
|
|
291
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
292
|
+
timeout?: boolean;
|
|
293
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
294
|
+
truncate?: number;
|
|
249
295
|
effect?: {
|
|
250
296
|
name: string;
|
|
251
297
|
params: Record<string, unknown>;
|
|
@@ -257,38 +303,200 @@ type FaultCandidate$1 = {
|
|
|
257
303
|
method: string;
|
|
258
304
|
path: string;
|
|
259
305
|
namespace: string;
|
|
306
|
+
/** Request headers and query, for rules that match on them. */
|
|
307
|
+
headers?: Headers;
|
|
308
|
+
query?: URLSearchParams;
|
|
309
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
310
|
+
now?: number;
|
|
311
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
312
|
+
wait?: (ms: number) => Promise<void>;
|
|
313
|
+
};
|
|
314
|
+
/** A stored rule and how often it was consulted. */
|
|
315
|
+
type FaultListing$1 = FaultRule$1 & {
|
|
316
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
317
|
+
remaining: number | null;
|
|
318
|
+
/** Times the rule faulted a request. */
|
|
319
|
+
hits: number;
|
|
320
|
+
/** Requests that matched the rule, faulted or not. */
|
|
321
|
+
seen: number;
|
|
322
|
+
};
|
|
323
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
324
|
+
type FaultSnapshot$1 = {
|
|
325
|
+
/**
|
|
326
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
327
|
+
* in the order means to a request and holds in any process.
|
|
328
|
+
*/
|
|
329
|
+
rules: (FaultListing$1 & {
|
|
330
|
+
position?: number;
|
|
331
|
+
})[];
|
|
332
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
333
|
+
nextId?: number;
|
|
260
334
|
};
|
|
261
335
|
type FaultRegistry$1 = {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
rules: (FaultRule$1 & {
|
|
265
|
-
remaining: number | null;
|
|
266
|
-
hits: number;
|
|
267
|
-
position: number;
|
|
268
|
-
})[];
|
|
269
|
-
rngState: number;
|
|
270
|
-
};
|
|
336
|
+
snapshot(namespace: string): FaultSnapshot$1;
|
|
337
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
271
338
|
add(rule: FaultRule$1): FaultRule$1;
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
})[];
|
|
284
|
-
rngState: number;
|
|
285
|
-
}): void;
|
|
339
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
340
|
+
nextId(namespace: string): string;
|
|
341
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
342
|
+
list(namespace?: string): FaultListing$1[];
|
|
343
|
+
get(id: string, namespace?: string): FaultListing$1 | undefined;
|
|
344
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
345
|
+
remove(id: string, namespace?: string): boolean;
|
|
346
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
347
|
+
clear(namespace?: string): void;
|
|
348
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
349
|
+
restore(namespace: string, state: FaultSnapshot$1): void;
|
|
286
350
|
/**
|
|
287
351
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
288
352
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
289
353
|
* each matching rule's remaining uses.
|
|
290
354
|
*/
|
|
291
355
|
take(candidate: FaultCandidate$1): Promise<FaultHit$1[]>;
|
|
356
|
+
/**
|
|
357
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
358
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
359
|
+
*/
|
|
360
|
+
fire(rules: readonly FaultRule$1[], candidate: FaultCandidate$1): Promise<FaultHit$1[]>;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* The admin controls every mock shares, as one document.
|
|
365
|
+
*
|
|
366
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
367
|
+
*
|
|
368
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
369
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
370
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
371
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
372
|
+
*
|
|
373
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
374
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
375
|
+
*/
|
|
376
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
377
|
+
type Duration$1 = number | string;
|
|
378
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
379
|
+
type Instant$1 = number | string;
|
|
380
|
+
type ClockControls$1 = {
|
|
381
|
+
/** Move the clock to this instant. */
|
|
382
|
+
now?: Instant$1;
|
|
383
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
384
|
+
frozen?: boolean;
|
|
385
|
+
/**
|
|
386
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
387
|
+
* each request still gets its own, reproducible timestamp.
|
|
388
|
+
*/
|
|
389
|
+
autoAdvance?: Duration$1;
|
|
390
|
+
};
|
|
391
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
392
|
+
type LatencyRuleInput$1 = {
|
|
393
|
+
delay?: Duration$1;
|
|
394
|
+
jitter?: Duration$1;
|
|
395
|
+
};
|
|
396
|
+
type LatencyControls$1 = LatencyRuleInput$1 & {
|
|
397
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
398
|
+
operations?: Record<string, Duration$1 | LatencyRuleInput$1>;
|
|
399
|
+
};
|
|
400
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
401
|
+
type FaultInput$1 = (Omit<FaultRule$1, "id"> & {
|
|
402
|
+
id?: string;
|
|
403
|
+
}) | ({
|
|
404
|
+
preset: string;
|
|
405
|
+
} & Partial<FaultRule$1>);
|
|
406
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
407
|
+
declare const SNAPSHOT_FORMAT$1 = "mockingbird.snapshot/v1";
|
|
408
|
+
/**
|
|
409
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
410
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
411
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
412
|
+
*/
|
|
413
|
+
type SnapshotDocument$1 = {
|
|
414
|
+
format: typeof SNAPSHOT_FORMAT$1;
|
|
415
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
416
|
+
service?: string;
|
|
417
|
+
/**
|
|
418
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
419
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
420
|
+
*/
|
|
421
|
+
records: {
|
|
422
|
+
collection: string;
|
|
423
|
+
id: string;
|
|
424
|
+
seq?: number;
|
|
425
|
+
value?: unknown;
|
|
426
|
+
raw?: string;
|
|
427
|
+
}[];
|
|
428
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
429
|
+
sequences?: {
|
|
430
|
+
name: string;
|
|
431
|
+
kind: string;
|
|
432
|
+
value: number;
|
|
433
|
+
}[];
|
|
434
|
+
clock?: {
|
|
435
|
+
now: number;
|
|
436
|
+
frozen: boolean;
|
|
437
|
+
autoAdvanceMs?: number;
|
|
438
|
+
};
|
|
439
|
+
seed?: number | string;
|
|
440
|
+
/** Positions of the seeded random streams. */
|
|
441
|
+
rng?: {
|
|
442
|
+
state: number;
|
|
443
|
+
faults?: number;
|
|
444
|
+
latency?: number;
|
|
445
|
+
};
|
|
446
|
+
faults?: unknown;
|
|
447
|
+
latency?: unknown;
|
|
448
|
+
virtualTime?: boolean;
|
|
449
|
+
};
|
|
450
|
+
/** Controls for one namespace. */
|
|
451
|
+
type NamespaceControls$1 = {
|
|
452
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
453
|
+
seed?: number | string;
|
|
454
|
+
clock?: ClockControls$1;
|
|
455
|
+
/**
|
|
456
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
457
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
458
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
459
|
+
*/
|
|
460
|
+
virtualTime?: boolean;
|
|
461
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
462
|
+
latency?: Duration$1 | LatencyControls$1;
|
|
463
|
+
faults?: readonly FaultInput$1[];
|
|
464
|
+
/** Start from this state instead of the service's own seed data. */
|
|
465
|
+
snapshot?: SnapshotDocument$1;
|
|
466
|
+
};
|
|
467
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
468
|
+
type MockControls$1 = NamespaceControls$1 & {
|
|
469
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
470
|
+
credentials?: Record<string, string>;
|
|
471
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
472
|
+
namespaces?: Record<string, NamespaceControls$1>;
|
|
473
|
+
};
|
|
474
|
+
/** A latency rule in milliseconds. */
|
|
475
|
+
type LatencyRule$1 = {
|
|
476
|
+
delayMs: number;
|
|
477
|
+
jitterMs: number;
|
|
478
|
+
};
|
|
479
|
+
/** Baseline latency for a namespace, normalized. */
|
|
480
|
+
type LatencyState$1 = LatencyRule$1 & {
|
|
481
|
+
operations: Record<string, LatencyRule$1>;
|
|
482
|
+
};
|
|
483
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
484
|
+
type ControlHeaderInput$1 = {
|
|
485
|
+
namespace?: string;
|
|
486
|
+
adminKey?: string;
|
|
487
|
+
branch?: string;
|
|
488
|
+
at?: string;
|
|
489
|
+
reset?: boolean;
|
|
490
|
+
restore?: string;
|
|
491
|
+
seed?: number | string;
|
|
492
|
+
time?: Instant$1 | Date;
|
|
493
|
+
advance?: Duration$1;
|
|
494
|
+
virtualTime?: boolean;
|
|
495
|
+
delay?: Duration$1;
|
|
496
|
+
timeout?: Duration$1;
|
|
497
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
498
|
+
fault?: number | string | Record<string, unknown>;
|
|
499
|
+
snapshot?: string;
|
|
292
500
|
};
|
|
293
501
|
|
|
294
502
|
/**
|
|
@@ -328,6 +536,8 @@ type RequestLog$1 = {
|
|
|
328
536
|
unmatched: boolean;
|
|
329
537
|
/** Set when a fault rule produced the response. */
|
|
330
538
|
faultId?: string;
|
|
539
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
540
|
+
delayMs?: number;
|
|
331
541
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
332
542
|
ids?: Record<string, string>;
|
|
333
543
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -373,6 +583,12 @@ type JournalQuery$1 = {
|
|
|
373
583
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
374
584
|
namespace?: string;
|
|
375
585
|
operationId?: string;
|
|
586
|
+
/** Only this HTTP method, case-insensitive. */
|
|
587
|
+
method?: string;
|
|
588
|
+
/** Only this exact path. */
|
|
589
|
+
path?: string;
|
|
590
|
+
/** Only requests this fault rule answered or shaped. */
|
|
591
|
+
faultId?: string;
|
|
376
592
|
status?: number;
|
|
377
593
|
/** Only entries at or after this instant (epoch ms). */
|
|
378
594
|
since?: number;
|
|
@@ -387,6 +603,50 @@ type Journal$1 = {
|
|
|
387
603
|
clear(namespace?: string): void;
|
|
388
604
|
};
|
|
389
605
|
|
|
606
|
+
/**
|
|
607
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
608
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
609
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
610
|
+
* fault hits.
|
|
611
|
+
*/
|
|
612
|
+
type LatencyRegistry$1 = {
|
|
613
|
+
get(namespace: string): LatencyState$1;
|
|
614
|
+
set(namespace: string, state: LatencyState$1): LatencyState$1;
|
|
615
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
616
|
+
clear(namespace?: string): void;
|
|
617
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
618
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
/** Clock state as the admin API reports it. */
|
|
622
|
+
type ControlClock$1 = ClockState$1 & {
|
|
623
|
+
/** `now`, as ISO-8601. */
|
|
624
|
+
iso: string;
|
|
625
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
626
|
+
autoAdvanceMs: number;
|
|
627
|
+
};
|
|
628
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
629
|
+
type ControlState$1 = {
|
|
630
|
+
namespace: string;
|
|
631
|
+
seed: number | string;
|
|
632
|
+
clock: ControlClock$1;
|
|
633
|
+
virtualTime: boolean;
|
|
634
|
+
latency: LatencyState$1;
|
|
635
|
+
faults: FaultListing$1[];
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
639
|
+
type SnapshotInfo$1 = {
|
|
640
|
+
id: string;
|
|
641
|
+
namespace: string;
|
|
642
|
+
/** Stored rows in the snapshot. */
|
|
643
|
+
records: number;
|
|
644
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
645
|
+
at: number;
|
|
646
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
647
|
+
portable: boolean;
|
|
648
|
+
};
|
|
649
|
+
|
|
390
650
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
391
651
|
type CredentialRegistry$1 = {
|
|
392
652
|
set(credential: string, namespace: string): void;
|
|
@@ -541,7 +801,10 @@ type ServiceInstance$1 = FetchAPI$2 & {
|
|
|
541
801
|
};
|
|
542
802
|
type ServiceTimelineState$1 = Readonly<{
|
|
543
803
|
snapshot: NamespaceSnapshot$1;
|
|
544
|
-
clock
|
|
804
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
805
|
+
clock: Readonly<ClockState$1 & {
|
|
806
|
+
pinned?: boolean;
|
|
807
|
+
}>;
|
|
545
808
|
rngState: number;
|
|
546
809
|
}>;
|
|
547
810
|
type ServiceCheckpoint$1 = Checkpoint$1<ServiceTimelineState$1>;
|
|
@@ -554,14 +817,18 @@ type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$2 & {
|
|
|
554
817
|
readonly sqlite: SqliteClient$2;
|
|
555
818
|
readonly clock: Clock$1;
|
|
556
819
|
readonly faults: FaultRegistry$1;
|
|
820
|
+
/** Baseline response time per namespace. */
|
|
821
|
+
readonly latency: LatencyRegistry$1;
|
|
557
822
|
readonly metrics: Metrics$1;
|
|
558
823
|
readonly journal: Journal$1;
|
|
559
824
|
readonly rng: Rng$1;
|
|
560
825
|
readonly credentials: CredentialRegistry$1;
|
|
561
826
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
562
827
|
readonly webhooks: WebhookHub$1 | undefined;
|
|
563
|
-
/**
|
|
564
|
-
|
|
828
|
+
/**
|
|
829
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
830
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
831
|
+
*/
|
|
565
832
|
namespaceClock(namespace?: string): Clock$1;
|
|
566
833
|
namespaceOf(request: Request): string;
|
|
567
834
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -573,8 +840,38 @@ type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$2 & {
|
|
|
573
840
|
instance(namespace?: string): T;
|
|
574
841
|
/** Public names of every namespace created so far. */
|
|
575
842
|
namespaces(): string[];
|
|
576
|
-
/**
|
|
843
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
577
844
|
reset(namespace?: string): Promise<void>;
|
|
845
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
846
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
847
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
848
|
+
controls(namespace?: string): ControlState$1 & {
|
|
849
|
+
snapshots: SnapshotInfo$1[];
|
|
850
|
+
};
|
|
851
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
852
|
+
configure(controls: NamespaceControls$1, namespace?: string): ControlState$1 & {
|
|
853
|
+
snapshots: SnapshotInfo$1[];
|
|
854
|
+
};
|
|
855
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
856
|
+
readonly snapshots: {
|
|
857
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
858
|
+
create(options?: {
|
|
859
|
+
name?: string;
|
|
860
|
+
namespace?: string;
|
|
861
|
+
}): SnapshotInfo$1;
|
|
862
|
+
list(namespace?: string): SnapshotInfo$1[];
|
|
863
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
864
|
+
export(id: string, namespace?: string): SnapshotDocument$1;
|
|
865
|
+
/** Store a document as a snapshot without restoring it. */
|
|
866
|
+
import(document: SnapshotDocument$1, options?: {
|
|
867
|
+
name?: string;
|
|
868
|
+
namespace?: string;
|
|
869
|
+
}): SnapshotInfo$1;
|
|
870
|
+
restore(id: string, namespace?: string): void;
|
|
871
|
+
delete(id: string, namespace?: string): boolean;
|
|
872
|
+
};
|
|
873
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
874
|
+
headers(input: ControlHeaderInput$1): Record<string, string>;
|
|
578
875
|
snapshot(namespace?: string): NamespaceSnapshot$1;
|
|
579
876
|
restore(snapshot: NamespaceSnapshot$1, namespace?: string): void;
|
|
580
877
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -617,6 +914,8 @@ type CommonServeOptions = {
|
|
|
617
914
|
adminKey: string | undefined;
|
|
618
915
|
seed: string | undefined;
|
|
619
916
|
onLog: ((entry: RequestLog$1) => void) | undefined;
|
|
917
|
+
/** Admin controls to boot with: clock, latency, faults, a starting snapshot. */
|
|
918
|
+
adminControls?: MockControls$1;
|
|
620
919
|
/** Synthetic provider fixture objects supplied by a fleet entry. */
|
|
621
920
|
fixtures?: Record<string, unknown>;
|
|
622
921
|
baseUrl?: string;
|
|
@@ -837,7 +1136,7 @@ type ClockState = {
|
|
|
837
1136
|
now: number;
|
|
838
1137
|
/** True while time does not advance on its own. */
|
|
839
1138
|
frozen: boolean;
|
|
840
|
-
/** Milliseconds
|
|
1139
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
841
1140
|
offsetMs: number;
|
|
842
1141
|
};
|
|
843
1142
|
type Clock = {
|
|
@@ -873,7 +1172,10 @@ type Rng = {
|
|
|
873
1172
|
state(): number;
|
|
874
1173
|
/** Restore a state previously returned by {@link state}. */
|
|
875
1174
|
setState(state: number): void;
|
|
876
|
-
seed
|
|
1175
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
1176
|
+
reseed(seed: number | string): void;
|
|
1177
|
+
/** The seed the stream currently starts from. */
|
|
1178
|
+
readonly seed: number;
|
|
877
1179
|
};
|
|
878
1180
|
|
|
879
1181
|
/**
|
|
@@ -882,44 +1184,83 @@ type Rng = {
|
|
|
882
1184
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
883
1185
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
884
1186
|
* appears under load, the 5xx that proves a retry path works.
|
|
1187
|
+
*
|
|
1188
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
1189
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
1190
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
885
1191
|
*/
|
|
886
1192
|
type FaultRule = {
|
|
887
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
1193
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
888
1194
|
id: string;
|
|
889
1195
|
/** Fault only this operation. Omit to match every operation. */
|
|
890
1196
|
operationId?: string;
|
|
891
1197
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
892
1198
|
method?: string;
|
|
1199
|
+
/** Fault only this exact path. */
|
|
1200
|
+
path?: string;
|
|
893
1201
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
894
1202
|
pathPrefix?: string;
|
|
1203
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
1204
|
+
pathPattern?: string;
|
|
1205
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
1206
|
+
requestHeaders?: Record<string, string>;
|
|
1207
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
1208
|
+
query?: Record<string, string>;
|
|
895
1209
|
/**
|
|
896
1210
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
897
1211
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
898
1212
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
899
1213
|
*/
|
|
900
1214
|
namespace?: string;
|
|
1215
|
+
/** Let this many matching requests through first. */
|
|
1216
|
+
after?: number;
|
|
1217
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
1218
|
+
every?: number;
|
|
1219
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
1220
|
+
count?: number;
|
|
1221
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
1222
|
+
rate?: number;
|
|
1223
|
+
/**
|
|
1224
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
1225
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
1226
|
+
*/
|
|
1227
|
+
from?: Instant | Duration;
|
|
1228
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
1229
|
+
until?: Instant | Duration;
|
|
901
1230
|
/**
|
|
902
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
903
|
-
*
|
|
904
|
-
* the request then still reaches the service.
|
|
1231
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
1232
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
905
1233
|
*/
|
|
906
1234
|
status?: number;
|
|
907
1235
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
908
1236
|
body?: unknown;
|
|
1237
|
+
/** Response headers. */
|
|
909
1238
|
headers?: Record<string, string>;
|
|
910
|
-
/**
|
|
911
|
-
|
|
912
|
-
/**
|
|
913
|
-
rate?: number;
|
|
914
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
1239
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
1240
|
+
delay?: Duration;
|
|
1241
|
+
/** `delay`, in milliseconds. */
|
|
915
1242
|
delayMs?: number;
|
|
916
1243
|
/** Alias of `delayMs`. */
|
|
917
1244
|
latencyMs?: number;
|
|
1245
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
1246
|
+
jitter?: Duration;
|
|
1247
|
+
jitterMs?: number;
|
|
1248
|
+
/**
|
|
1249
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
1250
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
1251
|
+
*/
|
|
1252
|
+
timeout?: Duration;
|
|
1253
|
+
timeoutMs?: number;
|
|
918
1254
|
/**
|
|
919
1255
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
920
1256
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
921
1257
|
*/
|
|
922
1258
|
drop?: boolean;
|
|
1259
|
+
/**
|
|
1260
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
1261
|
+
* the connection dies mid-body.
|
|
1262
|
+
*/
|
|
1263
|
+
truncate?: number;
|
|
923
1264
|
/**
|
|
924
1265
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
925
1266
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -928,8 +1269,8 @@ type FaultRule = {
|
|
|
928
1269
|
effect?: string;
|
|
929
1270
|
/** Parameters for `effect`. */
|
|
930
1271
|
params?: Record<string, unknown>;
|
|
931
|
-
/**
|
|
932
|
-
|
|
1272
|
+
/** The preset this rule was expanded from, if any. */
|
|
1273
|
+
fromPreset?: string;
|
|
933
1274
|
};
|
|
934
1275
|
/** A fault that fired for one request. */
|
|
935
1276
|
type FaultHit = {
|
|
@@ -937,6 +1278,10 @@ type FaultHit = {
|
|
|
937
1278
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
938
1279
|
response?: Response;
|
|
939
1280
|
drop?: boolean;
|
|
1281
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
1282
|
+
timeout?: boolean;
|
|
1283
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
1284
|
+
truncate?: number;
|
|
940
1285
|
effect?: {
|
|
941
1286
|
name: string;
|
|
942
1287
|
params: Record<string, unknown>;
|
|
@@ -948,38 +1293,200 @@ type FaultCandidate = {
|
|
|
948
1293
|
method: string;
|
|
949
1294
|
path: string;
|
|
950
1295
|
namespace: string;
|
|
1296
|
+
/** Request headers and query, for rules that match on them. */
|
|
1297
|
+
headers?: Headers;
|
|
1298
|
+
query?: URLSearchParams;
|
|
1299
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
1300
|
+
now?: number;
|
|
1301
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
1302
|
+
wait?: (ms: number) => Promise<void>;
|
|
1303
|
+
};
|
|
1304
|
+
/** A stored rule and how often it was consulted. */
|
|
1305
|
+
type FaultListing = FaultRule & {
|
|
1306
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
1307
|
+
remaining: number | null;
|
|
1308
|
+
/** Times the rule faulted a request. */
|
|
1309
|
+
hits: number;
|
|
1310
|
+
/** Requests that matched the rule, faulted or not. */
|
|
1311
|
+
seen: number;
|
|
1312
|
+
};
|
|
1313
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
1314
|
+
type FaultSnapshot = {
|
|
1315
|
+
/**
|
|
1316
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
1317
|
+
* in the order means to a request and holds in any process.
|
|
1318
|
+
*/
|
|
1319
|
+
rules: (FaultListing & {
|
|
1320
|
+
position?: number;
|
|
1321
|
+
})[];
|
|
1322
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
1323
|
+
nextId?: number;
|
|
951
1324
|
};
|
|
952
1325
|
type FaultRegistry = {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
rules: (FaultRule & {
|
|
956
|
-
remaining: number | null;
|
|
957
|
-
hits: number;
|
|
958
|
-
position: number;
|
|
959
|
-
})[];
|
|
960
|
-
rngState: number;
|
|
961
|
-
};
|
|
1326
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
1327
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
962
1328
|
add(rule: FaultRule): FaultRule;
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
})[];
|
|
975
|
-
rngState: number;
|
|
976
|
-
}): void;
|
|
1329
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
1330
|
+
nextId(namespace: string): string;
|
|
1331
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
1332
|
+
list(namespace?: string): FaultListing[];
|
|
1333
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
1334
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
1335
|
+
remove(id: string, namespace?: string): boolean;
|
|
1336
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
1337
|
+
clear(namespace?: string): void;
|
|
1338
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
1339
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
977
1340
|
/**
|
|
978
1341
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
979
1342
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
980
1343
|
* each matching rule's remaining uses.
|
|
981
1344
|
*/
|
|
982
1345
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
1346
|
+
/**
|
|
1347
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
1348
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
1349
|
+
*/
|
|
1350
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* The admin controls every mock shares, as one document.
|
|
1355
|
+
*
|
|
1356
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
1357
|
+
*
|
|
1358
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
1359
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
1360
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
1361
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
1362
|
+
*
|
|
1363
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
1364
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
1365
|
+
*/
|
|
1366
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
1367
|
+
type Duration = number | string;
|
|
1368
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
1369
|
+
type Instant = number | string;
|
|
1370
|
+
type ClockControls = {
|
|
1371
|
+
/** Move the clock to this instant. */
|
|
1372
|
+
now?: Instant;
|
|
1373
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
1374
|
+
frozen?: boolean;
|
|
1375
|
+
/**
|
|
1376
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
1377
|
+
* each request still gets its own, reproducible timestamp.
|
|
1378
|
+
*/
|
|
1379
|
+
autoAdvance?: Duration;
|
|
1380
|
+
};
|
|
1381
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
1382
|
+
type LatencyRuleInput = {
|
|
1383
|
+
delay?: Duration;
|
|
1384
|
+
jitter?: Duration;
|
|
1385
|
+
};
|
|
1386
|
+
type LatencyControls = LatencyRuleInput & {
|
|
1387
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
1388
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
1389
|
+
};
|
|
1390
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
1391
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
1392
|
+
id?: string;
|
|
1393
|
+
}) | ({
|
|
1394
|
+
preset: string;
|
|
1395
|
+
} & Partial<FaultRule>);
|
|
1396
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
1397
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
1398
|
+
/**
|
|
1399
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
1400
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
1401
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
1402
|
+
*/
|
|
1403
|
+
type SnapshotDocument = {
|
|
1404
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
1405
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
1406
|
+
service?: string;
|
|
1407
|
+
/**
|
|
1408
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
1409
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
1410
|
+
*/
|
|
1411
|
+
records: {
|
|
1412
|
+
collection: string;
|
|
1413
|
+
id: string;
|
|
1414
|
+
seq?: number;
|
|
1415
|
+
value?: unknown;
|
|
1416
|
+
raw?: string;
|
|
1417
|
+
}[];
|
|
1418
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
1419
|
+
sequences?: {
|
|
1420
|
+
name: string;
|
|
1421
|
+
kind: string;
|
|
1422
|
+
value: number;
|
|
1423
|
+
}[];
|
|
1424
|
+
clock?: {
|
|
1425
|
+
now: number;
|
|
1426
|
+
frozen: boolean;
|
|
1427
|
+
autoAdvanceMs?: number;
|
|
1428
|
+
};
|
|
1429
|
+
seed?: number | string;
|
|
1430
|
+
/** Positions of the seeded random streams. */
|
|
1431
|
+
rng?: {
|
|
1432
|
+
state: number;
|
|
1433
|
+
faults?: number;
|
|
1434
|
+
latency?: number;
|
|
1435
|
+
};
|
|
1436
|
+
faults?: unknown;
|
|
1437
|
+
latency?: unknown;
|
|
1438
|
+
virtualTime?: boolean;
|
|
1439
|
+
};
|
|
1440
|
+
/** Controls for one namespace. */
|
|
1441
|
+
type NamespaceControls = {
|
|
1442
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
1443
|
+
seed?: number | string;
|
|
1444
|
+
clock?: ClockControls;
|
|
1445
|
+
/**
|
|
1446
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
1447
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
1448
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
1449
|
+
*/
|
|
1450
|
+
virtualTime?: boolean;
|
|
1451
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
1452
|
+
latency?: Duration | LatencyControls;
|
|
1453
|
+
faults?: readonly FaultInput[];
|
|
1454
|
+
/** Start from this state instead of the service's own seed data. */
|
|
1455
|
+
snapshot?: SnapshotDocument;
|
|
1456
|
+
};
|
|
1457
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
1458
|
+
type MockControls = NamespaceControls & {
|
|
1459
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
1460
|
+
credentials?: Record<string, string>;
|
|
1461
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
1462
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
1463
|
+
};
|
|
1464
|
+
/** A latency rule in milliseconds. */
|
|
1465
|
+
type LatencyRule = {
|
|
1466
|
+
delayMs: number;
|
|
1467
|
+
jitterMs: number;
|
|
1468
|
+
};
|
|
1469
|
+
/** Baseline latency for a namespace, normalized. */
|
|
1470
|
+
type LatencyState = LatencyRule & {
|
|
1471
|
+
operations: Record<string, LatencyRule>;
|
|
1472
|
+
};
|
|
1473
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
1474
|
+
type ControlHeaderInput = {
|
|
1475
|
+
namespace?: string;
|
|
1476
|
+
adminKey?: string;
|
|
1477
|
+
branch?: string;
|
|
1478
|
+
at?: string;
|
|
1479
|
+
reset?: boolean;
|
|
1480
|
+
restore?: string;
|
|
1481
|
+
seed?: number | string;
|
|
1482
|
+
time?: Instant | Date;
|
|
1483
|
+
advance?: Duration;
|
|
1484
|
+
virtualTime?: boolean;
|
|
1485
|
+
delay?: Duration;
|
|
1486
|
+
timeout?: Duration;
|
|
1487
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
1488
|
+
fault?: number | string | Record<string, unknown>;
|
|
1489
|
+
snapshot?: string;
|
|
983
1490
|
};
|
|
984
1491
|
|
|
985
1492
|
/**
|
|
@@ -1019,6 +1526,8 @@ type RequestLog = {
|
|
|
1019
1526
|
unmatched: boolean;
|
|
1020
1527
|
/** Set when a fault rule produced the response. */
|
|
1021
1528
|
faultId?: string;
|
|
1529
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
1530
|
+
delayMs?: number;
|
|
1022
1531
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
1023
1532
|
ids?: Record<string, string>;
|
|
1024
1533
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -1064,6 +1573,12 @@ type JournalQuery = {
|
|
|
1064
1573
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
1065
1574
|
namespace?: string;
|
|
1066
1575
|
operationId?: string;
|
|
1576
|
+
/** Only this HTTP method, case-insensitive. */
|
|
1577
|
+
method?: string;
|
|
1578
|
+
/** Only this exact path. */
|
|
1579
|
+
path?: string;
|
|
1580
|
+
/** Only requests this fault rule answered or shaped. */
|
|
1581
|
+
faultId?: string;
|
|
1067
1582
|
status?: number;
|
|
1068
1583
|
/** Only entries at or after this instant (epoch ms). */
|
|
1069
1584
|
since?: number;
|
|
@@ -1078,6 +1593,50 @@ type Journal = {
|
|
|
1078
1593
|
clear(namespace?: string): void;
|
|
1079
1594
|
};
|
|
1080
1595
|
|
|
1596
|
+
/**
|
|
1597
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
1598
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
1599
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
1600
|
+
* fault hits.
|
|
1601
|
+
*/
|
|
1602
|
+
type LatencyRegistry = {
|
|
1603
|
+
get(namespace: string): LatencyState;
|
|
1604
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
1605
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
1606
|
+
clear(namespace?: string): void;
|
|
1607
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
1608
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
1609
|
+
};
|
|
1610
|
+
|
|
1611
|
+
/** Clock state as the admin API reports it. */
|
|
1612
|
+
type ControlClock = ClockState & {
|
|
1613
|
+
/** `now`, as ISO-8601. */
|
|
1614
|
+
iso: string;
|
|
1615
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
1616
|
+
autoAdvanceMs: number;
|
|
1617
|
+
};
|
|
1618
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
1619
|
+
type ControlState = {
|
|
1620
|
+
namespace: string;
|
|
1621
|
+
seed: number | string;
|
|
1622
|
+
clock: ControlClock;
|
|
1623
|
+
virtualTime: boolean;
|
|
1624
|
+
latency: LatencyState;
|
|
1625
|
+
faults: FaultListing[];
|
|
1626
|
+
};
|
|
1627
|
+
|
|
1628
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
1629
|
+
type SnapshotInfo = {
|
|
1630
|
+
id: string;
|
|
1631
|
+
namespace: string;
|
|
1632
|
+
/** Stored rows in the snapshot. */
|
|
1633
|
+
records: number;
|
|
1634
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
1635
|
+
at: number;
|
|
1636
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
1637
|
+
portable: boolean;
|
|
1638
|
+
};
|
|
1639
|
+
|
|
1081
1640
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
1082
1641
|
type CredentialRegistry = {
|
|
1083
1642
|
set(credential: string, namespace: string): void;
|
|
@@ -1232,7 +1791,10 @@ type ServiceInstance = FetchAPI$1 & {
|
|
|
1232
1791
|
};
|
|
1233
1792
|
type ServiceTimelineState = Readonly<{
|
|
1234
1793
|
snapshot: NamespaceSnapshot;
|
|
1235
|
-
clock
|
|
1794
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
1795
|
+
clock: Readonly<ClockState & {
|
|
1796
|
+
pinned?: boolean;
|
|
1797
|
+
}>;
|
|
1236
1798
|
rngState: number;
|
|
1237
1799
|
}>;
|
|
1238
1800
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -1245,14 +1807,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
|
|
|
1245
1807
|
readonly sqlite: SqliteClient$1;
|
|
1246
1808
|
readonly clock: Clock;
|
|
1247
1809
|
readonly faults: FaultRegistry;
|
|
1810
|
+
/** Baseline response time per namespace. */
|
|
1811
|
+
readonly latency: LatencyRegistry;
|
|
1248
1812
|
readonly metrics: Metrics;
|
|
1249
1813
|
readonly journal: Journal;
|
|
1250
1814
|
readonly rng: Rng;
|
|
1251
1815
|
readonly credentials: CredentialRegistry;
|
|
1252
1816
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
1253
1817
|
readonly webhooks: WebhookHub | undefined;
|
|
1254
|
-
/**
|
|
1255
|
-
|
|
1818
|
+
/**
|
|
1819
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
1820
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
1821
|
+
*/
|
|
1256
1822
|
namespaceClock(namespace?: string): Clock;
|
|
1257
1823
|
namespaceOf(request: Request): string;
|
|
1258
1824
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -1264,8 +1830,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI$1 & {
|
|
|
1264
1830
|
instance(namespace?: string): T;
|
|
1265
1831
|
/** Public names of every namespace created so far. */
|
|
1266
1832
|
namespaces(): string[];
|
|
1267
|
-
/**
|
|
1833
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
1268
1834
|
reset(namespace?: string): Promise<void>;
|
|
1835
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
1836
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
1837
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
1838
|
+
controls(namespace?: string): ControlState & {
|
|
1839
|
+
snapshots: SnapshotInfo[];
|
|
1840
|
+
};
|
|
1841
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
1842
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
1843
|
+
snapshots: SnapshotInfo[];
|
|
1844
|
+
};
|
|
1845
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
1846
|
+
readonly snapshots: {
|
|
1847
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
1848
|
+
create(options?: {
|
|
1849
|
+
name?: string;
|
|
1850
|
+
namespace?: string;
|
|
1851
|
+
}): SnapshotInfo;
|
|
1852
|
+
list(namespace?: string): SnapshotInfo[];
|
|
1853
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
1854
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
1855
|
+
/** Store a document as a snapshot without restoring it. */
|
|
1856
|
+
import(document: SnapshotDocument, options?: {
|
|
1857
|
+
name?: string;
|
|
1858
|
+
namespace?: string;
|
|
1859
|
+
}): SnapshotInfo;
|
|
1860
|
+
restore(id: string, namespace?: string): void;
|
|
1861
|
+
delete(id: string, namespace?: string): boolean;
|
|
1862
|
+
};
|
|
1863
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
1864
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
1269
1865
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
1270
1866
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
1271
1867
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1404,6 +2000,8 @@ type WorkOSRuntimeOptions = Omit<WorkOSAPIOptions, "namespace" | "now"> & {
|
|
|
1404
2000
|
seed?: string | number;
|
|
1405
2001
|
adminPrefix?: string;
|
|
1406
2002
|
adminKey?: string;
|
|
2003
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
2004
|
+
adminControls?: MockControls;
|
|
1407
2005
|
onLog?: (entry: RequestLog) => void;
|
|
1408
2006
|
};
|
|
1409
2007
|
type WorkOSRuntime = ServiceRuntime<WorkOSAPI>;
|