@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/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -228,7 +228,7 @@ type ClockState = {
|
|
|
228
228
|
now: number;
|
|
229
229
|
/** True while time does not advance on its own. */
|
|
230
230
|
frozen: boolean;
|
|
231
|
-
/** Milliseconds
|
|
231
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
232
232
|
offsetMs: number;
|
|
233
233
|
};
|
|
234
234
|
type Clock = {
|
|
@@ -264,7 +264,10 @@ type Rng = {
|
|
|
264
264
|
state(): number;
|
|
265
265
|
/** Restore a state previously returned by {@link state}. */
|
|
266
266
|
setState(state: number): void;
|
|
267
|
-
seed
|
|
267
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
268
|
+
reseed(seed: number | string): void;
|
|
269
|
+
/** The seed the stream currently starts from. */
|
|
270
|
+
readonly seed: number;
|
|
268
271
|
};
|
|
269
272
|
|
|
270
273
|
/**
|
|
@@ -273,44 +276,83 @@ type Rng = {
|
|
|
273
276
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
274
277
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
275
278
|
* appears under load, the 5xx that proves a retry path works.
|
|
279
|
+
*
|
|
280
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
281
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
282
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
276
283
|
*/
|
|
277
284
|
type FaultRule = {
|
|
278
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
285
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
279
286
|
id: string;
|
|
280
287
|
/** Fault only this operation. Omit to match every operation. */
|
|
281
288
|
operationId?: string;
|
|
282
289
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
283
290
|
method?: string;
|
|
291
|
+
/** Fault only this exact path. */
|
|
292
|
+
path?: string;
|
|
284
293
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
285
294
|
pathPrefix?: string;
|
|
295
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
296
|
+
pathPattern?: string;
|
|
297
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
298
|
+
requestHeaders?: Record<string, string>;
|
|
299
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
300
|
+
query?: Record<string, string>;
|
|
286
301
|
/**
|
|
287
302
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
288
303
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
289
304
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
290
305
|
*/
|
|
291
306
|
namespace?: string;
|
|
307
|
+
/** Let this many matching requests through first. */
|
|
308
|
+
after?: number;
|
|
309
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
310
|
+
every?: number;
|
|
311
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
312
|
+
count?: number;
|
|
313
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
314
|
+
rate?: number;
|
|
315
|
+
/**
|
|
316
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
317
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
318
|
+
*/
|
|
319
|
+
from?: Instant | Duration;
|
|
320
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
321
|
+
until?: Instant | Duration;
|
|
292
322
|
/**
|
|
293
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
294
|
-
*
|
|
295
|
-
* the request then still reaches the service.
|
|
323
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
324
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
296
325
|
*/
|
|
297
326
|
status?: number;
|
|
298
327
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
299
328
|
body?: unknown;
|
|
329
|
+
/** Response headers. */
|
|
300
330
|
headers?: Record<string, string>;
|
|
301
|
-
/**
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
rate?: number;
|
|
305
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
331
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
332
|
+
delay?: Duration;
|
|
333
|
+
/** `delay`, in milliseconds. */
|
|
306
334
|
delayMs?: number;
|
|
307
335
|
/** Alias of `delayMs`. */
|
|
308
336
|
latencyMs?: number;
|
|
337
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
338
|
+
jitter?: Duration;
|
|
339
|
+
jitterMs?: number;
|
|
340
|
+
/**
|
|
341
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
342
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
343
|
+
*/
|
|
344
|
+
timeout?: Duration;
|
|
345
|
+
timeoutMs?: number;
|
|
309
346
|
/**
|
|
310
347
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
311
348
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
312
349
|
*/
|
|
313
350
|
drop?: boolean;
|
|
351
|
+
/**
|
|
352
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
353
|
+
* the connection dies mid-body.
|
|
354
|
+
*/
|
|
355
|
+
truncate?: number;
|
|
314
356
|
/**
|
|
315
357
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
316
358
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -319,8 +361,8 @@ type FaultRule = {
|
|
|
319
361
|
effect?: string;
|
|
320
362
|
/** Parameters for `effect`. */
|
|
321
363
|
params?: Record<string, unknown>;
|
|
322
|
-
/**
|
|
323
|
-
|
|
364
|
+
/** The preset this rule was expanded from, if any. */
|
|
365
|
+
fromPreset?: string;
|
|
324
366
|
};
|
|
325
367
|
/** A fault that fired for one request. */
|
|
326
368
|
type FaultHit = {
|
|
@@ -328,6 +370,10 @@ type FaultHit = {
|
|
|
328
370
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
329
371
|
response?: Response;
|
|
330
372
|
drop?: boolean;
|
|
373
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
374
|
+
timeout?: boolean;
|
|
375
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
376
|
+
truncate?: number;
|
|
331
377
|
effect?: {
|
|
332
378
|
name: string;
|
|
333
379
|
params: Record<string, unknown>;
|
|
@@ -352,38 +398,200 @@ type FaultCandidate = {
|
|
|
352
398
|
method: string;
|
|
353
399
|
path: string;
|
|
354
400
|
namespace: string;
|
|
401
|
+
/** Request headers and query, for rules that match on them. */
|
|
402
|
+
headers?: Headers;
|
|
403
|
+
query?: URLSearchParams;
|
|
404
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
405
|
+
now?: number;
|
|
406
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
407
|
+
wait?: (ms: number) => Promise<void>;
|
|
408
|
+
};
|
|
409
|
+
/** A stored rule and how often it was consulted. */
|
|
410
|
+
type FaultListing = FaultRule & {
|
|
411
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
412
|
+
remaining: number | null;
|
|
413
|
+
/** Times the rule faulted a request. */
|
|
414
|
+
hits: number;
|
|
415
|
+
/** Requests that matched the rule, faulted or not. */
|
|
416
|
+
seen: number;
|
|
417
|
+
};
|
|
418
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
419
|
+
type FaultSnapshot = {
|
|
420
|
+
/**
|
|
421
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
422
|
+
* in the order means to a request and holds in any process.
|
|
423
|
+
*/
|
|
424
|
+
rules: (FaultListing & {
|
|
425
|
+
position?: number;
|
|
426
|
+
})[];
|
|
427
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
428
|
+
nextId?: number;
|
|
355
429
|
};
|
|
356
430
|
type FaultRegistry = {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
rules: (FaultRule & {
|
|
360
|
-
remaining: number | null;
|
|
361
|
-
hits: number;
|
|
362
|
-
position: number;
|
|
363
|
-
})[];
|
|
364
|
-
rngState: number;
|
|
365
|
-
};
|
|
431
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
432
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
366
433
|
add(rule: FaultRule): FaultRule;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
})[];
|
|
379
|
-
rngState: number;
|
|
380
|
-
}): void;
|
|
434
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
435
|
+
nextId(namespace: string): string;
|
|
436
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
437
|
+
list(namespace?: string): FaultListing[];
|
|
438
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
439
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
440
|
+
remove(id: string, namespace?: string): boolean;
|
|
441
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
442
|
+
clear(namespace?: string): void;
|
|
443
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
444
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
381
445
|
/**
|
|
382
446
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
383
447
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
384
448
|
* each matching rule's remaining uses.
|
|
385
449
|
*/
|
|
386
450
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
451
|
+
/**
|
|
452
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
453
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
454
|
+
*/
|
|
455
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* The admin controls every mock shares, as one document.
|
|
460
|
+
*
|
|
461
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
462
|
+
*
|
|
463
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
464
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
465
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
466
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
467
|
+
*
|
|
468
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
469
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
470
|
+
*/
|
|
471
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
472
|
+
type Duration = number | string;
|
|
473
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
474
|
+
type Instant = number | string;
|
|
475
|
+
type ClockControls = {
|
|
476
|
+
/** Move the clock to this instant. */
|
|
477
|
+
now?: Instant;
|
|
478
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
479
|
+
frozen?: boolean;
|
|
480
|
+
/**
|
|
481
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
482
|
+
* each request still gets its own, reproducible timestamp.
|
|
483
|
+
*/
|
|
484
|
+
autoAdvance?: Duration;
|
|
485
|
+
};
|
|
486
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
487
|
+
type LatencyRuleInput = {
|
|
488
|
+
delay?: Duration;
|
|
489
|
+
jitter?: Duration;
|
|
490
|
+
};
|
|
491
|
+
type LatencyControls = LatencyRuleInput & {
|
|
492
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
493
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
494
|
+
};
|
|
495
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
496
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
497
|
+
id?: string;
|
|
498
|
+
}) | ({
|
|
499
|
+
preset: string;
|
|
500
|
+
} & Partial<FaultRule>);
|
|
501
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
502
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
503
|
+
/**
|
|
504
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
505
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
506
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
507
|
+
*/
|
|
508
|
+
type SnapshotDocument = {
|
|
509
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
510
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
511
|
+
service?: string;
|
|
512
|
+
/**
|
|
513
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
514
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
515
|
+
*/
|
|
516
|
+
records: {
|
|
517
|
+
collection: string;
|
|
518
|
+
id: string;
|
|
519
|
+
seq?: number;
|
|
520
|
+
value?: unknown;
|
|
521
|
+
raw?: string;
|
|
522
|
+
}[];
|
|
523
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
524
|
+
sequences?: {
|
|
525
|
+
name: string;
|
|
526
|
+
kind: string;
|
|
527
|
+
value: number;
|
|
528
|
+
}[];
|
|
529
|
+
clock?: {
|
|
530
|
+
now: number;
|
|
531
|
+
frozen: boolean;
|
|
532
|
+
autoAdvanceMs?: number;
|
|
533
|
+
};
|
|
534
|
+
seed?: number | string;
|
|
535
|
+
/** Positions of the seeded random streams. */
|
|
536
|
+
rng?: {
|
|
537
|
+
state: number;
|
|
538
|
+
faults?: number;
|
|
539
|
+
latency?: number;
|
|
540
|
+
};
|
|
541
|
+
faults?: unknown;
|
|
542
|
+
latency?: unknown;
|
|
543
|
+
virtualTime?: boolean;
|
|
544
|
+
};
|
|
545
|
+
/** Controls for one namespace. */
|
|
546
|
+
type NamespaceControls = {
|
|
547
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
548
|
+
seed?: number | string;
|
|
549
|
+
clock?: ClockControls;
|
|
550
|
+
/**
|
|
551
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
552
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
553
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
554
|
+
*/
|
|
555
|
+
virtualTime?: boolean;
|
|
556
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
557
|
+
latency?: Duration | LatencyControls;
|
|
558
|
+
faults?: readonly FaultInput[];
|
|
559
|
+
/** Start from this state instead of the service's own seed data. */
|
|
560
|
+
snapshot?: SnapshotDocument;
|
|
561
|
+
};
|
|
562
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
563
|
+
type MockControls = NamespaceControls & {
|
|
564
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
565
|
+
credentials?: Record<string, string>;
|
|
566
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
567
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
568
|
+
};
|
|
569
|
+
/** A latency rule in milliseconds. */
|
|
570
|
+
type LatencyRule = {
|
|
571
|
+
delayMs: number;
|
|
572
|
+
jitterMs: number;
|
|
573
|
+
};
|
|
574
|
+
/** Baseline latency for a namespace, normalized. */
|
|
575
|
+
type LatencyState = LatencyRule & {
|
|
576
|
+
operations: Record<string, LatencyRule>;
|
|
577
|
+
};
|
|
578
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
579
|
+
type ControlHeaderInput = {
|
|
580
|
+
namespace?: string;
|
|
581
|
+
adminKey?: string;
|
|
582
|
+
branch?: string;
|
|
583
|
+
at?: string;
|
|
584
|
+
reset?: boolean;
|
|
585
|
+
restore?: string;
|
|
586
|
+
seed?: number | string;
|
|
587
|
+
time?: Instant | Date;
|
|
588
|
+
advance?: Duration;
|
|
589
|
+
virtualTime?: boolean;
|
|
590
|
+
delay?: Duration;
|
|
591
|
+
timeout?: Duration;
|
|
592
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
593
|
+
fault?: number | string | Record<string, unknown>;
|
|
594
|
+
snapshot?: string;
|
|
387
595
|
};
|
|
388
596
|
|
|
389
597
|
/**
|
|
@@ -423,6 +631,8 @@ type RequestLog = {
|
|
|
423
631
|
unmatched: boolean;
|
|
424
632
|
/** Set when a fault rule produced the response. */
|
|
425
633
|
faultId?: string;
|
|
634
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
635
|
+
delayMs?: number;
|
|
426
636
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
427
637
|
ids?: Record<string, string>;
|
|
428
638
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -468,6 +678,12 @@ type JournalQuery = {
|
|
|
468
678
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
469
679
|
namespace?: string;
|
|
470
680
|
operationId?: string;
|
|
681
|
+
/** Only this HTTP method, case-insensitive. */
|
|
682
|
+
method?: string;
|
|
683
|
+
/** Only this exact path. */
|
|
684
|
+
path?: string;
|
|
685
|
+
/** Only requests this fault rule answered or shaped. */
|
|
686
|
+
faultId?: string;
|
|
471
687
|
status?: number;
|
|
472
688
|
/** Only entries at or after this instant (epoch ms). */
|
|
473
689
|
since?: number;
|
|
@@ -482,6 +698,50 @@ type Journal = {
|
|
|
482
698
|
clear(namespace?: string): void;
|
|
483
699
|
};
|
|
484
700
|
|
|
701
|
+
/**
|
|
702
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
703
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
704
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
705
|
+
* fault hits.
|
|
706
|
+
*/
|
|
707
|
+
type LatencyRegistry = {
|
|
708
|
+
get(namespace: string): LatencyState;
|
|
709
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
710
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
711
|
+
clear(namespace?: string): void;
|
|
712
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
713
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
/** Clock state as the admin API reports it. */
|
|
717
|
+
type ControlClock = ClockState & {
|
|
718
|
+
/** `now`, as ISO-8601. */
|
|
719
|
+
iso: string;
|
|
720
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
721
|
+
autoAdvanceMs: number;
|
|
722
|
+
};
|
|
723
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
724
|
+
type ControlState = {
|
|
725
|
+
namespace: string;
|
|
726
|
+
seed: number | string;
|
|
727
|
+
clock: ControlClock;
|
|
728
|
+
virtualTime: boolean;
|
|
729
|
+
latency: LatencyState;
|
|
730
|
+
faults: FaultListing[];
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
734
|
+
type SnapshotInfo = {
|
|
735
|
+
id: string;
|
|
736
|
+
namespace: string;
|
|
737
|
+
/** Stored rows in the snapshot. */
|
|
738
|
+
records: number;
|
|
739
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
740
|
+
at: number;
|
|
741
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
742
|
+
portable: boolean;
|
|
743
|
+
};
|
|
744
|
+
|
|
485
745
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
486
746
|
type CredentialRegistry = {
|
|
487
747
|
set(credential: string, namespace: string): void;
|
|
@@ -636,7 +896,10 @@ type ServiceInstance = FetchAPI & {
|
|
|
636
896
|
};
|
|
637
897
|
type ServiceTimelineState = Readonly<{
|
|
638
898
|
snapshot: NamespaceSnapshot;
|
|
639
|
-
clock
|
|
899
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
900
|
+
clock: Readonly<ClockState & {
|
|
901
|
+
pinned?: boolean;
|
|
902
|
+
}>;
|
|
640
903
|
rngState: number;
|
|
641
904
|
}>;
|
|
642
905
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -649,14 +912,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
649
912
|
readonly sqlite: SqliteClient$1;
|
|
650
913
|
readonly clock: Clock;
|
|
651
914
|
readonly faults: FaultRegistry;
|
|
915
|
+
/** Baseline response time per namespace. */
|
|
916
|
+
readonly latency: LatencyRegistry;
|
|
652
917
|
readonly metrics: Metrics;
|
|
653
918
|
readonly journal: Journal;
|
|
654
919
|
readonly rng: Rng;
|
|
655
920
|
readonly credentials: CredentialRegistry;
|
|
656
921
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
657
922
|
readonly webhooks: WebhookHub | undefined;
|
|
658
|
-
/**
|
|
659
|
-
|
|
923
|
+
/**
|
|
924
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
925
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
926
|
+
*/
|
|
660
927
|
namespaceClock(namespace?: string): Clock;
|
|
661
928
|
namespaceOf(request: Request): string;
|
|
662
929
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -668,8 +935,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
668
935
|
instance(namespace?: string): T;
|
|
669
936
|
/** Public names of every namespace created so far. */
|
|
670
937
|
namespaces(): string[];
|
|
671
|
-
/**
|
|
938
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
672
939
|
reset(namespace?: string): Promise<void>;
|
|
940
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
941
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
942
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
943
|
+
controls(namespace?: string): ControlState & {
|
|
944
|
+
snapshots: SnapshotInfo[];
|
|
945
|
+
};
|
|
946
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
947
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
948
|
+
snapshots: SnapshotInfo[];
|
|
949
|
+
};
|
|
950
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
951
|
+
readonly snapshots: {
|
|
952
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
953
|
+
create(options?: {
|
|
954
|
+
name?: string;
|
|
955
|
+
namespace?: string;
|
|
956
|
+
}): SnapshotInfo;
|
|
957
|
+
list(namespace?: string): SnapshotInfo[];
|
|
958
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
959
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
960
|
+
/** Store a document as a snapshot without restoring it. */
|
|
961
|
+
import(document: SnapshotDocument, options?: {
|
|
962
|
+
name?: string;
|
|
963
|
+
namespace?: string;
|
|
964
|
+
}): SnapshotInfo;
|
|
965
|
+
restore(id: string, namespace?: string): void;
|
|
966
|
+
delete(id: string, namespace?: string): boolean;
|
|
967
|
+
};
|
|
968
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
969
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
673
970
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
674
971
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
675
972
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -985,6 +1282,8 @@ type SentryRuntimeOptions = Omit<SentryAPIOptions, "now" | "namespace"> & {
|
|
|
985
1282
|
clock?: Clock;
|
|
986
1283
|
seed?: number | string;
|
|
987
1284
|
adminKey?: string;
|
|
1285
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1286
|
+
adminControls?: MockControls;
|
|
988
1287
|
onLog?: (entry: RequestLog) => void;
|
|
989
1288
|
};
|
|
990
1289
|
type SentryRuntime = ServiceRuntime<SentryAPI>;
|