@crvouga/mockingbird-service-ec2 1.2.0 → 1.3.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 +8 -2
- package/DISCOVERY.md +23 -0
- package/README.md +15 -3
- package/dist/chunk-LRCKCQY6.js +9284 -0
- package/dist/chunk-LRCKCQY6.js.map +7 -0
- package/dist/{chunk-DCLU5ICB.js → chunk-MG7Z5UZC.js} +136 -25
- package/dist/chunk-MG7Z5UZC.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-DCLU5ICB.js.map +0 -7
- package/dist/chunk-W6I7EHRT.js +0 -7492
- package/dist/chunk-W6I7EHRT.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;
|
|
@@ -882,7 +1181,7 @@ type ClockState = {
|
|
|
882
1181
|
now: number;
|
|
883
1182
|
/** True while time does not advance on its own. */
|
|
884
1183
|
frozen: boolean;
|
|
885
|
-
/** Milliseconds
|
|
1184
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
886
1185
|
offsetMs: number;
|
|
887
1186
|
};
|
|
888
1187
|
type Clock = {
|
|
@@ -918,7 +1217,10 @@ type Rng = {
|
|
|
918
1217
|
state(): number;
|
|
919
1218
|
/** Restore a state previously returned by {@link state}. */
|
|
920
1219
|
setState(state: number): void;
|
|
921
|
-
seed
|
|
1220
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
1221
|
+
reseed(seed: number | string): void;
|
|
1222
|
+
/** The seed the stream currently starts from. */
|
|
1223
|
+
readonly seed: number;
|
|
922
1224
|
};
|
|
923
1225
|
|
|
924
1226
|
/**
|
|
@@ -927,44 +1229,83 @@ type Rng = {
|
|
|
927
1229
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
928
1230
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
929
1231
|
* appears under load, the 5xx that proves a retry path works.
|
|
1232
|
+
*
|
|
1233
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
1234
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
1235
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
930
1236
|
*/
|
|
931
1237
|
type FaultRule = {
|
|
932
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
1238
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
933
1239
|
id: string;
|
|
934
1240
|
/** Fault only this operation. Omit to match every operation. */
|
|
935
1241
|
operationId?: string;
|
|
936
1242
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
937
1243
|
method?: string;
|
|
1244
|
+
/** Fault only this exact path. */
|
|
1245
|
+
path?: string;
|
|
938
1246
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
939
1247
|
pathPrefix?: string;
|
|
1248
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
1249
|
+
pathPattern?: string;
|
|
1250
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
1251
|
+
requestHeaders?: Record<string, string>;
|
|
1252
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
1253
|
+
query?: Record<string, string>;
|
|
940
1254
|
/**
|
|
941
1255
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
942
1256
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
943
1257
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
944
1258
|
*/
|
|
945
1259
|
namespace?: string;
|
|
1260
|
+
/** Let this many matching requests through first. */
|
|
1261
|
+
after?: number;
|
|
1262
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
1263
|
+
every?: number;
|
|
1264
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
1265
|
+
count?: number;
|
|
1266
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
1267
|
+
rate?: number;
|
|
1268
|
+
/**
|
|
1269
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
1270
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
1271
|
+
*/
|
|
1272
|
+
from?: Instant | Duration;
|
|
1273
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
1274
|
+
until?: Instant | Duration;
|
|
946
1275
|
/**
|
|
947
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
948
|
-
*
|
|
949
|
-
* the request then still reaches the service.
|
|
1276
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
1277
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
950
1278
|
*/
|
|
951
1279
|
status?: number;
|
|
952
1280
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
953
1281
|
body?: unknown;
|
|
1282
|
+
/** Response headers. */
|
|
954
1283
|
headers?: Record<string, string>;
|
|
955
|
-
/**
|
|
956
|
-
|
|
957
|
-
/**
|
|
958
|
-
rate?: number;
|
|
959
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
1284
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
1285
|
+
delay?: Duration;
|
|
1286
|
+
/** `delay`, in milliseconds. */
|
|
960
1287
|
delayMs?: number;
|
|
961
1288
|
/** Alias of `delayMs`. */
|
|
962
1289
|
latencyMs?: number;
|
|
1290
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
1291
|
+
jitter?: Duration;
|
|
1292
|
+
jitterMs?: number;
|
|
1293
|
+
/**
|
|
1294
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
1295
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
1296
|
+
*/
|
|
1297
|
+
timeout?: Duration;
|
|
1298
|
+
timeoutMs?: number;
|
|
963
1299
|
/**
|
|
964
1300
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
965
1301
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
966
1302
|
*/
|
|
967
1303
|
drop?: boolean;
|
|
1304
|
+
/**
|
|
1305
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
1306
|
+
* the connection dies mid-body.
|
|
1307
|
+
*/
|
|
1308
|
+
truncate?: number;
|
|
968
1309
|
/**
|
|
969
1310
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
970
1311
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -973,8 +1314,8 @@ type FaultRule = {
|
|
|
973
1314
|
effect?: string;
|
|
974
1315
|
/** Parameters for `effect`. */
|
|
975
1316
|
params?: Record<string, unknown>;
|
|
976
|
-
/**
|
|
977
|
-
|
|
1317
|
+
/** The preset this rule was expanded from, if any. */
|
|
1318
|
+
fromPreset?: string;
|
|
978
1319
|
};
|
|
979
1320
|
/** A fault that fired for one request. */
|
|
980
1321
|
type FaultHit = {
|
|
@@ -982,6 +1323,10 @@ type FaultHit = {
|
|
|
982
1323
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
983
1324
|
response?: Response;
|
|
984
1325
|
drop?: boolean;
|
|
1326
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
1327
|
+
timeout?: boolean;
|
|
1328
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
1329
|
+
truncate?: number;
|
|
985
1330
|
effect?: {
|
|
986
1331
|
name: string;
|
|
987
1332
|
params: Record<string, unknown>;
|
|
@@ -993,38 +1338,200 @@ type FaultCandidate = {
|
|
|
993
1338
|
method: string;
|
|
994
1339
|
path: string;
|
|
995
1340
|
namespace: string;
|
|
1341
|
+
/** Request headers and query, for rules that match on them. */
|
|
1342
|
+
headers?: Headers;
|
|
1343
|
+
query?: URLSearchParams;
|
|
1344
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
1345
|
+
now?: number;
|
|
1346
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
1347
|
+
wait?: (ms: number) => Promise<void>;
|
|
1348
|
+
};
|
|
1349
|
+
/** A stored rule and how often it was consulted. */
|
|
1350
|
+
type FaultListing = FaultRule & {
|
|
1351
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
1352
|
+
remaining: number | null;
|
|
1353
|
+
/** Times the rule faulted a request. */
|
|
1354
|
+
hits: number;
|
|
1355
|
+
/** Requests that matched the rule, faulted or not. */
|
|
1356
|
+
seen: number;
|
|
1357
|
+
};
|
|
1358
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
1359
|
+
type FaultSnapshot = {
|
|
1360
|
+
/**
|
|
1361
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
1362
|
+
* in the order means to a request and holds in any process.
|
|
1363
|
+
*/
|
|
1364
|
+
rules: (FaultListing & {
|
|
1365
|
+
position?: number;
|
|
1366
|
+
})[];
|
|
1367
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
1368
|
+
nextId?: number;
|
|
996
1369
|
};
|
|
997
1370
|
type FaultRegistry = {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
rules: (FaultRule & {
|
|
1001
|
-
remaining: number | null;
|
|
1002
|
-
hits: number;
|
|
1003
|
-
position: number;
|
|
1004
|
-
})[];
|
|
1005
|
-
rngState: number;
|
|
1006
|
-
};
|
|
1371
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
1372
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
1007
1373
|
add(rule: FaultRule): FaultRule;
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
})[];
|
|
1020
|
-
rngState: number;
|
|
1021
|
-
}): void;
|
|
1374
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
1375
|
+
nextId(namespace: string): string;
|
|
1376
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
1377
|
+
list(namespace?: string): FaultListing[];
|
|
1378
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
1379
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
1380
|
+
remove(id: string, namespace?: string): boolean;
|
|
1381
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
1382
|
+
clear(namespace?: string): void;
|
|
1383
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
1384
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
1022
1385
|
/**
|
|
1023
1386
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
1024
1387
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
1025
1388
|
* each matching rule's remaining uses.
|
|
1026
1389
|
*/
|
|
1027
1390
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
1391
|
+
/**
|
|
1392
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
1393
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
1394
|
+
*/
|
|
1395
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
1396
|
+
};
|
|
1397
|
+
|
|
1398
|
+
/**
|
|
1399
|
+
* The admin controls every mock shares, as one document.
|
|
1400
|
+
*
|
|
1401
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
1402
|
+
*
|
|
1403
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
1404
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
1405
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
1406
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
1407
|
+
*
|
|
1408
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
1409
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
1410
|
+
*/
|
|
1411
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
1412
|
+
type Duration = number | string;
|
|
1413
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
1414
|
+
type Instant = number | string;
|
|
1415
|
+
type ClockControls = {
|
|
1416
|
+
/** Move the clock to this instant. */
|
|
1417
|
+
now?: Instant;
|
|
1418
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
1419
|
+
frozen?: boolean;
|
|
1420
|
+
/**
|
|
1421
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
1422
|
+
* each request still gets its own, reproducible timestamp.
|
|
1423
|
+
*/
|
|
1424
|
+
autoAdvance?: Duration;
|
|
1425
|
+
};
|
|
1426
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
1427
|
+
type LatencyRuleInput = {
|
|
1428
|
+
delay?: Duration;
|
|
1429
|
+
jitter?: Duration;
|
|
1430
|
+
};
|
|
1431
|
+
type LatencyControls = LatencyRuleInput & {
|
|
1432
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
1433
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
1434
|
+
};
|
|
1435
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
1436
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
1437
|
+
id?: string;
|
|
1438
|
+
}) | ({
|
|
1439
|
+
preset: string;
|
|
1440
|
+
} & Partial<FaultRule>);
|
|
1441
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
1442
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
1443
|
+
/**
|
|
1444
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
1445
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
1446
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
1447
|
+
*/
|
|
1448
|
+
type SnapshotDocument = {
|
|
1449
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
1450
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
1451
|
+
service?: string;
|
|
1452
|
+
/**
|
|
1453
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
1454
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
1455
|
+
*/
|
|
1456
|
+
records: {
|
|
1457
|
+
collection: string;
|
|
1458
|
+
id: string;
|
|
1459
|
+
seq?: number;
|
|
1460
|
+
value?: unknown;
|
|
1461
|
+
raw?: string;
|
|
1462
|
+
}[];
|
|
1463
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
1464
|
+
sequences?: {
|
|
1465
|
+
name: string;
|
|
1466
|
+
kind: string;
|
|
1467
|
+
value: number;
|
|
1468
|
+
}[];
|
|
1469
|
+
clock?: {
|
|
1470
|
+
now: number;
|
|
1471
|
+
frozen: boolean;
|
|
1472
|
+
autoAdvanceMs?: number;
|
|
1473
|
+
};
|
|
1474
|
+
seed?: number | string;
|
|
1475
|
+
/** Positions of the seeded random streams. */
|
|
1476
|
+
rng?: {
|
|
1477
|
+
state: number;
|
|
1478
|
+
faults?: number;
|
|
1479
|
+
latency?: number;
|
|
1480
|
+
};
|
|
1481
|
+
faults?: unknown;
|
|
1482
|
+
latency?: unknown;
|
|
1483
|
+
virtualTime?: boolean;
|
|
1484
|
+
};
|
|
1485
|
+
/** Controls for one namespace. */
|
|
1486
|
+
type NamespaceControls = {
|
|
1487
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
1488
|
+
seed?: number | string;
|
|
1489
|
+
clock?: ClockControls;
|
|
1490
|
+
/**
|
|
1491
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
1492
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
1493
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
1494
|
+
*/
|
|
1495
|
+
virtualTime?: boolean;
|
|
1496
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
1497
|
+
latency?: Duration | LatencyControls;
|
|
1498
|
+
faults?: readonly FaultInput[];
|
|
1499
|
+
/** Start from this state instead of the service's own seed data. */
|
|
1500
|
+
snapshot?: SnapshotDocument;
|
|
1501
|
+
};
|
|
1502
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
1503
|
+
type MockControls = NamespaceControls & {
|
|
1504
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
1505
|
+
credentials?: Record<string, string>;
|
|
1506
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
1507
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
1508
|
+
};
|
|
1509
|
+
/** A latency rule in milliseconds. */
|
|
1510
|
+
type LatencyRule = {
|
|
1511
|
+
delayMs: number;
|
|
1512
|
+
jitterMs: number;
|
|
1513
|
+
};
|
|
1514
|
+
/** Baseline latency for a namespace, normalized. */
|
|
1515
|
+
type LatencyState = LatencyRule & {
|
|
1516
|
+
operations: Record<string, LatencyRule>;
|
|
1517
|
+
};
|
|
1518
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
1519
|
+
type ControlHeaderInput = {
|
|
1520
|
+
namespace?: string;
|
|
1521
|
+
adminKey?: string;
|
|
1522
|
+
branch?: string;
|
|
1523
|
+
at?: string;
|
|
1524
|
+
reset?: boolean;
|
|
1525
|
+
restore?: string;
|
|
1526
|
+
seed?: number | string;
|
|
1527
|
+
time?: Instant | Date;
|
|
1528
|
+
advance?: Duration;
|
|
1529
|
+
virtualTime?: boolean;
|
|
1530
|
+
delay?: Duration;
|
|
1531
|
+
timeout?: Duration;
|
|
1532
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
1533
|
+
fault?: number | string | Record<string, unknown>;
|
|
1534
|
+
snapshot?: string;
|
|
1028
1535
|
};
|
|
1029
1536
|
|
|
1030
1537
|
/**
|
|
@@ -1064,6 +1571,8 @@ type RequestLog = {
|
|
|
1064
1571
|
unmatched: boolean;
|
|
1065
1572
|
/** Set when a fault rule produced the response. */
|
|
1066
1573
|
faultId?: string;
|
|
1574
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
1575
|
+
delayMs?: number;
|
|
1067
1576
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
1068
1577
|
ids?: Record<string, string>;
|
|
1069
1578
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -1109,6 +1618,12 @@ type JournalQuery = {
|
|
|
1109
1618
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
1110
1619
|
namespace?: string;
|
|
1111
1620
|
operationId?: string;
|
|
1621
|
+
/** Only this HTTP method, case-insensitive. */
|
|
1622
|
+
method?: string;
|
|
1623
|
+
/** Only this exact path. */
|
|
1624
|
+
path?: string;
|
|
1625
|
+
/** Only requests this fault rule answered or shaped. */
|
|
1626
|
+
faultId?: string;
|
|
1112
1627
|
status?: number;
|
|
1113
1628
|
/** Only entries at or after this instant (epoch ms). */
|
|
1114
1629
|
since?: number;
|
|
@@ -1123,6 +1638,50 @@ type Journal = {
|
|
|
1123
1638
|
clear(namespace?: string): void;
|
|
1124
1639
|
};
|
|
1125
1640
|
|
|
1641
|
+
/**
|
|
1642
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
1643
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
1644
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
1645
|
+
* fault hits.
|
|
1646
|
+
*/
|
|
1647
|
+
type LatencyRegistry = {
|
|
1648
|
+
get(namespace: string): LatencyState;
|
|
1649
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
1650
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
1651
|
+
clear(namespace?: string): void;
|
|
1652
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
1653
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
1654
|
+
};
|
|
1655
|
+
|
|
1656
|
+
/** Clock state as the admin API reports it. */
|
|
1657
|
+
type ControlClock = ClockState & {
|
|
1658
|
+
/** `now`, as ISO-8601. */
|
|
1659
|
+
iso: string;
|
|
1660
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
1661
|
+
autoAdvanceMs: number;
|
|
1662
|
+
};
|
|
1663
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
1664
|
+
type ControlState = {
|
|
1665
|
+
namespace: string;
|
|
1666
|
+
seed: number | string;
|
|
1667
|
+
clock: ControlClock;
|
|
1668
|
+
virtualTime: boolean;
|
|
1669
|
+
latency: LatencyState;
|
|
1670
|
+
faults: FaultListing[];
|
|
1671
|
+
};
|
|
1672
|
+
|
|
1673
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
1674
|
+
type SnapshotInfo = {
|
|
1675
|
+
id: string;
|
|
1676
|
+
namespace: string;
|
|
1677
|
+
/** Stored rows in the snapshot. */
|
|
1678
|
+
records: number;
|
|
1679
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
1680
|
+
at: number;
|
|
1681
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
1682
|
+
portable: boolean;
|
|
1683
|
+
};
|
|
1684
|
+
|
|
1126
1685
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
1127
1686
|
type CredentialRegistry = {
|
|
1128
1687
|
set(credential: string, namespace: string): void;
|
|
@@ -1277,7 +1836,10 @@ type ServiceInstance = FetchAPI & {
|
|
|
1277
1836
|
};
|
|
1278
1837
|
type ServiceTimelineState = Readonly<{
|
|
1279
1838
|
snapshot: NamespaceSnapshot;
|
|
1280
|
-
clock
|
|
1839
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
1840
|
+
clock: Readonly<ClockState & {
|
|
1841
|
+
pinned?: boolean;
|
|
1842
|
+
}>;
|
|
1281
1843
|
rngState: number;
|
|
1282
1844
|
}>;
|
|
1283
1845
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -1290,14 +1852,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
1290
1852
|
readonly sqlite: SqliteClient$1;
|
|
1291
1853
|
readonly clock: Clock;
|
|
1292
1854
|
readonly faults: FaultRegistry;
|
|
1855
|
+
/** Baseline response time per namespace. */
|
|
1856
|
+
readonly latency: LatencyRegistry;
|
|
1293
1857
|
readonly metrics: Metrics;
|
|
1294
1858
|
readonly journal: Journal;
|
|
1295
1859
|
readonly rng: Rng;
|
|
1296
1860
|
readonly credentials: CredentialRegistry;
|
|
1297
1861
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
1298
1862
|
readonly webhooks: WebhookHub | undefined;
|
|
1299
|
-
/**
|
|
1300
|
-
|
|
1863
|
+
/**
|
|
1864
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
1865
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
1866
|
+
*/
|
|
1301
1867
|
namespaceClock(namespace?: string): Clock;
|
|
1302
1868
|
namespaceOf(request: Request): string;
|
|
1303
1869
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -1309,8 +1875,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
1309
1875
|
instance(namespace?: string): T;
|
|
1310
1876
|
/** Public names of every namespace created so far. */
|
|
1311
1877
|
namespaces(): string[];
|
|
1312
|
-
/**
|
|
1878
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
1313
1879
|
reset(namespace?: string): Promise<void>;
|
|
1880
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
1881
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
1882
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
1883
|
+
controls(namespace?: string): ControlState & {
|
|
1884
|
+
snapshots: SnapshotInfo[];
|
|
1885
|
+
};
|
|
1886
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
1887
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
1888
|
+
snapshots: SnapshotInfo[];
|
|
1889
|
+
};
|
|
1890
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
1891
|
+
readonly snapshots: {
|
|
1892
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
1893
|
+
create(options?: {
|
|
1894
|
+
name?: string;
|
|
1895
|
+
namespace?: string;
|
|
1896
|
+
}): SnapshotInfo;
|
|
1897
|
+
list(namespace?: string): SnapshotInfo[];
|
|
1898
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
1899
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
1900
|
+
/** Store a document as a snapshot without restoring it. */
|
|
1901
|
+
import(document: SnapshotDocument, options?: {
|
|
1902
|
+
name?: string;
|
|
1903
|
+
namespace?: string;
|
|
1904
|
+
}): SnapshotInfo;
|
|
1905
|
+
restore(id: string, namespace?: string): void;
|
|
1906
|
+
delete(id: string, namespace?: string): boolean;
|
|
1907
|
+
};
|
|
1908
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
1909
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
1314
1910
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
1315
1911
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
1316
1912
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1374,6 +1970,8 @@ type RuntimeOptions = {
|
|
|
1374
1970
|
accountId?: string;
|
|
1375
1971
|
adminPrefix?: string;
|
|
1376
1972
|
adminKey?: string;
|
|
1973
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1974
|
+
adminControls?: MockControls;
|
|
1377
1975
|
onLog?: (entry: RequestLog) => void;
|
|
1378
1976
|
};
|
|
1379
1977
|
type Runtime = ServiceRuntime<Ec2API>;
|