@crvouga/mockingbird-service-hermes 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 +7 -1
- package/DISCOVERY.md +23 -0
- package/README.md +35 -16
- package/dist/chunk-AMUIT2BU.js +5518 -0
- package/dist/chunk-AMUIT2BU.js.map +7 -0
- package/dist/{chunk-CZFRUSRA.js → chunk-Y72MHOLI.js} +136 -25
- package/dist/chunk-Y72MHOLI.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +356 -44
- package/dist/index.js +1 -1
- package/dist/server.d.ts +695 -84
- package/dist/server.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-CZFRUSRA.js.map +0 -7
- package/dist/chunk-OPQVERJU.js +0 -3727
- package/dist/chunk-OPQVERJU.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,200 @@ 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
|
+
};
|
|
691
|
+
/** Controls for one namespace. */
|
|
692
|
+
type NamespaceControls = {
|
|
693
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
694
|
+
seed?: number | string;
|
|
695
|
+
clock?: ClockControls;
|
|
696
|
+
/**
|
|
697
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
698
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
699
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
700
|
+
*/
|
|
701
|
+
virtualTime?: boolean;
|
|
702
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
703
|
+
latency?: Duration | LatencyControls;
|
|
704
|
+
faults?: readonly FaultInput[];
|
|
705
|
+
/** Start from this state instead of the service's own seed data. */
|
|
706
|
+
snapshot?: SnapshotDocument;
|
|
707
|
+
};
|
|
708
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
709
|
+
type MockControls = NamespaceControls & {
|
|
710
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
711
|
+
credentials?: Record<string, string>;
|
|
712
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
713
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
714
|
+
};
|
|
715
|
+
/** A latency rule in milliseconds. */
|
|
716
|
+
type LatencyRule = {
|
|
717
|
+
delayMs: number;
|
|
718
|
+
jitterMs: number;
|
|
719
|
+
};
|
|
720
|
+
/** Baseline latency for a namespace, normalized. */
|
|
721
|
+
type LatencyState = LatencyRule & {
|
|
722
|
+
operations: Record<string, LatencyRule>;
|
|
723
|
+
};
|
|
724
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
725
|
+
type ControlHeaderInput = {
|
|
726
|
+
namespace?: string;
|
|
727
|
+
adminKey?: string;
|
|
728
|
+
branch?: string;
|
|
729
|
+
at?: string;
|
|
730
|
+
reset?: boolean;
|
|
731
|
+
restore?: string;
|
|
732
|
+
seed?: number | string;
|
|
733
|
+
time?: Instant | Date;
|
|
734
|
+
advance?: Duration;
|
|
735
|
+
virtualTime?: boolean;
|
|
736
|
+
delay?: Duration;
|
|
737
|
+
timeout?: Duration;
|
|
738
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
739
|
+
fault?: number | string | Record<string, unknown>;
|
|
740
|
+
snapshot?: string;
|
|
533
741
|
};
|
|
534
742
|
|
|
535
743
|
/**
|
|
@@ -569,6 +777,8 @@ type RequestLog = {
|
|
|
569
777
|
unmatched: boolean;
|
|
570
778
|
/** Set when a fault rule produced the response. */
|
|
571
779
|
faultId?: string;
|
|
780
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
781
|
+
delayMs?: number;
|
|
572
782
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
573
783
|
ids?: Record<string, string>;
|
|
574
784
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -614,6 +824,12 @@ type JournalQuery = {
|
|
|
614
824
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
615
825
|
namespace?: string;
|
|
616
826
|
operationId?: string;
|
|
827
|
+
/** Only this HTTP method, case-insensitive. */
|
|
828
|
+
method?: string;
|
|
829
|
+
/** Only this exact path. */
|
|
830
|
+
path?: string;
|
|
831
|
+
/** Only requests this fault rule answered or shaped. */
|
|
832
|
+
faultId?: string;
|
|
617
833
|
status?: number;
|
|
618
834
|
/** Only entries at or after this instant (epoch ms). */
|
|
619
835
|
since?: number;
|
|
@@ -628,6 +844,38 @@ type Journal = {
|
|
|
628
844
|
clear(namespace?: string): void;
|
|
629
845
|
};
|
|
630
846
|
|
|
847
|
+
/**
|
|
848
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
849
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
850
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
851
|
+
* fault hits.
|
|
852
|
+
*/
|
|
853
|
+
type LatencyRegistry = {
|
|
854
|
+
get(namespace: string): LatencyState;
|
|
855
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
856
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
857
|
+
clear(namespace?: string): void;
|
|
858
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
859
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
860
|
+
};
|
|
861
|
+
|
|
862
|
+
/** Clock state as the admin API reports it. */
|
|
863
|
+
type ControlClock = ClockState & {
|
|
864
|
+
/** `now`, as ISO-8601. */
|
|
865
|
+
iso: string;
|
|
866
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
867
|
+
autoAdvanceMs: number;
|
|
868
|
+
};
|
|
869
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
870
|
+
type ControlState = {
|
|
871
|
+
namespace: string;
|
|
872
|
+
seed: number | string;
|
|
873
|
+
clock: ControlClock;
|
|
874
|
+
virtualTime: boolean;
|
|
875
|
+
latency: LatencyState;
|
|
876
|
+
faults: FaultListing[];
|
|
877
|
+
};
|
|
878
|
+
|
|
631
879
|
type AdminRequest = {
|
|
632
880
|
request: Request;
|
|
633
881
|
url: URL;
|
|
@@ -644,6 +892,17 @@ type AdminRoute = (request: AdminRequest) => Response | Promise<Response>;
|
|
|
644
892
|
* `:param` segments — e.g. `"POST /orders/:id/transition"`.
|
|
645
893
|
*/
|
|
646
894
|
type AdminRoutes = Record<string, AdminRoute>;
|
|
895
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
896
|
+
type SnapshotInfo = {
|
|
897
|
+
id: string;
|
|
898
|
+
namespace: string;
|
|
899
|
+
/** Stored rows in the snapshot. */
|
|
900
|
+
records: number;
|
|
901
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
902
|
+
at: number;
|
|
903
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
904
|
+
portable: boolean;
|
|
905
|
+
};
|
|
647
906
|
|
|
648
907
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
649
908
|
type CredentialRegistry = {
|
|
@@ -888,14 +1147,26 @@ type RuntimeOptions<T extends ServiceInstance> = {
|
|
|
888
1147
|
sqlite?: SqliteClient$1;
|
|
889
1148
|
/** Defaults to a live clock over `Date.now`. */
|
|
890
1149
|
clock?: Clock;
|
|
891
|
-
/** Seeds every random choice the runtime makes (fault rates). Default `0`. */
|
|
1150
|
+
/** Seeds every random choice the runtime makes (fault rates, jitter). Default `0`. */
|
|
892
1151
|
seed?: number | string;
|
|
1152
|
+
/**
|
|
1153
|
+
* Admin controls to boot with: clock, latency, faults, a starting snapshot, credential
|
|
1154
|
+
* mappings and per-namespace overrides. `reset` returns a namespace to exactly this.
|
|
1155
|
+
*/
|
|
1156
|
+
adminControls?: MockControls;
|
|
893
1157
|
/** Extra `GET /__admin/health` fields, such as the loaded corpus version. */
|
|
894
1158
|
describe?: () => Record<string, unknown>;
|
|
895
1159
|
/** Service-specific admin routes, given the runtime so they can reach any namespace. */
|
|
896
1160
|
admin?: (runtime: ServiceRuntime<T>) => AdminRoutes;
|
|
897
1161
|
/** Reserved tree for every internal HTTP endpoint, UI and namespace carrier. Default /__admin. */
|
|
898
1162
|
adminPrefix?: string;
|
|
1163
|
+
/**
|
|
1164
|
+
* A namespace's clock was moved — by `/__admin/clock`, a header, a restore, a reset, or a
|
|
1165
|
+
* wait spent in virtual time. Run whatever the service schedules by that clock, so what
|
|
1166
|
+
* came due is seen at once and not on the next request. Moving the base clock in process
|
|
1167
|
+
* (`runtime.clock`) is the caller's own doing and is not reported here.
|
|
1168
|
+
*/
|
|
1169
|
+
onClockChange?: (namespace: string) => void;
|
|
899
1170
|
/** Invalidate transient handles before replacing an existing instance's stored state. */
|
|
900
1171
|
beforeRestore?: (instance: T) => void;
|
|
901
1172
|
/** Require this value in `x-mockingbird-admin-key` on admin data routes. */
|
|
@@ -913,7 +1184,10 @@ type RuntimeOptions<T extends ServiceInstance> = {
|
|
|
913
1184
|
* `sigV4AccessKeyId`.
|
|
914
1185
|
*/
|
|
915
1186
|
credential?: (request: Request) => string | undefined;
|
|
916
|
-
/**
|
|
1187
|
+
/**
|
|
1188
|
+
* Named faults, switched on with `POST /__admin/faults {"preset": "<name>"}`. They join the
|
|
1189
|
+
* standard presets every mock has; one with a standard name replaces it.
|
|
1190
|
+
*/
|
|
917
1191
|
presets?: Record<string, FaultPreset>;
|
|
918
1192
|
/** Outbound webhooks; adds the `/__admin/webhooks*` routes and clears on reset. */
|
|
919
1193
|
webhooks?: WebhookHub;
|
|
@@ -936,11 +1210,15 @@ type RuntimeOptions<T extends ServiceInstance> = {
|
|
|
936
1210
|
type RuntimeIO = {
|
|
937
1211
|
wallNow(): number;
|
|
938
1212
|
monotonicNow(): number;
|
|
939
|
-
|
|
1213
|
+
/** Wait on the wall clock. Rejects with the signal's reason when it aborts first. */
|
|
1214
|
+
sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
940
1215
|
};
|
|
941
1216
|
type ServiceTimelineState = Readonly<{
|
|
942
1217
|
snapshot: NamespaceSnapshot;
|
|
943
|
-
clock
|
|
1218
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
1219
|
+
clock: Readonly<ClockState & {
|
|
1220
|
+
pinned?: boolean;
|
|
1221
|
+
}>;
|
|
944
1222
|
rngState: number;
|
|
945
1223
|
}>;
|
|
946
1224
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -953,14 +1231,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
953
1231
|
readonly sqlite: SqliteClient$1;
|
|
954
1232
|
readonly clock: Clock;
|
|
955
1233
|
readonly faults: FaultRegistry;
|
|
1234
|
+
/** Baseline response time per namespace. */
|
|
1235
|
+
readonly latency: LatencyRegistry;
|
|
956
1236
|
readonly metrics: Metrics;
|
|
957
1237
|
readonly journal: Journal;
|
|
958
1238
|
readonly rng: Rng;
|
|
959
1239
|
readonly credentials: CredentialRegistry;
|
|
960
1240
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
961
1241
|
readonly webhooks: WebhookHub | undefined;
|
|
962
|
-
/**
|
|
963
|
-
|
|
1242
|
+
/**
|
|
1243
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
1244
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
1245
|
+
*/
|
|
964
1246
|
namespaceClock(namespace?: string): Clock;
|
|
965
1247
|
namespaceOf(request: Request): string;
|
|
966
1248
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -972,8 +1254,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
972
1254
|
instance(namespace?: string): T;
|
|
973
1255
|
/** Public names of every namespace created so far. */
|
|
974
1256
|
namespaces(): string[];
|
|
975
|
-
/**
|
|
1257
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
976
1258
|
reset(namespace?: string): Promise<void>;
|
|
1259
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
1260
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
1261
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
1262
|
+
controls(namespace?: string): ControlState & {
|
|
1263
|
+
snapshots: SnapshotInfo[];
|
|
1264
|
+
};
|
|
1265
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
1266
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
1267
|
+
snapshots: SnapshotInfo[];
|
|
1268
|
+
};
|
|
1269
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
1270
|
+
readonly snapshots: {
|
|
1271
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
1272
|
+
create(options?: {
|
|
1273
|
+
name?: string;
|
|
1274
|
+
namespace?: string;
|
|
1275
|
+
}): SnapshotInfo;
|
|
1276
|
+
list(namespace?: string): SnapshotInfo[];
|
|
1277
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
1278
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
1279
|
+
/** Store a document as a snapshot without restoring it. */
|
|
1280
|
+
import(document: SnapshotDocument, options?: {
|
|
1281
|
+
name?: string;
|
|
1282
|
+
namespace?: string;
|
|
1283
|
+
}): SnapshotInfo;
|
|
1284
|
+
restore(id: string, namespace?: string): void;
|
|
1285
|
+
delete(id: string, namespace?: string): boolean;
|
|
1286
|
+
};
|
|
1287
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
1288
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
977
1289
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
978
1290
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
979
1291
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1277,7 +1589,7 @@ type SupportedOperationId = "RunCreate" | "RunGet" | "RunStop";
|
|
|
1277
1589
|
declare const operationIds: readonly ["RunCreate", "RunGet", "RunStop", "RunEvents", "RunApproval", "RunSteer"];
|
|
1278
1590
|
declare const supportedOperationIds: readonly ["RunCreate", "RunGet", "RunStop"];
|
|
1279
1591
|
|
|
1280
|
-
type HermesRuntimeOptions = Pick<RuntimeOptions<HermesAPI>, "sqlite" | "clock" | "seed" | "adminKey" | "onLog" | "journalSize" | "maxCheckpoints">;
|
|
1592
|
+
type HermesRuntimeOptions = Pick<RuntimeOptions<HermesAPI>, "sqlite" | "clock" | "seed" | "adminKey" | "adminControls" | "onLog" | "journalSize" | "maxCheckpoints">;
|
|
1281
1593
|
type HermesRuntime = ServiceRuntime<HermesAPI>;
|
|
1282
1594
|
/** Standard controls and Timeline coordination; no provider-local history. */
|
|
1283
1595
|
declare const createRuntime: (options?: HermesRuntimeOptions) => HermesRuntime;
|