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