@crvouga/mockingbird-service-step-functions 3.2.0 → 3.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/dist/server.d.ts CHANGED
@@ -144,7 +144,7 @@ type ClockState$1 = {
144
144
  now: number;
145
145
  /** True while time does not advance on its own. */
146
146
  frozen: boolean;
147
- /** Milliseconds this clock adds to its underlying source. */
147
+ /** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
148
148
  offsetMs: number;
149
149
  };
150
150
  type Clock$1 = {
@@ -180,7 +180,10 @@ type Rng$1 = {
180
180
  state(): number;
181
181
  /** Restore a state previously returned by {@link state}. */
182
182
  setState(state: number): void;
183
- seed: number;
183
+ /** Restart the stream from a new seed. `reset` then returns to this seed. */
184
+ reseed(seed: number | string): void;
185
+ /** The seed the stream currently starts from. */
186
+ readonly seed: number;
184
187
  };
185
188
 
186
189
  /**
@@ -189,44 +192,83 @@ type Rng$1 = {
189
192
  * This is how a suite reaches the vendor's failure modes without the vendor: the
190
193
  * quota error that only appears when a shared sandbox is full, the 429 that only
191
194
  * appears under load, the 5xx that proves a retry path works.
195
+ *
196
+ * A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
197
+ * it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
198
+ * and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
192
199
  */
193
200
  type FaultRule$1 = {
194
- /** Stable id, so a suite can retire exactly the rule it added. */
201
+ /** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
195
202
  id: string;
196
203
  /** Fault only this operation. Omit to match every operation. */
197
204
  operationId?: string;
198
205
  /** Fault only this HTTP method, case-insensitive. Omit to match every method. */
199
206
  method?: string;
207
+ /** Fault only this exact path. */
208
+ path?: string;
200
209
  /** Fault only paths starting with this prefix. Omit to match every path. */
201
210
  pathPrefix?: string;
211
+ /** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
212
+ pathPattern?: string;
213
+ /** Fault only requests carrying these headers. `"*"` matches any value. */
214
+ requestHeaders?: Record<string, string>;
215
+ /** Fault only requests carrying these query parameters. `"*"` matches any value. */
216
+ query?: Record<string, string>;
202
217
  /**
203
218
  * Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
204
219
  * an in-process caller usually wants, and what a parallel worker usually does not:
205
220
  * rules added through `POST /__admin/faults` default to the calling namespace.
206
221
  */
207
222
  namespace?: string;
223
+ /** Let this many matching requests through first. */
224
+ after?: number;
225
+ /** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
226
+ every?: number;
227
+ /** Retire the rule after this many faults. Omit to keep it until removed. */
228
+ count?: number;
229
+ /** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
230
+ rate?: number;
231
+ /**
232
+ * Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
233
+ * clock when the rule was added. Listed as epoch ms.
234
+ */
235
+ from?: Instant$1 | Duration$1;
236
+ /** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
237
+ until?: Instant$1 | Duration$1;
208
238
  /**
209
- * Status of the injected response. Omit for a rule that only delays (`delayMs` /
210
- * `latencyMs`), only drops the connection (`drop`), or only switches on an `effect`:
211
- * the request then still reaches the service.
239
+ * Status of the injected response. Omit for a rule that only delays, times out, drops,
240
+ * truncates, or switches on an `effect`: the request then still reaches the service.
212
241
  */
213
242
  status?: number;
214
243
  /** Response body, serialized as JSON. A string is sent as-is. */
215
244
  body?: unknown;
245
+ /** Response headers. */
216
246
  headers?: Record<string, string>;
217
- /** Retire the rule after this many faults. Omit to keep it until removed. */
218
- count?: number;
219
- /** Fault this fraction of matching requests, `0`–`1`. Default `1`. */
220
- rate?: number;
221
- /** Hold the response back this long, to exercise timeouts. */
247
+ /** Hold the response back this long. Listed as `delayMs`. */
248
+ delay?: Duration$1;
249
+ /** `delay`, in milliseconds. */
222
250
  delayMs?: number;
223
251
  /** Alias of `delayMs`. */
224
252
  latencyMs?: number;
253
+ /** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
254
+ jitter?: Duration$1;
255
+ jitterMs?: number;
256
+ /**
257
+ * Never answer: hold the request this long, then drop the connection. Listed as
258
+ * `timeoutMs`. With virtual time the wait is spent on the mock clock.
259
+ */
260
+ timeout?: Duration$1;
261
+ timeoutMs?: number;
225
262
  /**
226
263
  * Drop the connection instead of answering: an in-process `fetch` rejects with a
227
264
  * `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
228
265
  */
229
266
  drop?: boolean;
267
+ /**
268
+ * Cut the response body off after this many bytes: the status and headers arrive, then
269
+ * the connection dies mid-body.
270
+ */
271
+ truncate?: number;
230
272
  /**
231
273
  * A named service behaviour to switch on for the matching request instead of (or
232
274
  * before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
@@ -235,8 +277,8 @@ type FaultRule$1 = {
235
277
  effect?: string;
236
278
  /** Parameters for `effect`. */
237
279
  params?: Record<string, unknown>;
238
- /** From the preset this rule was expanded from, if any. */
239
- preset?: string;
280
+ /** The preset this rule was expanded from, if any. */
281
+ fromPreset?: string;
240
282
  };
241
283
  /** A fault that fired for one request. */
242
284
  type FaultHit$1 = {
@@ -244,6 +286,10 @@ type FaultHit$1 = {
244
286
  /** The injected response; absent when the rule only delays, drops, or sets an effect. */
245
287
  response?: Response;
246
288
  drop?: boolean;
289
+ /** Set with `drop` when the rule held the request for its `timeout` first. */
290
+ timeout?: boolean;
291
+ /** Bytes of response body to let through before the connection dies. */
292
+ truncate?: number;
247
293
  effect?: {
248
294
  name: string;
249
295
  params: Record<string, unknown>;
@@ -255,38 +301,202 @@ type FaultCandidate$1 = {
255
301
  method: string;
256
302
  path: string;
257
303
  namespace: string;
304
+ /** Request headers and query, for rules that match on them. */
305
+ headers?: Headers;
306
+ query?: URLSearchParams;
307
+ /** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
308
+ now?: number;
309
+ /** How to spend a delay for this request. Default: the registry's own sleep. */
310
+ wait?: (ms: number) => Promise<void>;
311
+ };
312
+ /** A stored rule and how often it was consulted. */
313
+ type FaultListing$1 = FaultRule$1 & {
314
+ /** Faults left before the rule retires. `null` when it has no `count`. */
315
+ remaining: number | null;
316
+ /** Times the rule faulted a request. */
317
+ hits: number;
318
+ /** Requests that matched the rule, faulted or not. */
319
+ seen: number;
320
+ };
321
+ /** A namespace's own rules, with their counters, in the order they are tried. */
322
+ type FaultSnapshot$1 = {
323
+ /**
324
+ * `position` is how many `"*"` rules are tried before the rule, which is what its place
325
+ * in the order means to a request and holds in any process.
326
+ */
327
+ rules: (FaultListing$1 & {
328
+ position?: number;
329
+ })[];
330
+ /** How many `fault_<n>` ids the namespace has handed out. */
331
+ nextId?: number;
258
332
  };
259
333
  type FaultRegistry$1 = {
260
- isolateNamespaces(): void;
261
- snapshot(namespace: string): {
262
- rules: (FaultRule$1 & {
263
- remaining: number | null;
264
- hits: number;
265
- position: number;
266
- })[];
267
- rngState: number;
268
- };
334
+ snapshot(namespace: string): FaultSnapshot$1;
335
+ /** Add a rule, or replace the rule with the same id in the same namespace. */
269
336
  add(rule: FaultRule$1): FaultRule$1;
270
- list(): (FaultRule$1 & {
271
- remaining: number | null;
272
- hits: number;
273
- })[];
274
- remove(id: string): boolean;
275
- clear(): void;
276
- restore(namespace: string, state: {
277
- rules: (FaultRule$1 & {
278
- remaining: number | null;
279
- hits: number;
280
- position: number;
281
- })[];
282
- rngState: number;
283
- }): void;
337
+ /** The next unused `fault_<n>` id in `namespace`. */
338
+ nextId(namespace: string): string;
339
+ /** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
340
+ list(namespace?: string): FaultListing$1[];
341
+ get(id: string, namespace?: string): FaultListing$1 | undefined;
342
+ /** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
343
+ remove(id: string, namespace?: string): boolean;
344
+ /** Remove every rule, or one namespace's own rules. */
345
+ clear(namespace?: string): void;
346
+ /** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
347
+ restore(namespace: string, state: FaultSnapshot$1): void;
284
348
  /**
285
349
  * Every fault this request should get, in rule order, stopping at the first that answers
286
350
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
287
351
  * each matching rule's remaining uses.
288
352
  */
289
353
  take(candidate: FaultCandidate$1): Promise<FaultHit$1[]>;
354
+ /**
355
+ * Fire these rules at one request without storing them: no matching, no schedule, in order,
356
+ * stopping at the first that answers or drops. Jitter draws from the namespace's stream.
357
+ */
358
+ fire(rules: readonly FaultRule$1[], candidate: FaultCandidate$1): Promise<FaultHit$1[]>;
359
+ };
360
+
361
+ /**
362
+ * The admin controls every mock shares, as one document.
363
+ *
364
+ * The same shape is accepted in three places, and means the same thing in each:
365
+ *
366
+ * - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
367
+ * `MOCKINGBIRD_ADMIN_CONTROLS`
368
+ * - over HTTP: `PUT /__admin/controls`
369
+ * - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
370
+ *
371
+ * Every control is deterministic: given the same seed, clock and requests, a mock answers
372
+ * the same bytes. Nothing here reads the wall clock or `Math.random`.
373
+ */
374
+ /** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
375
+ type Duration$1 = number | string;
376
+ /** Epoch milliseconds, or an ISO-8601 string. */
377
+ type Instant$1 = number | string;
378
+ type ClockControls$1 = {
379
+ /** Move the clock to this instant. */
380
+ now?: Instant$1;
381
+ /** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
382
+ frozen?: boolean;
383
+ /**
384
+ * Step the clock forward by this much before every vendor request. With a frozen clock
385
+ * each request still gets its own, reproducible timestamp.
386
+ */
387
+ autoAdvance?: Duration$1;
388
+ };
389
+ /** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
390
+ type LatencyRuleInput$1 = {
391
+ delay?: Duration$1;
392
+ jitter?: Duration$1;
393
+ };
394
+ type LatencyControls$1 = LatencyRuleInput$1 & {
395
+ /** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
396
+ operations?: Record<string, Duration$1 | LatencyRuleInput$1>;
397
+ };
398
+ /** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
399
+ type FaultInput$1 = (Omit<FaultRule$1, "id"> & {
400
+ id?: string;
401
+ }) | ({
402
+ preset: string;
403
+ } & Partial<FaultRule$1>);
404
+ /** Identifies a {@link SnapshotDocument}. */
405
+ declare const SNAPSHOT_FORMAT$1 = "mockingbird.snapshot/v1";
406
+ /**
407
+ * A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
408
+ * `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
409
+ * `records` are required, so a hand-written seed file is a valid snapshot.
410
+ */
411
+ type SnapshotDocument$1 = {
412
+ format: typeof SNAPSHOT_FORMAT$1;
413
+ /** The service that wrote it. A snapshot is rejected by any other service. */
414
+ service?: string;
415
+ /**
416
+ * Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
417
+ * the stored text of a row that is not a plain record, and replaces `value` when present.
418
+ */
419
+ records: {
420
+ collection: string;
421
+ id: string;
422
+ seq?: number;
423
+ value?: unknown;
424
+ raw?: string;
425
+ }[];
426
+ /** Id counters, so the next generated id continues where the snapshot left off. */
427
+ sequences?: {
428
+ name: string;
429
+ kind: string;
430
+ value: number;
431
+ }[];
432
+ clock?: {
433
+ now: number;
434
+ frozen: boolean;
435
+ autoAdvanceMs?: number;
436
+ };
437
+ seed?: number | string;
438
+ /** Positions of the seeded random streams. */
439
+ rng?: {
440
+ state: number;
441
+ faults?: number;
442
+ latency?: number;
443
+ };
444
+ faults?: unknown;
445
+ latency?: unknown;
446
+ virtualTime?: boolean;
447
+ /** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
448
+ webhooks?: unknown;
449
+ };
450
+ /** Controls for one namespace. */
451
+ type NamespaceControls$1 = {
452
+ /** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
453
+ seed?: number | string;
454
+ clock?: ClockControls$1;
455
+ /**
456
+ * Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
457
+ * wall clock: the request returns at once, the clock has moved, and the journal records
458
+ * the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
459
+ */
460
+ virtualTime?: boolean;
461
+ /** Baseline response time for every vendor request. A bare duration is its `delay`. */
462
+ latency?: Duration$1 | LatencyControls$1;
463
+ faults?: readonly FaultInput$1[];
464
+ /** Start from this state instead of the service's own seed data. */
465
+ snapshot?: SnapshotDocument$1;
466
+ };
467
+ /** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
468
+ type MockControls$1 = NamespaceControls$1 & {
469
+ /** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
470
+ credentials?: Record<string, string>;
471
+ /** Overrides for named namespaces. A key given here replaces the shared value. */
472
+ namespaces?: Record<string, NamespaceControls$1>;
473
+ };
474
+ /** A latency rule in milliseconds. */
475
+ type LatencyRule$1 = {
476
+ delayMs: number;
477
+ jitterMs: number;
478
+ };
479
+ /** Baseline latency for a namespace, normalized. */
480
+ type LatencyState$1 = LatencyRule$1 & {
481
+ operations: Record<string, LatencyRule$1>;
482
+ };
483
+ /** What {@link controlHeaders} turns into request headers. */
484
+ type ControlHeaderInput$1 = {
485
+ namespace?: string;
486
+ adminKey?: string;
487
+ branch?: string;
488
+ at?: string;
489
+ reset?: boolean;
490
+ restore?: string;
491
+ seed?: number | string;
492
+ time?: Instant$1 | Date;
493
+ advance?: Duration$1;
494
+ virtualTime?: boolean;
495
+ delay?: Duration$1;
496
+ timeout?: Duration$1;
497
+ /** A status, `"drop"`, a preset name, or a fault rule. */
498
+ fault?: number | string | Record<string, unknown>;
499
+ snapshot?: string;
290
500
  };
291
501
 
292
502
  /**
@@ -326,6 +536,8 @@ type RequestLog$1 = {
326
536
  unmatched: boolean;
327
537
  /** Set when a fault rule produced the response. */
328
538
  faultId?: string;
539
+ /** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
540
+ delayMs?: number;
329
541
  /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
330
542
  ids?: Record<string, string>;
331
543
  /** Set when the service created a resource the request referred to but that did not exist. */
@@ -371,6 +583,12 @@ type JournalQuery$1 = {
371
583
  /** Only this namespace. Omit for every namespace, oldest first across all of them. */
372
584
  namespace?: string;
373
585
  operationId?: string;
586
+ /** Only this HTTP method, case-insensitive. */
587
+ method?: string;
588
+ /** Only this exact path. */
589
+ path?: string;
590
+ /** Only requests this fault rule answered or shaped. */
591
+ faultId?: string;
374
592
  status?: number;
375
593
  /** Only entries at or after this instant (epoch ms). */
376
594
  since?: number;
@@ -385,6 +603,50 @@ type Journal$1 = {
385
603
  clear(namespace?: string): void;
386
604
  };
387
605
 
606
+ /**
607
+ * Baseline response time, per namespace: how long every vendor request takes before any
608
+ * fault is considered. Jitter draws from a stream the caller owns, one per namespace and
609
+ * separate from the fault stream, so adding latency never shifts which requests a `rate`
610
+ * fault hits.
611
+ */
612
+ type LatencyRegistry$1 = {
613
+ get(namespace: string): LatencyState$1;
614
+ set(namespace: string, state: LatencyState$1): LatencyState$1;
615
+ /** Remove one namespace's latency, or every namespace's. */
616
+ clear(namespace?: string): void;
617
+ /** Milliseconds this request waits. Draws jitter, so call it once per request. */
618
+ take(namespace: string, operationId: string | undefined): number;
619
+ };
620
+
621
+ /** Clock state as the admin API reports it. */
622
+ type ControlClock$1 = ClockState$1 & {
623
+ /** `now`, as ISO-8601. */
624
+ iso: string;
625
+ /** Milliseconds the clock steps before every vendor request. */
626
+ autoAdvanceMs: number;
627
+ };
628
+ /** One namespace's controls: the body of `GET /__admin/controls`. */
629
+ type ControlState$1 = {
630
+ namespace: string;
631
+ seed: number | string;
632
+ clock: ControlClock$1;
633
+ virtualTime: boolean;
634
+ latency: LatencyState$1;
635
+ faults: FaultListing$1[];
636
+ };
637
+
638
+ /** What `GET /__admin/snapshots` lists for each snapshot. */
639
+ type SnapshotInfo$1 = {
640
+ id: string;
641
+ namespace: string;
642
+ /** Stored rows in the snapshot. */
643
+ records: number;
644
+ /** The namespace clock when it was taken, epoch ms. */
645
+ at: number;
646
+ /** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
647
+ portable: boolean;
648
+ };
649
+
388
650
  /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
389
651
  type CredentialRegistry$1 = {
390
652
  set(credential: string, namespace: string): void;
@@ -397,6 +659,8 @@ type CredentialRegistry$1 = {
397
659
  }[];
398
660
  };
399
661
 
662
+ type OwnedTransport$1 = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
663
+
400
664
  /**
401
665
  * A point-in-time copy of everything a service namespace holds.
402
666
  *
@@ -514,8 +778,16 @@ type PublishInput$1 = {
514
778
  id?: string;
515
779
  };
516
780
  type WebhookHub$1 = {
781
+ observeDeliveries(listener: (event: {
782
+ namespace: string;
783
+ state: string;
784
+ deliveryId: string;
785
+ }) => void): () => void;
786
+ setTransportPolicy(policy: OwnedTransport$1): void;
517
787
  pending(namespace: string): number;
518
788
  snapshot(namespace: string): unknown;
789
+ exportSnapshot(handle: unknown): unknown;
790
+ importSnapshot(namespace: string, document: unknown): unknown;
519
791
  restore(namespace: string, snapshot: unknown): void;
520
792
  publish(input: PublishInput$1): WebhookMessage$1;
521
793
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
@@ -528,7 +800,7 @@ type WebhookHub$1 = {
528
800
  /** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
529
801
  flush(): Promise<void>;
530
802
  /** Resolve once nothing is in flight. */
531
- idle(): Promise<void>;
803
+ idle(namespace?: string): Promise<void>;
532
804
  fault(namespace: string, fault: WebhookFault$1): void;
533
805
  clear(namespace?: string): void;
534
806
  };
@@ -539,7 +811,10 @@ type ServiceInstance$1 = FetchAPI$1 & {
539
811
  };
540
812
  type ServiceTimelineState$1 = Readonly<{
541
813
  snapshot: NamespaceSnapshot$1;
542
- clock: Readonly<ReturnType<Clock$1["state"]>>;
814
+ /** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
815
+ clock: Readonly<ClockState$1 & {
816
+ pinned?: boolean;
817
+ }>;
543
818
  rngState: number;
544
819
  }>;
545
820
  type ServiceCheckpoint$1 = Checkpoint$1<ServiceTimelineState$1>;
@@ -552,27 +827,63 @@ type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$1 & {
552
827
  readonly sqlite: SqliteClient$2;
553
828
  readonly clock: Clock$1;
554
829
  readonly faults: FaultRegistry$1;
830
+ /** Baseline response time per namespace. */
831
+ readonly latency: LatencyRegistry$1;
555
832
  readonly metrics: Metrics$1;
556
833
  readonly journal: Journal$1;
557
834
  readonly rng: Rng$1;
558
835
  readonly credentials: CredentialRegistry$1;
559
836
  /** The webhook hub, when the service has outbound webhooks. */
560
837
  readonly webhooks: WebhookHub$1 | undefined;
561
- /** Enable independent namespace clocks and PRNGs before serving a fleet. */
562
- isolateNamespaces(): void;
838
+ /**
839
+ * A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
840
+ * offset and a freeze of its own, so moving one never moves another.
841
+ */
563
842
  namespaceClock(namespace?: string): Clock$1;
564
843
  namespaceOf(request: Request): string;
565
844
  /** Opaque in-process checkpoint including records, controls and webhook history. */
566
845
  fleetSnapshot(namespace: string): object;
567
846
  fleetRestore(snapshot: unknown, namespace: string): void;
847
+ fleetExport(snapshot: unknown): SnapshotDocument$1;
848
+ fleetImport(namespace: string, document: unknown): object;
568
849
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
569
850
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule$1>): FaultRule$1[];
570
851
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
571
852
  instance(namespace?: string): T;
572
853
  /** Public names of every namespace created so far. */
573
854
  namespaces(): string[];
574
- /** Reset one namespace, or every namespace with `"*"`. */
855
+ /** Return one namespace to its boot state, or every namespace with `"*"`. */
575
856
  reset(namespace?: string): Promise<void>;
857
+ /** Reset a namespace and forget it, releasing everything it held. */
858
+ dropNamespace(namespace: string): Promise<void>;
859
+ /** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
860
+ controls(namespace?: string): ControlState$1 & {
861
+ snapshots: SnapshotInfo$1[];
862
+ };
863
+ /** Apply a control document to a namespace. A given key replaces that control. */
864
+ configure(controls: NamespaceControls$1, namespace?: string): ControlState$1 & {
865
+ snapshots: SnapshotInfo$1[];
866
+ };
867
+ /** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
868
+ readonly snapshots: {
869
+ /** Capture the namespace now. Reusing a name replaces that snapshot. */
870
+ create(options?: {
871
+ name?: string;
872
+ namespace?: string;
873
+ }): SnapshotInfo$1;
874
+ list(namespace?: string): SnapshotInfo$1[];
875
+ /** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
876
+ export(id: string, namespace?: string): SnapshotDocument$1;
877
+ /** Store a document as a snapshot without restoring it. */
878
+ import(document: SnapshotDocument$1, options?: {
879
+ name?: string;
880
+ namespace?: string;
881
+ }): SnapshotInfo$1;
882
+ restore(id: string, namespace?: string): void;
883
+ delete(id: string, namespace?: string): boolean;
884
+ };
885
+ /** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
886
+ headers(input: ControlHeaderInput$1): Record<string, string>;
576
887
  snapshot(namespace?: string): NamespaceSnapshot$1;
577
888
  restore(snapshot: NamespaceSnapshot$1, namespace?: string): void;
578
889
  /** Capture the current branch. Mutating HTTP calls do this automatically. */
@@ -615,6 +926,8 @@ type CommonServeOptions = {
615
926
  adminKey: string | undefined;
616
927
  seed: string | undefined;
617
928
  onLog: ((entry: RequestLog$1) => void) | undefined;
929
+ /** Admin controls to boot with: clock, latency, faults, a starting snapshot. */
930
+ adminControls?: MockControls$1;
618
931
  /** Synthetic provider fixture objects supplied by a fleet entry. */
619
932
  fixtures?: Record<string, unknown>;
620
933
  baseUrl?: string;
@@ -625,6 +938,7 @@ type CommonServeOptions = {
625
938
  * `serveTarget`, which is also how `serve --config` finds services by name.
626
939
  */
627
940
  type ServeTarget = {
941
+ packageVersion?: string;
628
942
  name: string;
629
943
  defaultPort: number;
630
944
  /** Serve flags beyond the common ones. */
@@ -847,7 +1161,7 @@ type ClockState = {
847
1161
  now: number;
848
1162
  /** True while time does not advance on its own. */
849
1163
  frozen: boolean;
850
- /** Milliseconds this clock adds to its underlying source. */
1164
+ /** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
851
1165
  offsetMs: number;
852
1166
  };
853
1167
  type Clock = {
@@ -883,7 +1197,10 @@ type Rng = {
883
1197
  state(): number;
884
1198
  /** Restore a state previously returned by {@link state}. */
885
1199
  setState(state: number): void;
886
- seed: number;
1200
+ /** Restart the stream from a new seed. `reset` then returns to this seed. */
1201
+ reseed(seed: number | string): void;
1202
+ /** The seed the stream currently starts from. */
1203
+ readonly seed: number;
887
1204
  };
888
1205
 
889
1206
  /**
@@ -892,44 +1209,83 @@ type Rng = {
892
1209
  * This is how a suite reaches the vendor's failure modes without the vendor: the
893
1210
  * quota error that only appears when a shared sandbox is full, the 429 that only
894
1211
  * appears under load, the 5xx that proves a retry path works.
1212
+ *
1213
+ * A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
1214
+ * it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
1215
+ * and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
895
1216
  */
896
1217
  type FaultRule = {
897
- /** Stable id, so a suite can retire exactly the rule it added. */
1218
+ /** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
898
1219
  id: string;
899
1220
  /** Fault only this operation. Omit to match every operation. */
900
1221
  operationId?: string;
901
1222
  /** Fault only this HTTP method, case-insensitive. Omit to match every method. */
902
1223
  method?: string;
1224
+ /** Fault only this exact path. */
1225
+ path?: string;
903
1226
  /** Fault only paths starting with this prefix. Omit to match every path. */
904
1227
  pathPrefix?: string;
1228
+ /** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
1229
+ pathPattern?: string;
1230
+ /** Fault only requests carrying these headers. `"*"` matches any value. */
1231
+ requestHeaders?: Record<string, string>;
1232
+ /** Fault only requests carrying these query parameters. `"*"` matches any value. */
1233
+ query?: Record<string, string>;
905
1234
  /**
906
1235
  * Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
907
1236
  * an in-process caller usually wants, and what a parallel worker usually does not:
908
1237
  * rules added through `POST /__admin/faults` default to the calling namespace.
909
1238
  */
910
1239
  namespace?: string;
1240
+ /** Let this many matching requests through first. */
1241
+ after?: number;
1242
+ /** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
1243
+ every?: number;
1244
+ /** Retire the rule after this many faults. Omit to keep it until removed. */
1245
+ count?: number;
1246
+ /** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
1247
+ rate?: number;
1248
+ /**
1249
+ * Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
1250
+ * clock when the rule was added. Listed as epoch ms.
1251
+ */
1252
+ from?: Instant | Duration;
1253
+ /** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
1254
+ until?: Instant | Duration;
911
1255
  /**
912
- * Status of the injected response. Omit for a rule that only delays (`delayMs` /
913
- * `latencyMs`), only drops the connection (`drop`), or only switches on an `effect`:
914
- * the request then still reaches the service.
1256
+ * Status of the injected response. Omit for a rule that only delays, times out, drops,
1257
+ * truncates, or switches on an `effect`: the request then still reaches the service.
915
1258
  */
916
1259
  status?: number;
917
1260
  /** Response body, serialized as JSON. A string is sent as-is. */
918
1261
  body?: unknown;
1262
+ /** Response headers. */
919
1263
  headers?: Record<string, string>;
920
- /** Retire the rule after this many faults. Omit to keep it until removed. */
921
- count?: number;
922
- /** Fault this fraction of matching requests, `0`–`1`. Default `1`. */
923
- rate?: number;
924
- /** Hold the response back this long, to exercise timeouts. */
1264
+ /** Hold the response back this long. Listed as `delayMs`. */
1265
+ delay?: Duration;
1266
+ /** `delay`, in milliseconds. */
925
1267
  delayMs?: number;
926
1268
  /** Alias of `delayMs`. */
927
1269
  latencyMs?: number;
1270
+ /** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
1271
+ jitter?: Duration;
1272
+ jitterMs?: number;
1273
+ /**
1274
+ * Never answer: hold the request this long, then drop the connection. Listed as
1275
+ * `timeoutMs`. With virtual time the wait is spent on the mock clock.
1276
+ */
1277
+ timeout?: Duration;
1278
+ timeoutMs?: number;
928
1279
  /**
929
1280
  * Drop the connection instead of answering: an in-process `fetch` rejects with a
930
1281
  * `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
931
1282
  */
932
1283
  drop?: boolean;
1284
+ /**
1285
+ * Cut the response body off after this many bytes: the status and headers arrive, then
1286
+ * the connection dies mid-body.
1287
+ */
1288
+ truncate?: number;
933
1289
  /**
934
1290
  * A named service behaviour to switch on for the matching request instead of (or
935
1291
  * before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
@@ -938,8 +1294,8 @@ type FaultRule = {
938
1294
  effect?: string;
939
1295
  /** Parameters for `effect`. */
940
1296
  params?: Record<string, unknown>;
941
- /** From the preset this rule was expanded from, if any. */
942
- preset?: string;
1297
+ /** The preset this rule was expanded from, if any. */
1298
+ fromPreset?: string;
943
1299
  };
944
1300
  /** A fault that fired for one request. */
945
1301
  type FaultHit = {
@@ -947,6 +1303,10 @@ type FaultHit = {
947
1303
  /** The injected response; absent when the rule only delays, drops, or sets an effect. */
948
1304
  response?: Response;
949
1305
  drop?: boolean;
1306
+ /** Set with `drop` when the rule held the request for its `timeout` first. */
1307
+ timeout?: boolean;
1308
+ /** Bytes of response body to let through before the connection dies. */
1309
+ truncate?: number;
950
1310
  effect?: {
951
1311
  name: string;
952
1312
  params: Record<string, unknown>;
@@ -958,38 +1318,202 @@ type FaultCandidate = {
958
1318
  method: string;
959
1319
  path: string;
960
1320
  namespace: string;
1321
+ /** Request headers and query, for rules that match on them. */
1322
+ headers?: Headers;
1323
+ query?: URLSearchParams;
1324
+ /** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
1325
+ now?: number;
1326
+ /** How to spend a delay for this request. Default: the registry's own sleep. */
1327
+ wait?: (ms: number) => Promise<void>;
1328
+ };
1329
+ /** A stored rule and how often it was consulted. */
1330
+ type FaultListing = FaultRule & {
1331
+ /** Faults left before the rule retires. `null` when it has no `count`. */
1332
+ remaining: number | null;
1333
+ /** Times the rule faulted a request. */
1334
+ hits: number;
1335
+ /** Requests that matched the rule, faulted or not. */
1336
+ seen: number;
1337
+ };
1338
+ /** A namespace's own rules, with their counters, in the order they are tried. */
1339
+ type FaultSnapshot = {
1340
+ /**
1341
+ * `position` is how many `"*"` rules are tried before the rule, which is what its place
1342
+ * in the order means to a request and holds in any process.
1343
+ */
1344
+ rules: (FaultListing & {
1345
+ position?: number;
1346
+ })[];
1347
+ /** How many `fault_<n>` ids the namespace has handed out. */
1348
+ nextId?: number;
961
1349
  };
962
1350
  type FaultRegistry = {
963
- isolateNamespaces(): void;
964
- snapshot(namespace: string): {
965
- rules: (FaultRule & {
966
- remaining: number | null;
967
- hits: number;
968
- position: number;
969
- })[];
970
- rngState: number;
971
- };
1351
+ snapshot(namespace: string): FaultSnapshot;
1352
+ /** Add a rule, or replace the rule with the same id in the same namespace. */
972
1353
  add(rule: FaultRule): FaultRule;
973
- list(): (FaultRule & {
974
- remaining: number | null;
975
- hits: number;
976
- })[];
977
- remove(id: string): boolean;
978
- clear(): void;
979
- restore(namespace: string, state: {
980
- rules: (FaultRule & {
981
- remaining: number | null;
982
- hits: number;
983
- position: number;
984
- })[];
985
- rngState: number;
986
- }): void;
1354
+ /** The next unused `fault_<n>` id in `namespace`. */
1355
+ nextId(namespace: string): string;
1356
+ /** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
1357
+ list(namespace?: string): FaultListing[];
1358
+ get(id: string, namespace?: string): FaultListing | undefined;
1359
+ /** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
1360
+ remove(id: string, namespace?: string): boolean;
1361
+ /** Remove every rule, or one namespace's own rules. */
1362
+ clear(namespace?: string): void;
1363
+ /** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
1364
+ restore(namespace: string, state: FaultSnapshot): void;
987
1365
  /**
988
1366
  * Every fault this request should get, in rule order, stopping at the first that answers
989
1367
  * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
990
1368
  * each matching rule's remaining uses.
991
1369
  */
992
1370
  take(candidate: FaultCandidate): Promise<FaultHit[]>;
1371
+ /**
1372
+ * Fire these rules at one request without storing them: no matching, no schedule, in order,
1373
+ * stopping at the first that answers or drops. Jitter draws from the namespace's stream.
1374
+ */
1375
+ fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
1376
+ };
1377
+
1378
+ /**
1379
+ * The admin controls every mock shares, as one document.
1380
+ *
1381
+ * The same shape is accepted in three places, and means the same thing in each:
1382
+ *
1383
+ * - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
1384
+ * `MOCKINGBIRD_ADMIN_CONTROLS`
1385
+ * - over HTTP: `PUT /__admin/controls`
1386
+ * - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
1387
+ *
1388
+ * Every control is deterministic: given the same seed, clock and requests, a mock answers
1389
+ * the same bytes. Nothing here reads the wall clock or `Math.random`.
1390
+ */
1391
+ /** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
1392
+ type Duration = number | string;
1393
+ /** Epoch milliseconds, or an ISO-8601 string. */
1394
+ type Instant = number | string;
1395
+ type ClockControls = {
1396
+ /** Move the clock to this instant. */
1397
+ now?: Instant;
1398
+ /** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
1399
+ frozen?: boolean;
1400
+ /**
1401
+ * Step the clock forward by this much before every vendor request. With a frozen clock
1402
+ * each request still gets its own, reproducible timestamp.
1403
+ */
1404
+ autoAdvance?: Duration;
1405
+ };
1406
+ /** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
1407
+ type LatencyRuleInput = {
1408
+ delay?: Duration;
1409
+ jitter?: Duration;
1410
+ };
1411
+ type LatencyControls = LatencyRuleInput & {
1412
+ /** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
1413
+ operations?: Record<string, Duration | LatencyRuleInput>;
1414
+ };
1415
+ /** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
1416
+ type FaultInput = (Omit<FaultRule, "id"> & {
1417
+ id?: string;
1418
+ }) | ({
1419
+ preset: string;
1420
+ } & Partial<FaultRule>);
1421
+ /** Identifies a {@link SnapshotDocument}. */
1422
+ declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
1423
+ /**
1424
+ * A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
1425
+ * `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
1426
+ * `records` are required, so a hand-written seed file is a valid snapshot.
1427
+ */
1428
+ type SnapshotDocument = {
1429
+ format: typeof SNAPSHOT_FORMAT;
1430
+ /** The service that wrote it. A snapshot is rejected by any other service. */
1431
+ service?: string;
1432
+ /**
1433
+ * Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
1434
+ * the stored text of a row that is not a plain record, and replaces `value` when present.
1435
+ */
1436
+ records: {
1437
+ collection: string;
1438
+ id: string;
1439
+ seq?: number;
1440
+ value?: unknown;
1441
+ raw?: string;
1442
+ }[];
1443
+ /** Id counters, so the next generated id continues where the snapshot left off. */
1444
+ sequences?: {
1445
+ name: string;
1446
+ kind: string;
1447
+ value: number;
1448
+ }[];
1449
+ clock?: {
1450
+ now: number;
1451
+ frozen: boolean;
1452
+ autoAdvanceMs?: number;
1453
+ };
1454
+ seed?: number | string;
1455
+ /** Positions of the seeded random streams. */
1456
+ rng?: {
1457
+ state: number;
1458
+ faults?: number;
1459
+ latency?: number;
1460
+ };
1461
+ faults?: unknown;
1462
+ latency?: unknown;
1463
+ virtualTime?: boolean;
1464
+ /** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
1465
+ webhooks?: unknown;
1466
+ };
1467
+ /** Controls for one namespace. */
1468
+ type NamespaceControls = {
1469
+ /** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
1470
+ seed?: number | string;
1471
+ clock?: ClockControls;
1472
+ /**
1473
+ * Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
1474
+ * wall clock: the request returns at once, the clock has moved, and the journal records
1475
+ * the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
1476
+ */
1477
+ virtualTime?: boolean;
1478
+ /** Baseline response time for every vendor request. A bare duration is its `delay`. */
1479
+ latency?: Duration | LatencyControls;
1480
+ faults?: readonly FaultInput[];
1481
+ /** Start from this state instead of the service's own seed data. */
1482
+ snapshot?: SnapshotDocument;
1483
+ };
1484
+ /** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
1485
+ type MockControls = NamespaceControls & {
1486
+ /** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
1487
+ credentials?: Record<string, string>;
1488
+ /** Overrides for named namespaces. A key given here replaces the shared value. */
1489
+ namespaces?: Record<string, NamespaceControls>;
1490
+ };
1491
+ /** A latency rule in milliseconds. */
1492
+ type LatencyRule = {
1493
+ delayMs: number;
1494
+ jitterMs: number;
1495
+ };
1496
+ /** Baseline latency for a namespace, normalized. */
1497
+ type LatencyState = LatencyRule & {
1498
+ operations: Record<string, LatencyRule>;
1499
+ };
1500
+ /** What {@link controlHeaders} turns into request headers. */
1501
+ type ControlHeaderInput = {
1502
+ namespace?: string;
1503
+ adminKey?: string;
1504
+ branch?: string;
1505
+ at?: string;
1506
+ reset?: boolean;
1507
+ restore?: string;
1508
+ seed?: number | string;
1509
+ time?: Instant | Date;
1510
+ advance?: Duration;
1511
+ virtualTime?: boolean;
1512
+ delay?: Duration;
1513
+ timeout?: Duration;
1514
+ /** A status, `"drop"`, a preset name, or a fault rule. */
1515
+ fault?: number | string | Record<string, unknown>;
1516
+ snapshot?: string;
993
1517
  };
994
1518
 
995
1519
  /**
@@ -1029,6 +1553,8 @@ type RequestLog = {
1029
1553
  unmatched: boolean;
1030
1554
  /** Set when a fault rule produced the response. */
1031
1555
  faultId?: string;
1556
+ /** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
1557
+ delayMs?: number;
1032
1558
  /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
1033
1559
  ids?: Record<string, string>;
1034
1560
  /** Set when the service created a resource the request referred to but that did not exist. */
@@ -1074,6 +1600,12 @@ type JournalQuery = {
1074
1600
  /** Only this namespace. Omit for every namespace, oldest first across all of them. */
1075
1601
  namespace?: string;
1076
1602
  operationId?: string;
1603
+ /** Only this HTTP method, case-insensitive. */
1604
+ method?: string;
1605
+ /** Only this exact path. */
1606
+ path?: string;
1607
+ /** Only requests this fault rule answered or shaped. */
1608
+ faultId?: string;
1077
1609
  status?: number;
1078
1610
  /** Only entries at or after this instant (epoch ms). */
1079
1611
  since?: number;
@@ -1088,6 +1620,50 @@ type Journal = {
1088
1620
  clear(namespace?: string): void;
1089
1621
  };
1090
1622
 
1623
+ /**
1624
+ * Baseline response time, per namespace: how long every vendor request takes before any
1625
+ * fault is considered. Jitter draws from a stream the caller owns, one per namespace and
1626
+ * separate from the fault stream, so adding latency never shifts which requests a `rate`
1627
+ * fault hits.
1628
+ */
1629
+ type LatencyRegistry = {
1630
+ get(namespace: string): LatencyState;
1631
+ set(namespace: string, state: LatencyState): LatencyState;
1632
+ /** Remove one namespace's latency, or every namespace's. */
1633
+ clear(namespace?: string): void;
1634
+ /** Milliseconds this request waits. Draws jitter, so call it once per request. */
1635
+ take(namespace: string, operationId: string | undefined): number;
1636
+ };
1637
+
1638
+ /** Clock state as the admin API reports it. */
1639
+ type ControlClock = ClockState & {
1640
+ /** `now`, as ISO-8601. */
1641
+ iso: string;
1642
+ /** Milliseconds the clock steps before every vendor request. */
1643
+ autoAdvanceMs: number;
1644
+ };
1645
+ /** One namespace's controls: the body of `GET /__admin/controls`. */
1646
+ type ControlState = {
1647
+ namespace: string;
1648
+ seed: number | string;
1649
+ clock: ControlClock;
1650
+ virtualTime: boolean;
1651
+ latency: LatencyState;
1652
+ faults: FaultListing[];
1653
+ };
1654
+
1655
+ /** What `GET /__admin/snapshots` lists for each snapshot. */
1656
+ type SnapshotInfo = {
1657
+ id: string;
1658
+ namespace: string;
1659
+ /** Stored rows in the snapshot. */
1660
+ records: number;
1661
+ /** The namespace clock when it was taken, epoch ms. */
1662
+ at: number;
1663
+ /** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
1664
+ portable: boolean;
1665
+ };
1666
+
1091
1667
  /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
1092
1668
  type CredentialRegistry = {
1093
1669
  set(credential: string, namespace: string): void;
@@ -1100,6 +1676,8 @@ type CredentialRegistry = {
1100
1676
  }[];
1101
1677
  };
1102
1678
 
1679
+ type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
1680
+
1103
1681
  /**
1104
1682
  * A point-in-time copy of everything a service namespace holds.
1105
1683
  *
@@ -1217,8 +1795,16 @@ type PublishInput = {
1217
1795
  id?: string;
1218
1796
  };
1219
1797
  type WebhookHub = {
1798
+ observeDeliveries(listener: (event: {
1799
+ namespace: string;
1800
+ state: string;
1801
+ deliveryId: string;
1802
+ }) => void): () => void;
1803
+ setTransportPolicy(policy: OwnedTransport): void;
1220
1804
  pending(namespace: string): number;
1221
1805
  snapshot(namespace: string): unknown;
1806
+ exportSnapshot(handle: unknown): unknown;
1807
+ importSnapshot(namespace: string, document: unknown): unknown;
1222
1808
  restore(namespace: string, snapshot: unknown): void;
1223
1809
  publish(input: PublishInput): WebhookMessage;
1224
1810
  /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
@@ -1231,7 +1817,7 @@ type WebhookHub = {
1231
1817
  /** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
1232
1818
  flush(): Promise<void>;
1233
1819
  /** Resolve once nothing is in flight. */
1234
- idle(): Promise<void>;
1820
+ idle(namespace?: string): Promise<void>;
1235
1821
  fault(namespace: string, fault: WebhookFault): void;
1236
1822
  clear(namespace?: string): void;
1237
1823
  };
@@ -1242,7 +1828,10 @@ type ServiceInstance = FetchAPI & {
1242
1828
  };
1243
1829
  type ServiceTimelineState = Readonly<{
1244
1830
  snapshot: NamespaceSnapshot;
1245
- clock: Readonly<ReturnType<Clock["state"]>>;
1831
+ /** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
1832
+ clock: Readonly<ClockState & {
1833
+ pinned?: boolean;
1834
+ }>;
1246
1835
  rngState: number;
1247
1836
  }>;
1248
1837
  type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
@@ -1255,27 +1844,63 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
1255
1844
  readonly sqlite: SqliteClient$1;
1256
1845
  readonly clock: Clock;
1257
1846
  readonly faults: FaultRegistry;
1847
+ /** Baseline response time per namespace. */
1848
+ readonly latency: LatencyRegistry;
1258
1849
  readonly metrics: Metrics;
1259
1850
  readonly journal: Journal;
1260
1851
  readonly rng: Rng;
1261
1852
  readonly credentials: CredentialRegistry;
1262
1853
  /** The webhook hub, when the service has outbound webhooks. */
1263
1854
  readonly webhooks: WebhookHub | undefined;
1264
- /** Enable independent namespace clocks and PRNGs before serving a fleet. */
1265
- isolateNamespaces(): void;
1855
+ /**
1856
+ * A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
1857
+ * offset and a freeze of its own, so moving one never moves another.
1858
+ */
1266
1859
  namespaceClock(namespace?: string): Clock;
1267
1860
  namespaceOf(request: Request): string;
1268
1861
  /** Opaque in-process checkpoint including records, controls and webhook history. */
1269
1862
  fleetSnapshot(namespace: string): object;
1270
1863
  fleetRestore(snapshot: unknown, namespace: string): void;
1864
+ fleetExport(snapshot: unknown): SnapshotDocument;
1865
+ fleetImport(namespace: string, document: unknown): object;
1271
1866
  /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
1272
1867
  applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
1273
1868
  /** The instance behind `namespace` (the default one when omitted), created on first use. */
1274
1869
  instance(namespace?: string): T;
1275
1870
  /** Public names of every namespace created so far. */
1276
1871
  namespaces(): string[];
1277
- /** Reset one namespace, or every namespace with `"*"`. */
1872
+ /** Return one namespace to its boot state, or every namespace with `"*"`. */
1278
1873
  reset(namespace?: string): Promise<void>;
1874
+ /** Reset a namespace and forget it, releasing everything it held. */
1875
+ dropNamespace(namespace: string): Promise<void>;
1876
+ /** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
1877
+ controls(namespace?: string): ControlState & {
1878
+ snapshots: SnapshotInfo[];
1879
+ };
1880
+ /** Apply a control document to a namespace. A given key replaces that control. */
1881
+ configure(controls: NamespaceControls, namespace?: string): ControlState & {
1882
+ snapshots: SnapshotInfo[];
1883
+ };
1884
+ /** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
1885
+ readonly snapshots: {
1886
+ /** Capture the namespace now. Reusing a name replaces that snapshot. */
1887
+ create(options?: {
1888
+ name?: string;
1889
+ namespace?: string;
1890
+ }): SnapshotInfo;
1891
+ list(namespace?: string): SnapshotInfo[];
1892
+ /** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
1893
+ export(id: string, namespace?: string): SnapshotDocument;
1894
+ /** Store a document as a snapshot without restoring it. */
1895
+ import(document: SnapshotDocument, options?: {
1896
+ name?: string;
1897
+ namespace?: string;
1898
+ }): SnapshotInfo;
1899
+ restore(id: string, namespace?: string): void;
1900
+ delete(id: string, namespace?: string): boolean;
1901
+ };
1902
+ /** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
1903
+ headers(input: ControlHeaderInput): Record<string, string>;
1279
1904
  snapshot(namespace?: string): NamespaceSnapshot;
1280
1905
  restore(snapshot: NamespaceSnapshot, namespace?: string): void;
1281
1906
  /** Capture the current branch. Mutating HTTP calls do this automatically. */
@@ -1413,6 +2038,8 @@ type StepFunctionsRuntimeOptions = {
1413
2038
  seed?: number | string;
1414
2039
  adminPrefix?: string;
1415
2040
  adminKey?: string;
2041
+ /** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
2042
+ adminControls?: MockControls;
1416
2043
  onLog?: (entry: RequestLog) => void;
1417
2044
  region?: string;
1418
2045
  accountId?: string;