@crvouga/mockingbird-service-docker 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -4
- package/DISCOVERY.md +23 -0
- package/README.md +29 -11
- package/dist/{chunk-TR75ZFCZ.js → chunk-DG4KWFV5.js} +3 -2
- package/dist/{chunk-TR75ZFCZ.js.map → chunk-DG4KWFV5.js.map} +2 -2
- package/dist/chunk-PEU54Q4H.js +6092 -0
- package/dist/chunk-PEU54Q4H.js.map +7 -0
- package/dist/cli.js +4078 -160
- package/dist/cli.js.map +4 -4
- package/dist/index.d.ts +371 -45
- package/dist/index.js +1 -1
- package/dist/server.d.ts +726 -86
- package/dist/server.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-5I542RFL.js +0 -4198
- package/dist/chunk-5I542RFL.js.map +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -374,7 +374,7 @@ type ClockState = {
|
|
|
374
374
|
now: number;
|
|
375
375
|
/** True while time does not advance on its own. */
|
|
376
376
|
frozen: boolean;
|
|
377
|
-
/** Milliseconds
|
|
377
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
378
378
|
offsetMs: number;
|
|
379
379
|
};
|
|
380
380
|
type Clock = {
|
|
@@ -410,7 +410,10 @@ type Rng = {
|
|
|
410
410
|
state(): number;
|
|
411
411
|
/** Restore a state previously returned by {@link state}. */
|
|
412
412
|
setState(state: number): void;
|
|
413
|
-
seed
|
|
413
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
414
|
+
reseed(seed: number | string): void;
|
|
415
|
+
/** The seed the stream currently starts from. */
|
|
416
|
+
readonly seed: number;
|
|
414
417
|
};
|
|
415
418
|
|
|
416
419
|
/**
|
|
@@ -419,44 +422,83 @@ type Rng = {
|
|
|
419
422
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
420
423
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
421
424
|
* appears under load, the 5xx that proves a retry path works.
|
|
425
|
+
*
|
|
426
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
427
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
428
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
422
429
|
*/
|
|
423
430
|
type FaultRule = {
|
|
424
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
431
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
425
432
|
id: string;
|
|
426
433
|
/** Fault only this operation. Omit to match every operation. */
|
|
427
434
|
operationId?: string;
|
|
428
435
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
429
436
|
method?: string;
|
|
437
|
+
/** Fault only this exact path. */
|
|
438
|
+
path?: string;
|
|
430
439
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
431
440
|
pathPrefix?: string;
|
|
441
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
442
|
+
pathPattern?: string;
|
|
443
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
444
|
+
requestHeaders?: Record<string, string>;
|
|
445
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
446
|
+
query?: Record<string, string>;
|
|
432
447
|
/**
|
|
433
448
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
434
449
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
435
450
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
436
451
|
*/
|
|
437
452
|
namespace?: string;
|
|
453
|
+
/** Let this many matching requests through first. */
|
|
454
|
+
after?: number;
|
|
455
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
456
|
+
every?: number;
|
|
457
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
458
|
+
count?: number;
|
|
459
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
460
|
+
rate?: number;
|
|
461
|
+
/**
|
|
462
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
463
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
464
|
+
*/
|
|
465
|
+
from?: Instant | Duration;
|
|
466
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
467
|
+
until?: Instant | Duration;
|
|
438
468
|
/**
|
|
439
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
440
|
-
*
|
|
441
|
-
* the request then still reaches the service.
|
|
469
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
470
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
442
471
|
*/
|
|
443
472
|
status?: number;
|
|
444
473
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
445
474
|
body?: unknown;
|
|
475
|
+
/** Response headers. */
|
|
446
476
|
headers?: Record<string, string>;
|
|
447
|
-
/**
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
rate?: number;
|
|
451
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
477
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
478
|
+
delay?: Duration;
|
|
479
|
+
/** `delay`, in milliseconds. */
|
|
452
480
|
delayMs?: number;
|
|
453
481
|
/** Alias of `delayMs`. */
|
|
454
482
|
latencyMs?: number;
|
|
483
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
484
|
+
jitter?: Duration;
|
|
485
|
+
jitterMs?: number;
|
|
486
|
+
/**
|
|
487
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
488
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
489
|
+
*/
|
|
490
|
+
timeout?: Duration;
|
|
491
|
+
timeoutMs?: number;
|
|
455
492
|
/**
|
|
456
493
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
457
494
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
458
495
|
*/
|
|
459
496
|
drop?: boolean;
|
|
497
|
+
/**
|
|
498
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
499
|
+
* the connection dies mid-body.
|
|
500
|
+
*/
|
|
501
|
+
truncate?: number;
|
|
460
502
|
/**
|
|
461
503
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
462
504
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -465,8 +507,8 @@ type FaultRule = {
|
|
|
465
507
|
effect?: string;
|
|
466
508
|
/** Parameters for `effect`. */
|
|
467
509
|
params?: Record<string, unknown>;
|
|
468
|
-
/**
|
|
469
|
-
|
|
510
|
+
/** The preset this rule was expanded from, if any. */
|
|
511
|
+
fromPreset?: string;
|
|
470
512
|
};
|
|
471
513
|
/** A fault that fired for one request. */
|
|
472
514
|
type FaultHit = {
|
|
@@ -474,6 +516,10 @@ type FaultHit = {
|
|
|
474
516
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
475
517
|
response?: Response;
|
|
476
518
|
drop?: boolean;
|
|
519
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
520
|
+
timeout?: boolean;
|
|
521
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
522
|
+
truncate?: number;
|
|
477
523
|
effect?: {
|
|
478
524
|
name: string;
|
|
479
525
|
params: Record<string, unknown>;
|
|
@@ -498,38 +544,202 @@ type FaultCandidate = {
|
|
|
498
544
|
method: string;
|
|
499
545
|
path: string;
|
|
500
546
|
namespace: string;
|
|
547
|
+
/** Request headers and query, for rules that match on them. */
|
|
548
|
+
headers?: Headers;
|
|
549
|
+
query?: URLSearchParams;
|
|
550
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
551
|
+
now?: number;
|
|
552
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
553
|
+
wait?: (ms: number) => Promise<void>;
|
|
554
|
+
};
|
|
555
|
+
/** A stored rule and how often it was consulted. */
|
|
556
|
+
type FaultListing = FaultRule & {
|
|
557
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
558
|
+
remaining: number | null;
|
|
559
|
+
/** Times the rule faulted a request. */
|
|
560
|
+
hits: number;
|
|
561
|
+
/** Requests that matched the rule, faulted or not. */
|
|
562
|
+
seen: number;
|
|
563
|
+
};
|
|
564
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
565
|
+
type FaultSnapshot = {
|
|
566
|
+
/**
|
|
567
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
568
|
+
* in the order means to a request and holds in any process.
|
|
569
|
+
*/
|
|
570
|
+
rules: (FaultListing & {
|
|
571
|
+
position?: number;
|
|
572
|
+
})[];
|
|
573
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
574
|
+
nextId?: number;
|
|
501
575
|
};
|
|
502
576
|
type FaultRegistry = {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
rules: (FaultRule & {
|
|
506
|
-
remaining: number | null;
|
|
507
|
-
hits: number;
|
|
508
|
-
position: number;
|
|
509
|
-
})[];
|
|
510
|
-
rngState: number;
|
|
511
|
-
};
|
|
577
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
578
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
512
579
|
add(rule: FaultRule): FaultRule;
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
})[];
|
|
525
|
-
rngState: number;
|
|
526
|
-
}): void;
|
|
580
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
581
|
+
nextId(namespace: string): string;
|
|
582
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
583
|
+
list(namespace?: string): FaultListing[];
|
|
584
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
585
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
586
|
+
remove(id: string, namespace?: string): boolean;
|
|
587
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
588
|
+
clear(namespace?: string): void;
|
|
589
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
590
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
527
591
|
/**
|
|
528
592
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
529
593
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
530
594
|
* each matching rule's remaining uses.
|
|
531
595
|
*/
|
|
532
596
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
597
|
+
/**
|
|
598
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
599
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
600
|
+
*/
|
|
601
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* The admin controls every mock shares, as one document.
|
|
606
|
+
*
|
|
607
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
608
|
+
*
|
|
609
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
610
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
611
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
612
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
613
|
+
*
|
|
614
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
615
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
616
|
+
*/
|
|
617
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
618
|
+
type Duration = number | string;
|
|
619
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
620
|
+
type Instant = number | string;
|
|
621
|
+
type ClockControls = {
|
|
622
|
+
/** Move the clock to this instant. */
|
|
623
|
+
now?: Instant;
|
|
624
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
625
|
+
frozen?: boolean;
|
|
626
|
+
/**
|
|
627
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
628
|
+
* each request still gets its own, reproducible timestamp.
|
|
629
|
+
*/
|
|
630
|
+
autoAdvance?: Duration;
|
|
631
|
+
};
|
|
632
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
633
|
+
type LatencyRuleInput = {
|
|
634
|
+
delay?: Duration;
|
|
635
|
+
jitter?: Duration;
|
|
636
|
+
};
|
|
637
|
+
type LatencyControls = LatencyRuleInput & {
|
|
638
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
639
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
640
|
+
};
|
|
641
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
642
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
643
|
+
id?: string;
|
|
644
|
+
}) | ({
|
|
645
|
+
preset: string;
|
|
646
|
+
} & Partial<FaultRule>);
|
|
647
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
648
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
649
|
+
/**
|
|
650
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
651
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
652
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
653
|
+
*/
|
|
654
|
+
type SnapshotDocument = {
|
|
655
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
656
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
657
|
+
service?: string;
|
|
658
|
+
/**
|
|
659
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
660
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
661
|
+
*/
|
|
662
|
+
records: {
|
|
663
|
+
collection: string;
|
|
664
|
+
id: string;
|
|
665
|
+
seq?: number;
|
|
666
|
+
value?: unknown;
|
|
667
|
+
raw?: string;
|
|
668
|
+
}[];
|
|
669
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
670
|
+
sequences?: {
|
|
671
|
+
name: string;
|
|
672
|
+
kind: string;
|
|
673
|
+
value: number;
|
|
674
|
+
}[];
|
|
675
|
+
clock?: {
|
|
676
|
+
now: number;
|
|
677
|
+
frozen: boolean;
|
|
678
|
+
autoAdvanceMs?: number;
|
|
679
|
+
};
|
|
680
|
+
seed?: number | string;
|
|
681
|
+
/** Positions of the seeded random streams. */
|
|
682
|
+
rng?: {
|
|
683
|
+
state: number;
|
|
684
|
+
faults?: number;
|
|
685
|
+
latency?: number;
|
|
686
|
+
};
|
|
687
|
+
faults?: unknown;
|
|
688
|
+
latency?: unknown;
|
|
689
|
+
virtualTime?: boolean;
|
|
690
|
+
/** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
|
|
691
|
+
webhooks?: unknown;
|
|
692
|
+
};
|
|
693
|
+
/** Controls for one namespace. */
|
|
694
|
+
type NamespaceControls = {
|
|
695
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
696
|
+
seed?: number | string;
|
|
697
|
+
clock?: ClockControls;
|
|
698
|
+
/**
|
|
699
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
700
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
701
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
702
|
+
*/
|
|
703
|
+
virtualTime?: boolean;
|
|
704
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
705
|
+
latency?: Duration | LatencyControls;
|
|
706
|
+
faults?: readonly FaultInput[];
|
|
707
|
+
/** Start from this state instead of the service's own seed data. */
|
|
708
|
+
snapshot?: SnapshotDocument;
|
|
709
|
+
};
|
|
710
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
711
|
+
type MockControls = NamespaceControls & {
|
|
712
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
713
|
+
credentials?: Record<string, string>;
|
|
714
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
715
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
716
|
+
};
|
|
717
|
+
/** A latency rule in milliseconds. */
|
|
718
|
+
type LatencyRule = {
|
|
719
|
+
delayMs: number;
|
|
720
|
+
jitterMs: number;
|
|
721
|
+
};
|
|
722
|
+
/** Baseline latency for a namespace, normalized. */
|
|
723
|
+
type LatencyState = LatencyRule & {
|
|
724
|
+
operations: Record<string, LatencyRule>;
|
|
725
|
+
};
|
|
726
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
727
|
+
type ControlHeaderInput = {
|
|
728
|
+
namespace?: string;
|
|
729
|
+
adminKey?: string;
|
|
730
|
+
branch?: string;
|
|
731
|
+
at?: string;
|
|
732
|
+
reset?: boolean;
|
|
733
|
+
restore?: string;
|
|
734
|
+
seed?: number | string;
|
|
735
|
+
time?: Instant | Date;
|
|
736
|
+
advance?: Duration;
|
|
737
|
+
virtualTime?: boolean;
|
|
738
|
+
delay?: Duration;
|
|
739
|
+
timeout?: Duration;
|
|
740
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
741
|
+
fault?: number | string | Record<string, unknown>;
|
|
742
|
+
snapshot?: string;
|
|
533
743
|
};
|
|
534
744
|
|
|
535
745
|
/**
|
|
@@ -569,6 +779,8 @@ type RequestLog = {
|
|
|
569
779
|
unmatched: boolean;
|
|
570
780
|
/** Set when a fault rule produced the response. */
|
|
571
781
|
faultId?: string;
|
|
782
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
783
|
+
delayMs?: number;
|
|
572
784
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
573
785
|
ids?: Record<string, string>;
|
|
574
786
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -614,6 +826,12 @@ type JournalQuery = {
|
|
|
614
826
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
615
827
|
namespace?: string;
|
|
616
828
|
operationId?: string;
|
|
829
|
+
/** Only this HTTP method, case-insensitive. */
|
|
830
|
+
method?: string;
|
|
831
|
+
/** Only this exact path. */
|
|
832
|
+
path?: string;
|
|
833
|
+
/** Only requests this fault rule answered or shaped. */
|
|
834
|
+
faultId?: string;
|
|
617
835
|
status?: number;
|
|
618
836
|
/** Only entries at or after this instant (epoch ms). */
|
|
619
837
|
since?: number;
|
|
@@ -628,6 +846,38 @@ type Journal = {
|
|
|
628
846
|
clear(namespace?: string): void;
|
|
629
847
|
};
|
|
630
848
|
|
|
849
|
+
/**
|
|
850
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
851
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
852
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
853
|
+
* fault hits.
|
|
854
|
+
*/
|
|
855
|
+
type LatencyRegistry = {
|
|
856
|
+
get(namespace: string): LatencyState;
|
|
857
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
858
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
859
|
+
clear(namespace?: string): void;
|
|
860
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
861
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
/** Clock state as the admin API reports it. */
|
|
865
|
+
type ControlClock = ClockState & {
|
|
866
|
+
/** `now`, as ISO-8601. */
|
|
867
|
+
iso: string;
|
|
868
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
869
|
+
autoAdvanceMs: number;
|
|
870
|
+
};
|
|
871
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
872
|
+
type ControlState = {
|
|
873
|
+
namespace: string;
|
|
874
|
+
seed: number | string;
|
|
875
|
+
clock: ControlClock;
|
|
876
|
+
virtualTime: boolean;
|
|
877
|
+
latency: LatencyState;
|
|
878
|
+
faults: FaultListing[];
|
|
879
|
+
};
|
|
880
|
+
|
|
631
881
|
type AdminRequest = {
|
|
632
882
|
request: Request;
|
|
633
883
|
url: URL;
|
|
@@ -644,6 +894,17 @@ type AdminRoute = (request: AdminRequest) => Response | Promise<Response>;
|
|
|
644
894
|
* `:param` segments — e.g. `"POST /orders/:id/transition"`.
|
|
645
895
|
*/
|
|
646
896
|
type AdminRoutes = Record<string, AdminRoute>;
|
|
897
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
898
|
+
type SnapshotInfo = {
|
|
899
|
+
id: string;
|
|
900
|
+
namespace: string;
|
|
901
|
+
/** Stored rows in the snapshot. */
|
|
902
|
+
records: number;
|
|
903
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
904
|
+
at: number;
|
|
905
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
906
|
+
portable: boolean;
|
|
907
|
+
};
|
|
647
908
|
|
|
648
909
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
649
910
|
type CredentialRegistry = {
|
|
@@ -657,6 +918,8 @@ type CredentialRegistry = {
|
|
|
657
918
|
}[];
|
|
658
919
|
};
|
|
659
920
|
|
|
921
|
+
type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
|
|
922
|
+
|
|
660
923
|
/**
|
|
661
924
|
* A point-in-time copy of everything a service namespace holds.
|
|
662
925
|
*
|
|
@@ -843,8 +1106,16 @@ type PublishInput = {
|
|
|
843
1106
|
id?: string;
|
|
844
1107
|
};
|
|
845
1108
|
type WebhookHub = {
|
|
1109
|
+
observeDeliveries(listener: (event: {
|
|
1110
|
+
namespace: string;
|
|
1111
|
+
state: string;
|
|
1112
|
+
deliveryId: string;
|
|
1113
|
+
}) => void): () => void;
|
|
1114
|
+
setTransportPolicy(policy: OwnedTransport): void;
|
|
846
1115
|
pending(namespace: string): number;
|
|
847
1116
|
snapshot(namespace: string): unknown;
|
|
1117
|
+
exportSnapshot(handle: unknown): unknown;
|
|
1118
|
+
importSnapshot(namespace: string, document: unknown): unknown;
|
|
848
1119
|
restore(namespace: string, snapshot: unknown): void;
|
|
849
1120
|
publish(input: PublishInput): WebhookMessage;
|
|
850
1121
|
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
@@ -857,7 +1128,7 @@ type WebhookHub = {
|
|
|
857
1128
|
/** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
|
|
858
1129
|
flush(): Promise<void>;
|
|
859
1130
|
/** Resolve once nothing is in flight. */
|
|
860
|
-
idle(): Promise<void>;
|
|
1131
|
+
idle(namespace?: string): Promise<void>;
|
|
861
1132
|
fault(namespace: string, fault: WebhookFault): void;
|
|
862
1133
|
clear(namespace?: string): void;
|
|
863
1134
|
};
|
|
@@ -888,14 +1159,26 @@ type RuntimeOptions<T extends ServiceInstance> = {
|
|
|
888
1159
|
sqlite?: SqliteClient$1;
|
|
889
1160
|
/** Defaults to a live clock over `Date.now`. */
|
|
890
1161
|
clock?: Clock;
|
|
891
|
-
/** Seeds every random choice the runtime makes (fault rates). Default `0`. */
|
|
1162
|
+
/** Seeds every random choice the runtime makes (fault rates, jitter). Default `0`. */
|
|
892
1163
|
seed?: number | string;
|
|
1164
|
+
/**
|
|
1165
|
+
* Admin controls to boot with: clock, latency, faults, a starting snapshot, credential
|
|
1166
|
+
* mappings and per-namespace overrides. `reset` returns a namespace to exactly this.
|
|
1167
|
+
*/
|
|
1168
|
+
adminControls?: MockControls;
|
|
893
1169
|
/** Extra `GET /__admin/health` fields, such as the loaded corpus version. */
|
|
894
1170
|
describe?: () => Record<string, unknown>;
|
|
895
1171
|
/** Service-specific admin routes, given the runtime so they can reach any namespace. */
|
|
896
1172
|
admin?: (runtime: ServiceRuntime<T>) => AdminRoutes;
|
|
897
1173
|
/** Reserved tree for every internal HTTP endpoint, UI and namespace carrier. Default /__admin. */
|
|
898
1174
|
adminPrefix?: string;
|
|
1175
|
+
/**
|
|
1176
|
+
* A namespace's clock was moved — by `/__admin/clock`, a header, a restore, a reset, or a
|
|
1177
|
+
* wait spent in virtual time. Run whatever the service schedules by that clock, so what
|
|
1178
|
+
* came due is seen at once and not on the next request. Moving the base clock in process
|
|
1179
|
+
* (`runtime.clock`) is the caller's own doing and is not reported here.
|
|
1180
|
+
*/
|
|
1181
|
+
onClockChange?: (namespace: string) => void;
|
|
899
1182
|
/** Invalidate transient handles before replacing an existing instance's stored state. */
|
|
900
1183
|
beforeRestore?: (instance: T) => void;
|
|
901
1184
|
/** Require this value in `x-mockingbird-admin-key` on admin data routes. */
|
|
@@ -913,7 +1196,10 @@ type RuntimeOptions<T extends ServiceInstance> = {
|
|
|
913
1196
|
* `sigV4AccessKeyId`.
|
|
914
1197
|
*/
|
|
915
1198
|
credential?: (request: Request) => string | undefined;
|
|
916
|
-
/**
|
|
1199
|
+
/**
|
|
1200
|
+
* Named faults, switched on with `POST /__admin/faults {"preset": "<name>"}`. They join the
|
|
1201
|
+
* standard presets every mock has; one with a standard name replaces it.
|
|
1202
|
+
*/
|
|
917
1203
|
presets?: Record<string, FaultPreset>;
|
|
918
1204
|
/** Outbound webhooks; adds the `/__admin/webhooks*` routes and clears on reset. */
|
|
919
1205
|
webhooks?: WebhookHub;
|
|
@@ -936,11 +1222,15 @@ type RuntimeOptions<T extends ServiceInstance> = {
|
|
|
936
1222
|
type RuntimeIO = {
|
|
937
1223
|
wallNow(): number;
|
|
938
1224
|
monotonicNow(): number;
|
|
939
|
-
|
|
1225
|
+
/** Wait on the wall clock. Rejects with the signal's reason when it aborts first. */
|
|
1226
|
+
sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
940
1227
|
};
|
|
941
1228
|
type ServiceTimelineState = Readonly<{
|
|
942
1229
|
snapshot: NamespaceSnapshot;
|
|
943
|
-
clock
|
|
1230
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
1231
|
+
clock: Readonly<ClockState & {
|
|
1232
|
+
pinned?: boolean;
|
|
1233
|
+
}>;
|
|
944
1234
|
rngState: number;
|
|
945
1235
|
}>;
|
|
946
1236
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -953,27 +1243,63 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
953
1243
|
readonly sqlite: SqliteClient$1;
|
|
954
1244
|
readonly clock: Clock;
|
|
955
1245
|
readonly faults: FaultRegistry;
|
|
1246
|
+
/** Baseline response time per namespace. */
|
|
1247
|
+
readonly latency: LatencyRegistry;
|
|
956
1248
|
readonly metrics: Metrics;
|
|
957
1249
|
readonly journal: Journal;
|
|
958
1250
|
readonly rng: Rng;
|
|
959
1251
|
readonly credentials: CredentialRegistry;
|
|
960
1252
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
961
1253
|
readonly webhooks: WebhookHub | undefined;
|
|
962
|
-
/**
|
|
963
|
-
|
|
1254
|
+
/**
|
|
1255
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
1256
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
1257
|
+
*/
|
|
964
1258
|
namespaceClock(namespace?: string): Clock;
|
|
965
1259
|
namespaceOf(request: Request): string;
|
|
966
1260
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
967
1261
|
fleetSnapshot(namespace: string): object;
|
|
968
1262
|
fleetRestore(snapshot: unknown, namespace: string): void;
|
|
1263
|
+
fleetExport(snapshot: unknown): SnapshotDocument;
|
|
1264
|
+
fleetImport(namespace: string, document: unknown): object;
|
|
969
1265
|
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
970
1266
|
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
|
|
971
1267
|
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
972
1268
|
instance(namespace?: string): T;
|
|
973
1269
|
/** Public names of every namespace created so far. */
|
|
974
1270
|
namespaces(): string[];
|
|
975
|
-
/**
|
|
1271
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
976
1272
|
reset(namespace?: string): Promise<void>;
|
|
1273
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
1274
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
1275
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
1276
|
+
controls(namespace?: string): ControlState & {
|
|
1277
|
+
snapshots: SnapshotInfo[];
|
|
1278
|
+
};
|
|
1279
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
1280
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
1281
|
+
snapshots: SnapshotInfo[];
|
|
1282
|
+
};
|
|
1283
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
1284
|
+
readonly snapshots: {
|
|
1285
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
1286
|
+
create(options?: {
|
|
1287
|
+
name?: string;
|
|
1288
|
+
namespace?: string;
|
|
1289
|
+
}): SnapshotInfo;
|
|
1290
|
+
list(namespace?: string): SnapshotInfo[];
|
|
1291
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
1292
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
1293
|
+
/** Store a document as a snapshot without restoring it. */
|
|
1294
|
+
import(document: SnapshotDocument, options?: {
|
|
1295
|
+
name?: string;
|
|
1296
|
+
namespace?: string;
|
|
1297
|
+
}): SnapshotInfo;
|
|
1298
|
+
restore(id: string, namespace?: string): void;
|
|
1299
|
+
delete(id: string, namespace?: string): boolean;
|
|
1300
|
+
};
|
|
1301
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
1302
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
977
1303
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
978
1304
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
979
1305
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1286,7 +1612,7 @@ type SupportedOperationId = "ContainerList" | "ContainerCreate" | "ContainerInsp
|
|
|
1286
1612
|
declare const operationIds: readonly ["ContainerList", "ContainerCreate", "ContainerInspect", "ContainerStart", "ContainerStop", "ContainerKill", "ContainerAttach", "ContainerWait", "ContainerDelete", "SystemInfo", "SystemVersion", "SystemPing", "SystemPingHead"];
|
|
1287
1613
|
declare const supportedOperationIds: readonly ["ContainerList", "ContainerCreate", "ContainerInspect", "ContainerStart", "ContainerStop", "ContainerKill", "ContainerWait", "ContainerDelete", "SystemInfo", "SystemVersion", "SystemPing", "SystemPingHead"];
|
|
1288
1614
|
|
|
1289
|
-
type DockerRuntimeOptions = Pick<RuntimeOptions<DockerAPI>, "sqlite" | "clock" | "seed" | "adminKey" | "onLog" | "journalSize" | "maxCheckpoints"> & Pick<DockerAPIOptions, "onAttach">;
|
|
1615
|
+
type DockerRuntimeOptions = Pick<RuntimeOptions<DockerAPI>, "sqlite" | "clock" | "seed" | "adminKey" | "adminControls" | "onLog" | "journalSize" | "maxCheckpoints"> & Pick<DockerAPIOptions, "onAttach">;
|
|
1290
1616
|
type DockerRuntime = ServiceRuntime<DockerAPI> & {
|
|
1291
1617
|
close(): void;
|
|
1292
1618
|
};
|