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