eutaxy 0.9.1 → 0.11.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.
Files changed (39) hide show
  1. package/README.md +14 -12
  2. package/dist/aws.d.mts +2 -2
  3. package/dist/aws.d.mts.map +1 -1
  4. package/dist/aws.mjs +22 -38
  5. package/dist/aws.mjs.map +1 -1
  6. package/dist/bin.mjs +2 -2
  7. package/dist/{checksum-DHr5qb3Y.mjs → checksum-DJbbDJA0.mjs} +3 -3
  8. package/dist/{checksum-DHr5qb3Y.mjs.map → checksum-DJbbDJA0.mjs.map} +1 -1
  9. package/dist/cli-CMJqrBq-.mjs +2 -0
  10. package/dist/cli.d.mts.map +1 -1
  11. package/dist/cli.mjs +2 -2
  12. package/dist/cloudflare.d.mts +149 -14
  13. package/dist/cloudflare.d.mts.map +1 -1
  14. package/dist/cloudflare.mjs +3 -3
  15. package/dist/delivery-invariants-Br29H7Rg.mjs +62 -0
  16. package/dist/delivery-invariants-Br29H7Rg.mjs.map +1 -0
  17. package/dist/{delivery-invariants-DfPkJL0Q.d.mts → delivery-invariants-DZOBkCMR.d.mts} +2 -2
  18. package/dist/{delivery-invariants-DfPkJL0Q.d.mts.map → delivery-invariants-DZOBkCMR.d.mts.map} +1 -1
  19. package/dist/{event-streams-i8OGzuFN.mjs → event-streams-eH6Jim9p.mjs} +2 -2
  20. package/dist/{event-streams-i8OGzuFN.mjs.map → event-streams-eH6Jim9p.mjs.map} +1 -1
  21. package/dist/{explore-Rwe1PPqX.d.mts → explore-B7aR_5Hy.d.mts} +2 -2
  22. package/dist/{explore-Rwe1PPqX.d.mts.map → explore-B7aR_5Hy.d.mts.map} +1 -1
  23. package/dist/index.d.mts +2 -2
  24. package/dist/index.mjs +2 -2
  25. package/dist/{platform-Bpnav0kn.d.mts → platform-CCz48WF9.d.mts} +30 -30
  26. package/dist/platform-CCz48WF9.d.mts.map +1 -0
  27. package/dist/{src-BnTcWa-4.mjs → src-BYm3aLWV.mjs} +3461 -1759
  28. package/dist/src-BYm3aLWV.mjs.map +1 -0
  29. package/dist/{src-Db2r3ZDr.mjs → src-CWVQEhTr.mjs} +2 -2
  30. package/dist/{src-Db2r3ZDr.mjs.map → src-CWVQEhTr.mjs.map} +1 -1
  31. package/dist/{src-BRjmbzMV.mjs → src-DGh7w877.mjs} +365 -246
  32. package/dist/src-DGh7w877.mjs.map +1 -0
  33. package/package.json +1 -1
  34. package/dist/cli-CVdHb_gU.mjs +0 -2
  35. package/dist/delivery-invariants-Cg3eVKSw.mjs +0 -39
  36. package/dist/delivery-invariants-Cg3eVKSw.mjs.map +0 -1
  37. package/dist/platform-Bpnav0kn.d.mts.map +0 -1
  38. package/dist/src-BRjmbzMV.mjs.map +0 -1
  39. package/dist/src-BnTcWa-4.mjs.map +0 -1
@@ -214,6 +214,26 @@ function nextInt(state, bound) {
214
214
  * record of which fault was injected at which effect point in one run.
215
215
  */
216
216
  /**
217
+ * The ladders of faults an effect's kind admits, written once; a proxy names
218
+ * one as a point's `allowed` faults. A point with a meaning of its own (the
219
+ * response point, a Workflow step, the background point) lists its own.
220
+ */
221
+ /** An effect that may commit and whose answer may be lost: a write, a call into another system, an outbound request. */
222
+ const writeFaults = [
223
+ "crash_before",
224
+ "crash_after",
225
+ "ambiguous",
226
+ "error"
227
+ ];
228
+ /** An effect with nothing to be ambiguous about: a read, or a handler run whose failure is seen either way. */
229
+ const readFaults = [
230
+ "crash_before",
231
+ "crash_after",
232
+ "error"
233
+ ];
234
+ /** A decision a platform records on the invocation's behalf (an ack, a delete): the invocation may die either side of it; it neither errors nor goes missing. */
235
+ const decisionFaults = ["crash_before", "crash_after"];
236
+ /**
217
237
  * Decide whether to inject a fault at an effect point during exploration.
218
238
  * Pure: the same state and inputs always give the same decision. The PRNG is
219
239
  * only consumed when a fault is possible, so adding an ineligible point does
@@ -667,6 +687,105 @@ function walk(value, extra, depth, seen) {
667
687
  seen.delete(object);
668
688
  }
669
689
  }
690
+ // packages/engine/src/chooser.ts
691
+ /**
692
+ * How a run chooses. A run's nondeterminism is a sequence of decisions: a
693
+ * fault (or none) at each effect point that may take one, and the next turn
694
+ * at each scheduling decision of a concurrent run. One object makes them
695
+ * all. Exploring from a seed draws them (`seededChooser`), replaying a
696
+ * schedule looks them up (`replayChooser`), and exhaustive exploration picks
697
+ * them from the enumerator (`exhaustive.ts`), which walks every sequence of
698
+ * choices once. The run only asks; which faults a run may take, how many and
699
+ * where is the chooser's, so the run loop holds no policy.
700
+ */
701
+ /**
702
+ * Choices drawn from the seed: faults from a stream seeded by it, placed by
703
+ * the plan; turns from a separate stream (`turns:<seed>`), so a fault more
704
+ * or less does not move the picks after it.
705
+ */
706
+ function seededChooser(seed, placement) {
707
+ let faults = seedPrng(seed);
708
+ let turns = seedPrng(`turns:${seed}`);
709
+ let position = 0;
710
+ let injected = 0;
711
+ return {
712
+ seed,
713
+ recordsTurns: false,
714
+ choose(kind, options) {
715
+ if (kind === "turn") {
716
+ if (options.length < 2) return 0;
717
+ const [i, next] = nextInt(turns, options.length);
718
+ turns = next;
719
+ return i;
720
+ }
721
+ if (options.length < 2) return 0;
722
+ const at = position++;
723
+ let i = 0;
724
+ if (placement.faultPlan) {
725
+ if (injected >= placement.maxFaultsPerRun || !placement.faultPlan.includes(at)) return 0;
726
+ const [k, next] = nextInt(faults, options.length - 1);
727
+ faults = next;
728
+ i = k + 1;
729
+ } else {
730
+ const kinds = options.slice(1).map((o) => o.label);
731
+ const [fault, next] = decideFault(faults, kinds, injected, placement);
732
+ faults = next;
733
+ i = fault === null ? 0 : kinds.indexOf(fault) + 1;
734
+ }
735
+ if (i > 0) injected++;
736
+ return i;
737
+ }
738
+ };
739
+ }
740
+ /**
741
+ * Choices a recorded schedule made: its fault at the point (none when it
742
+ * recorded none, or one the point no longer allows), its turns when it
743
+ * recorded them (the run takes one past the options as the first), else the
744
+ * seed's.
745
+ */
746
+ function replayChooser(schedule) {
747
+ const recorded = schedule.turns;
748
+ let replayed = 0;
749
+ let turns = seedPrng(`turns:${schedule.seed}`);
750
+ return {
751
+ seed: schedule.seed,
752
+ recordsTurns: recorded !== void 0,
753
+ choose(kind, options) {
754
+ if (kind === "turn") {
755
+ if (options.length < 2) return 0;
756
+ if (recorded) return recorded[replayed++] ?? 0;
757
+ const [i, next] = nextInt(turns, options.length);
758
+ turns = next;
759
+ return i;
760
+ }
761
+ if (options.length < 2) return 0;
762
+ const at = options[0];
763
+ const decision = schedule.faults.find((f) => f.invocation === at?.invocation && f.ordinal === at?.ordinal);
764
+ if (!decision) return 0;
765
+ const i = options.findIndex((o) => o.label === decision.fault);
766
+ return Math.max(i, 0);
767
+ }
768
+ };
769
+ }
770
+ /**
771
+ * The chooser under the run's fault bound: once it has taken `max` faults,
772
+ * no further fault decision is put to it (the enumerator then sees no
773
+ * choice there).
774
+ */
775
+ function limitFaults(chooser, max) {
776
+ let injected = 0;
777
+ return {
778
+ seed: chooser.seed,
779
+ recordsTurns: chooser.recordsTurns,
780
+ choose(kind, options) {
781
+ if (kind !== "fault") return chooser.choose(kind, options);
782
+ if (injected >= max) return 0;
783
+ const i = chooser.choose(kind, options);
784
+ if (i > 0) injected++;
785
+ return i;
786
+ }
787
+ };
788
+ }
670
789
  // packages/engine/src/context.ts
671
790
  /** A new async context slot, or null where the host has no AsyncLocalStorage. */
672
791
  function asyncScope() {
@@ -1014,152 +1133,19 @@ async function settleOn(promise, ctx) {
1014
1133
  return new Promise(() => {});
1015
1134
  }
1016
1135
  }
1017
- // packages/engine/src/exhaustive.ts
1018
- /** Whether two turns commute: different invocations, effects on different targets. */
1019
- function independent(a, b) {
1020
- return a.invocation !== void 0 && b.invocation !== void 0 && a.invocation !== b.invocation && a.target !== void 0 && b.target !== void 0 && a.target !== b.target;
1021
- }
1022
- const asleep = /* @__PURE__ */ new Map();
1023
- var Enumerator = class {
1024
- stack = [];
1025
- depth = 0;
1026
- /** The depth of the first node in the run just made whose every option was asleep, or null. */
1027
- blockedAt = null;
1028
- mismatchReason = null;
1029
- reduction;
1030
- constructor(options) {
1031
- this.reduction = options.reduction;
1032
- }
1033
- /** Whether the run just made repeats an explored order (every option at some point was asleep). */
1034
- get blocked() {
1035
- return this.blockedAt !== null;
1036
- }
1037
- /** Set when a run made different choices than the same prefix did before: not deterministic. */
1038
- get mismatch() {
1039
- return this.mismatchReason;
1040
- }
1041
- /** The chooser for the next run: the explored prefix, then the first option not asleep. */
1042
- next() {
1043
- this.depth = 0;
1044
- this.blockedAt = null;
1045
- return { choose: (kind, options) => this.choose(kind, options) };
1046
- }
1047
- choose(kind, options) {
1048
- const i = this.depth++;
1049
- const known = this.stack[i];
1050
- if (known) {
1051
- if (!(known.kind === kind && known.options.length === options.length && known.options.every((o, j) => o.label === options[j]?.label)) && this.mismatchReason === null) this.mismatchReason = `choice ${i} differed between runs with the same earlier choices (${known.options.map((o) => o.label).join(", ")} then ${options.map((o) => o.label).join(", ")})`;
1052
- return known.picked < options.length ? known.picked : 0;
1053
- }
1054
- if (this.blockedAt !== null) return 0;
1055
- const sleep = this.sleepAt(i);
1056
- let picked = kind === "turn" ? options.findIndex((o) => !sleep.has(o.label)) : 0;
1057
- if (picked < 0) {
1058
- this.blockedAt = i;
1059
- picked = 0;
1060
- }
1061
- this.stack.push({
1062
- kind,
1063
- options,
1064
- picked,
1065
- done: [],
1066
- sleep
1067
- });
1068
- return picked;
1069
- }
1070
- /** The sleep set of a new node at depth i, from its parent's. */
1071
- sleepAt(i) {
1072
- const parent = this.stack[i - 1];
1073
- if (!this.reduction || !parent) return asleep;
1074
- if (parent.kind === "fault") return parent.sleep;
1075
- const taken = parent.options[parent.picked];
1076
- if (!taken) return asleep;
1077
- const sleep = /* @__PURE__ */ new Map();
1078
- const candidates = [...parent.sleep.values(), ...parent.done.map((j) => parent.options[j])];
1079
- for (const c of candidates) if (c && independent(c, taken)) sleep.set(c.label, c);
1080
- return sleep;
1081
- }
1082
- /** Move to the next schedule after a run. False once every schedule has been explored. */
1083
- advance() {
1084
- this.stack.length = Math.min(this.stack.length, this.depth, (this.blockedAt ?? Infinity) + 1);
1085
- while (this.stack.length > 0) {
1086
- const node = this.stack[this.stack.length - 1];
1087
- if (!node.done.includes(node.picked)) node.done.push(node.picked);
1088
- const next = node.options.findIndex((o, j) => !node.done.includes(j) && (node.kind === "fault" || !node.sleep.has(o.label)));
1089
- if (next >= 0) {
1090
- node.picked = next;
1091
- return true;
1092
- }
1093
- this.stack.pop();
1094
- }
1095
- return false;
1096
- }
1097
- };
1136
+ // packages/engine/src/fetch.ts
1098
1137
  /**
1099
- * The exhaustive half of `explore`: the chooser for each run, what a run
1100
- * counts for, and starting the enumeration again with the reduction off
1101
- * once a run shows its turns may not commute.
1138
+ * Scripted outbound fetch. During a run, `fetch` is replaced by a function
1139
+ * that answers from the scenario's declared externals instead of the
1140
+ * network. Each request is an effect point (with every fault available) when
1141
+ * run hooks are given; without hooks it is the same scripted behaviour with
1142
+ * no recording, which the differential's raw side uses.
1143
+ *
1144
+ * An external that declares `dedupeBy` remembers the first response per key
1145
+ * for the run: a repeated key gets that response back and is recorded as
1146
+ * not effective. A request to an undeclared host, or one no scripted
1147
+ * response answers, makes the run unsupported.
1102
1148
  */
1103
- var ExhaustiveDriver = class {
1104
- reduction;
1105
- enumerator;
1106
- schedules = 0;
1107
- more = true;
1108
- restart = false;
1109
- constructor(reduction) {
1110
- this.reduction = reduction;
1111
- this.enumerator = new Enumerator({ reduction });
1112
- }
1113
- /** Whether schedules are left to run. */
1114
- get hasMore() {
1115
- return this.more;
1116
- }
1117
- /** See `Enumerator.mismatch`. */
1118
- get mismatch() {
1119
- return this.enumerator.mismatch;
1120
- }
1121
- /** The chooser for the next run. */
1122
- next() {
1123
- return this.enumerator.next();
1124
- }
1125
- /**
1126
- * Account for the run just made. False when it only repeated an order the
1127
- * reduction had covered: it is not a new schedule and its checks repeat
1128
- * others'. A run that shows its turns may not commute counts and is
1129
- * checked, and `checked` then starts again over every order.
1130
- */
1131
- ran(turnsMayNotCommute) {
1132
- this.restart = this.reduction && turnsMayNotCommute();
1133
- if (!this.restart) {
1134
- this.more = this.enumerator.advance();
1135
- if (this.enumerator.blocked) return false;
1136
- }
1137
- this.schedules++;
1138
- return true;
1139
- }
1140
- /** The run's checks passed: if it turned the reduction off, every order from the start. */
1141
- checked() {
1142
- if (!this.restart) return;
1143
- this.reduction = false;
1144
- this.enumerator = new Enumerator({ reduction: false });
1145
- this.schedules = 0;
1146
- }
1147
- /** What the verdict reports (see `BoundsReached.exhaustive`). */
1148
- get reached() {
1149
- return {
1150
- complete: !this.more,
1151
- schedules: this.schedules,
1152
- reduction: this.reduction
1153
- };
1154
- }
1155
- };
1156
- // packages/engine/src/fetch.ts
1157
- const FAULTS = [
1158
- "crash_before",
1159
- "crash_after",
1160
- "ambiguous",
1161
- "error"
1162
- ];
1163
1149
  /** Match a host against an exact host or a "*.suffix" pattern. */
1164
1150
  function hostMatches(pattern, host) {
1165
1151
  if (pattern.startsWith("*.")) {
@@ -1186,6 +1172,11 @@ const REDIRECTS = /* @__PURE__ */ new Set([
1186
1172
  307,
1187
1173
  308
1188
1174
  ]);
1175
+ /** Whether a status is a redirect `fetch` would follow unless told `redirect: "manual"`. */
1176
+ function isRedirect(status) {
1177
+ return REDIRECTS.has(status);
1178
+ }
1179
+ /** The reply a scripted response stands for; `null` is the default reply, 200 with an empty body. */
1189
1180
  function replyOf(r) {
1190
1181
  if (r === null) return {
1191
1182
  status: 200,
@@ -1209,6 +1200,7 @@ function toResponse(reply) {
1209
1200
  headers: reply.headers
1210
1201
  });
1211
1202
  }
1203
+ /** A request or reply body as effect-log data: JSON when it parses, the text otherwise, null when empty. */
1212
1204
  function parseBody(text) {
1213
1205
  if (text === "") return null;
1214
1206
  try {
@@ -1262,7 +1254,7 @@ function createScriptedFetch(externals, hooks, unsupported, afterRequest = () =>
1262
1254
  throw new TypeError(`fetch failed: no scripted response for ${method} ${url.pathname}`);
1263
1255
  }
1264
1256
  const reply = replyOf(script);
1265
- if (REDIRECTS.has(reply.status) && request.redirect !== "manual") {
1257
+ if (isRedirect(reply.status) && request.redirect !== "manual") {
1266
1258
  unsupported(`external ${external.name} answers ${method} ${url.pathname} with a ${reply.status} redirect; script the final reply or fetch with redirect: "manual"`);
1267
1259
  throw new TypeError(`fetch failed: redirects are not modelled (${reply.status} from ${url.host})`);
1268
1260
  }
@@ -1282,7 +1274,7 @@ function createScriptedFetch(externals, hooks, unsupported, afterRequest = () =>
1282
1274
  target: `Fetch:${external.name}`,
1283
1275
  op: method,
1284
1276
  args,
1285
- allowed: FAULTS
1277
+ allowed: writeFaults
1286
1278
  }, perform, (r) => ({
1287
1279
  status: r.reply.status,
1288
1280
  effective: r.effective,
@@ -1449,27 +1441,8 @@ var Frames = class {
1449
1441
  }
1450
1442
  };
1451
1443
  // packages/engine/src/turns.ts
1452
- /**
1453
- * The concurrent scheduler. Each asynchronous effect of a concurrent run is
1454
- * a turn: the invocation parks there, and once every invocation has parked,
1455
- * finished or gone idle the run picks which parked one goes next (or whether
1456
- * a new event starts): from the recorded turns when replaying them, from the
1457
- * chooser when exploring exhaustively, else from a stream seeded by the
1458
- * schedule's seed. It also tracks whether turns told apart by their parked
1459
- * effects' targets may not commute, which partial-order reduction needs.
1460
- *
1461
- * Between turns the run waits for the code it released to come to rest
1462
- * (`quiesce`): progress (a park, a delivery's end, real I/O completing)
1463
- * wakes it, and before it decides every continuation that progress set off
1464
- * has run, which takes one turn of the host's event loop: `setImmediate`
1465
- * where that is cheap (Node), else the real zero timer the wait armed, which
1466
- * also polls for the moves of hosted code, which cannot wake it, and gives
1467
- * code waiting on something it cannot see its allowance. One such turn per
1468
- * decision is the floor in workerd, where a zero timer is the only way to
1469
- * the event loop and costs about a millisecond.
1470
- */
1471
1444
  var Turns = class {
1472
- options;
1445
+ chooser;
1473
1446
  frames;
1474
1447
  /** Makes an invocation the running one. */
1475
1448
  runAs;
@@ -1480,8 +1453,6 @@ var Turns = class {
1480
1453
  parkSeq = 0;
1481
1454
  /** The turns picked at decisions with more than one option, in order (see Schedule.turns). */
1482
1455
  picked = [];
1483
- /** Turns taken from `schedule.turns` so far, when replaying recorded turns. */
1484
- replayed = 0;
1485
1456
  /** Events started so far, to name the next start the same in every run. */
1486
1457
  starts = 0;
1487
1458
  /** The target of the turn running since the last decision; null for an event's start or none. */
@@ -1497,14 +1468,11 @@ var Turns = class {
1497
1468
  restsAtStep = 0;
1498
1469
  /** The order invocations started in, which orders the parked ones. */
1499
1470
  startOrder = /* @__PURE__ */ new Map();
1500
- /** The picks among parked invocations, drawn apart from fault decisions. */
1501
- prng;
1502
- constructor(options, frames, runAs, reads) {
1503
- this.options = options;
1471
+ constructor(chooser, frames, runAs, reads) {
1472
+ this.chooser = chooser;
1504
1473
  this.frames = frames;
1505
1474
  this.runAs = runAs;
1506
1475
  this.reads = reads;
1507
- this.prng = seedPrng(`turns:${options.schedule.seed}`);
1508
1476
  }
1509
1477
  /** The turns picked so far, as a copy. */
1510
1478
  get picks() {
@@ -1619,11 +1587,9 @@ var Turns = class {
1619
1587
  this.turnTarget = null;
1620
1588
  this.step();
1621
1589
  if (options === 0) return "none";
1622
- let pick = 0;
1623
- if (options > 1) {
1624
- pick = this.pickTurn(options, canStart);
1625
- this.picked.push(pick);
1626
- } else if (this.options.chooser && this.options.mode === "explore") this.options.chooser.choose("turn", this.turnOptions(canStart));
1590
+ const answer = this.chooser.choose("turn", this.turnOptions(canStart));
1591
+ const pick = answer < options ? answer : 0;
1592
+ if (options > 1) this.picked.push(pick);
1627
1593
  const [chosen] = pick < this.parked.length ? this.parked.splice(pick, 1) : [];
1628
1594
  if (!chosen) {
1629
1595
  this.starts++;
@@ -1640,25 +1606,12 @@ var Turns = class {
1640
1606
  turnOptions(canStart) {
1641
1607
  return [...this.parked.map((p) => p.option), ...canStart ? [{ label: `start:${this.starts}` }] : []];
1642
1608
  }
1643
- /** The turn at a decision with more than one option: recorded, chosen, or drawn from the seed. */
1644
- pickTurn(options, canStart) {
1645
- const recorded = this.options.schedule.turns;
1646
- if (this.options.mode === "replay" && recorded) {
1647
- const i = recorded[this.replayed++] ?? 0;
1648
- return i < options ? i : 0;
1649
- }
1650
- const chooser = this.options.chooser;
1651
- if (chooser && this.options.mode === "explore") return chooser.choose("turn", this.turnOptions(canStart));
1652
- const [i, next] = nextInt(this.prng, options);
1653
- this.prng = next;
1654
- return i;
1655
- }
1656
1609
  };
1657
1610
  // packages/engine/src/run.ts
1658
1611
  /**
1659
1612
  * One run of a scenario: the effect log being built, the fault decisions
1660
- * (drawn during exploration, looked up during replay), and the invocations
1661
- * in flight. Proxies in the platform package call `effect`/`effectSync`
1613
+ * (made by the run's chooser, see `chooser.ts`), and the invocations in
1614
+ * flight. Proxies in the platform package call `effect`/`effectSync`
1662
1615
  * around every real effect; everything else is engine-internal.
1663
1616
  *
1664
1617
  * With `maxConcurrentInvocations` above 1 the run is concurrent: several
@@ -1738,7 +1691,6 @@ var Run = class {
1738
1691
  faults = [];
1739
1692
  effectIndex = 0;
1740
1693
  eligibleSeen = 0;
1741
- prng;
1742
1694
  invocations = /* @__PURE__ */ new Map();
1743
1695
  reasons = [];
1744
1696
  frames = new Frames();
@@ -1755,20 +1707,19 @@ var Run = class {
1755
1707
  options;
1756
1708
  constructor(options) {
1757
1709
  this.options = options;
1758
- this.prng = seedPrng(options.schedule.seed);
1759
- this.turns = new Turns(options, this.frames, (id) => this.runAs(id), () => this.patched?.reads);
1710
+ this.turns = new Turns(options.chooser, this.frames, (id) => this.runAs(id), () => this.patched?.reads);
1760
1711
  this.concurrent = options.bounds.maxConcurrentInvocations > 1;
1761
1712
  }
1762
1713
  get log() {
1763
1714
  return this.logState;
1764
1715
  }
1765
- /** The schedule as actually executed: input decisions during replay, drawn ones during exploration. */
1716
+ /** The schedule as actually executed: the faults taken and, when they do not follow the seed, the turns. */
1766
1717
  get schedule() {
1767
- const recorded = this.options.chooser !== void 0 || this.options.schedule.turns !== void 0;
1718
+ const { seed, recordsTurns } = this.options.chooser;
1768
1719
  return {
1769
- seed: this.options.schedule.seed,
1720
+ seed,
1770
1721
  faults: [...this.faults],
1771
- ...recorded ? { turns: [...this.turns.picks] } : {}
1722
+ ...recordsTurns ? { turns: [...this.turns.picks] } : {}
1772
1723
  };
1773
1724
  }
1774
1725
  get effectPoints() {
@@ -1803,7 +1754,7 @@ var Run = class {
1803
1754
  install(externals = []) {
1804
1755
  installed = this;
1805
1756
  if (!this.patched) {
1806
- this.patched = patchGlobals(this.options.schedule.seed, { trackIo: (work) => {
1757
+ this.patched = patchGlobals(this.options.chooser.seed, { trackIo: (work) => {
1807
1758
  this.frames.inFlight++;
1808
1759
  return work.finally(() => {
1809
1760
  this.frames.inFlight--;
@@ -1889,36 +1840,26 @@ var Run = class {
1889
1840
  if (!inv) throw new Error(`effect from unknown invocation ${id}`);
1890
1841
  return inv;
1891
1842
  }
1892
- /** Effect points so far that could take a fault (see `RunOptions.faultPlan`). */
1843
+ /** Effect points so far that could take a fault (the positions a seeded chooser's plan counts). */
1893
1844
  get eligiblePoints() {
1894
1845
  return this.eligibleSeen;
1895
1846
  }
1847
+ /** The fault at an eligible point, if any: the chooser's pick among none and the allowed kinds. */
1896
1848
  decide(point, ordinal) {
1897
- const position = point.allowed.length > 0 ? this.eligibleSeen++ : -1;
1898
- const plan = this.options.faultPlan;
1899
- if (plan && this.options.mode === "explore" && !this.options.chooser) {
1900
- if (position < 0 || this.faults.length >= this.options.bounds.maxFaultsPerRun) return null;
1901
- if (!plan.includes(position)) return null;
1902
- const [i, next] = nextInt(this.prng, point.allowed.length);
1903
- this.prng = next;
1904
- return point.allowed[i] ?? null;
1905
- }
1906
- const chooser = this.options.chooser;
1907
- if (chooser && this.options.mode === "explore") {
1908
- if (point.allowed.length === 0 || this.faults.length >= this.options.bounds.maxFaultsPerRun) return null;
1909
- const i = chooser.choose("fault", [{ label: "none" }, ...point.allowed.map((f) => ({ label: f }))]);
1910
- return i === 0 ? null : point.allowed[i - 1] ?? null;
1911
- }
1912
- if (this.options.mode === "replay") {
1913
- const d = this.options.schedule.faults.find((f) => f.invocation === point.invocation && f.ordinal === ordinal);
1914
- return d && point.allowed.includes(d.fault) ? d.fault : null;
1915
- }
1916
- const [fault, next] = decideFault(this.prng, point.allowed, this.faults.length, {
1917
- maxFaultsPerRun: this.options.bounds.maxFaultsPerRun,
1918
- faultProbability: this.options.faultProbability
1919
- });
1920
- this.prng = next;
1921
- return fault;
1849
+ if (point.allowed.length === 0) return null;
1850
+ this.eligibleSeen++;
1851
+ const at = {
1852
+ invocation: point.invocation,
1853
+ ordinal
1854
+ };
1855
+ const i = this.options.chooser.choose("fault", [{
1856
+ label: "none",
1857
+ ...at
1858
+ }, ...point.allowed.map((fault) => ({
1859
+ label: fault,
1860
+ ...at
1861
+ }))]);
1862
+ return i === 0 ? null : point.allowed[i - 1] ?? null;
1922
1863
  }
1923
1864
  record(point, kind, payload) {
1924
1865
  if (kind === "result") this.turns.performed(point.target);
@@ -2249,6 +2190,190 @@ var Run = class {
2249
2190
  });
2250
2191
  }
2251
2192
  };
2193
+ // packages/engine/src/deliver.ts
2194
+ /**
2195
+ * Run user code as an invocation: under `RunHooks.settle` (real I/O
2196
+ * completes, timers fire while it is idle) and ended as "crashed" when an
2197
+ * injected fault crashes the invocation, whether the code saw the crash as
2198
+ * a `CrashSignal` or an effect of its hung, as "errored" when it threw
2199
+ * anything else.
2200
+ */
2201
+ async function runInvocation(hooks, inv, work) {
2202
+ const outcome = Promise.resolve().then(work).then((value) => ({
2203
+ status: "completed",
2204
+ value
2205
+ }), (error) => error instanceof CrashSignal ? { status: "crashed" } : {
2206
+ status: "errored",
2207
+ error
2208
+ });
2209
+ return Promise.race([hooks.settle(outcome, inv.id), inv.crashed.then(() => ({ status: "crashed" }))]);
2210
+ }
2211
+ // packages/engine/src/exhaustive.ts
2212
+ /**
2213
+ * Exhaustive exploration: every schedule within the bounds, each once. A
2214
+ * schedule is the sequence of choices a run makes: a fault or none at each
2215
+ * effect point that may still take one, and the next turn at each decision
2216
+ * of a concurrent run. Runs are deterministic, so forcing a prefix of
2217
+ * choices reproduces the run up to there; the enumerator walks the tree of
2218
+ * choice sequences depth first, one run per leaf, without saving state
2219
+ * (each run starts from the scenario's reset).
2220
+ *
2221
+ * Reduction, when on, uses sleep sets (Godefroid, Partial-Order Methods for
2222
+ * the Verification of Concurrent Systems, 1996): two turns of different
2223
+ * invocations whose effects have different targets commute, so after one
2224
+ * order of them has been explored the other is not. Starting an event is
2225
+ * dependent on everything. A run whose every option is asleep repeats an
2226
+ * explored order; it still runs (the choices are forced up to it) but is not
2227
+ * counted as a schedule and nothing below it is explored.
2228
+ */
2229
+ /** Whether two turns commute: different invocations, effects on different targets. */
2230
+ function independent(a, b) {
2231
+ return a.invocation !== void 0 && b.invocation !== void 0 && a.invocation !== b.invocation && a.target !== void 0 && b.target !== void 0 && a.target !== b.target;
2232
+ }
2233
+ const asleep = /* @__PURE__ */ new Map();
2234
+ var Enumerator = class {
2235
+ stack = [];
2236
+ depth = 0;
2237
+ /** The depth of the first node in the run just made whose every option was asleep, or null. */
2238
+ blockedAt = null;
2239
+ mismatchReason = null;
2240
+ reduction;
2241
+ constructor(options) {
2242
+ this.reduction = options.reduction;
2243
+ }
2244
+ /** Whether the run just made repeats an explored order (every option at some point was asleep). */
2245
+ get blocked() {
2246
+ return this.blockedAt !== null;
2247
+ }
2248
+ /** Set when a run made different choices than the same prefix did before: not deterministic. */
2249
+ get mismatch() {
2250
+ return this.mismatchReason;
2251
+ }
2252
+ /**
2253
+ * The chooser for the next run: the explored prefix, then the first option
2254
+ * not asleep. Enumerated runs pick their choices and share one seed for
2255
+ * the virtual globals; their turns are recorded, since they do not follow it.
2256
+ */
2257
+ next() {
2258
+ this.depth = 0;
2259
+ this.blockedAt = null;
2260
+ return {
2261
+ seed: 0,
2262
+ recordsTurns: true,
2263
+ choose: (kind, options) => this.choose(kind, options)
2264
+ };
2265
+ }
2266
+ choose(kind, options) {
2267
+ const i = this.depth++;
2268
+ const known = this.stack[i];
2269
+ if (known) {
2270
+ if (!(known.kind === kind && known.options.length === options.length && known.options.every((o, j) => o.label === options[j]?.label)) && this.mismatchReason === null) this.mismatchReason = `choice ${i} differed between runs with the same earlier choices (${known.options.map((o) => o.label).join(", ")} then ${options.map((o) => o.label).join(", ")})`;
2271
+ return known.picked < options.length ? known.picked : 0;
2272
+ }
2273
+ if (this.blockedAt !== null) return 0;
2274
+ const sleep = this.sleepAt(i);
2275
+ let picked = kind === "turn" ? options.findIndex((o) => !sleep.has(o.label)) : 0;
2276
+ if (picked < 0) {
2277
+ this.blockedAt = i;
2278
+ picked = 0;
2279
+ }
2280
+ this.stack.push({
2281
+ kind,
2282
+ options,
2283
+ picked,
2284
+ done: [],
2285
+ sleep
2286
+ });
2287
+ return picked;
2288
+ }
2289
+ /** The sleep set of a new node at depth i, from its parent's. */
2290
+ sleepAt(i) {
2291
+ const parent = this.stack[i - 1];
2292
+ if (!this.reduction || !parent) return asleep;
2293
+ if (parent.kind === "fault") return parent.sleep;
2294
+ const taken = parent.options[parent.picked];
2295
+ if (!taken) return asleep;
2296
+ const sleep = /* @__PURE__ */ new Map();
2297
+ const candidates = [...parent.sleep.values(), ...parent.done.map((j) => parent.options[j])];
2298
+ for (const c of candidates) if (c && independent(c, taken)) sleep.set(c.label, c);
2299
+ return sleep;
2300
+ }
2301
+ /** Move to the next schedule after a run. False once every schedule has been explored. */
2302
+ advance() {
2303
+ this.stack.length = Math.min(this.stack.length, this.depth, (this.blockedAt ?? Infinity) + 1);
2304
+ while (this.stack.length > 0) {
2305
+ const node = this.stack[this.stack.length - 1];
2306
+ if (!node.done.includes(node.picked)) node.done.push(node.picked);
2307
+ const next = node.options.findIndex((o, j) => !node.done.includes(j) && (node.kind === "fault" || !node.sleep.has(o.label)));
2308
+ if (next >= 0) {
2309
+ node.picked = next;
2310
+ return true;
2311
+ }
2312
+ this.stack.pop();
2313
+ }
2314
+ return false;
2315
+ }
2316
+ };
2317
+ /**
2318
+ * The exhaustive half of `explore`: the chooser for each run, what a run
2319
+ * counts for, and starting the enumeration again with the reduction off
2320
+ * once a run shows its turns may not commute.
2321
+ */
2322
+ var ExhaustiveDriver = class {
2323
+ reduction;
2324
+ enumerator;
2325
+ maxFaultsPerRun;
2326
+ schedules = 0;
2327
+ more = true;
2328
+ restart = false;
2329
+ constructor(reduction, maxFaultsPerRun) {
2330
+ this.reduction = reduction;
2331
+ this.maxFaultsPerRun = maxFaultsPerRun;
2332
+ this.enumerator = new Enumerator({ reduction });
2333
+ }
2334
+ /** Whether schedules are left to run. */
2335
+ get hasMore() {
2336
+ return this.more;
2337
+ }
2338
+ /** See `Enumerator.mismatch`. */
2339
+ get mismatch() {
2340
+ return this.enumerator.mismatch;
2341
+ }
2342
+ /** The chooser for the next run, under the run's fault bound. */
2343
+ next() {
2344
+ return limitFaults(this.enumerator.next(), this.maxFaultsPerRun);
2345
+ }
2346
+ /**
2347
+ * Account for the run just made. False when it only repeated an order the
2348
+ * reduction had covered: it is not a new schedule and its checks repeat
2349
+ * others'. A run that shows its turns may not commute counts and is
2350
+ * checked, and `checked` then starts again over every order.
2351
+ */
2352
+ ran(turnsMayNotCommute) {
2353
+ this.restart = this.reduction && turnsMayNotCommute();
2354
+ if (!this.restart) {
2355
+ this.more = this.enumerator.advance();
2356
+ if (this.enumerator.blocked) return false;
2357
+ }
2358
+ this.schedules++;
2359
+ return true;
2360
+ }
2361
+ /** The run's checks passed: if it turned the reduction off, every order from the start. */
2362
+ checked() {
2363
+ if (!this.restart) return;
2364
+ this.reduction = false;
2365
+ this.enumerator = new Enumerator({ reduction: false });
2366
+ this.schedules = 0;
2367
+ }
2368
+ /** What the verdict reports (see `BoundsReached.exhaustive`). */
2369
+ get reached() {
2370
+ return {
2371
+ complete: !this.more,
2372
+ schedules: this.schedules,
2373
+ reduction: this.reduction
2374
+ };
2375
+ }
2376
+ };
2252
2377
  // packages/engine/src/shrink.ts
2253
2378
  /**
2254
2379
  * Shrinking, the loop: try the pure candidates in order, replay each, keep
@@ -2419,10 +2544,8 @@ async function runOnce(spec, platform, run) {
2419
2544
  /** Re-run a recorded schedule exactly and return the whole run (log and support status). */
2420
2545
  async function replayRun(spec, platform, schedule) {
2421
2546
  const run = new Run({
2422
- mode: "replay",
2423
- schedule,
2424
2547
  bounds: spec.bounds,
2425
- faultProbability: 0
2548
+ chooser: replayChooser(schedule)
2426
2549
  });
2427
2550
  await runOnce(spec, platform, run);
2428
2551
  return run;
@@ -2486,7 +2609,7 @@ async function explore(scenario, platform, options) {
2486
2609
  /** Eligible points of a run without faults, and the most any run has had: seeded fault positions. */
2487
2610
  let baseline = 0;
2488
2611
  let longest = 0;
2489
- const exhaustive = options.exhaustive ? new ExhaustiveDriver(typeof options.exhaustive === "object" ? options.exhaustive.reduction ?? true : true) : null;
2612
+ const exhaustive = options.exhaustive ? new ExhaustiveDriver(typeof options.exhaustive === "object" ? options.exhaustive.reduction ?? true : true, spec.bounds.maxFaultsPerRun) : null;
2490
2613
  const doneNow = () => ({
2491
2614
  ...done(),
2492
2615
  ...exhaustive ? { exhaustive: exhaustive.reached } : {}
@@ -2497,14 +2620,12 @@ async function explore(scenario, platform, options) {
2497
2620
  let faultPlan = [];
2498
2621
  if (!exhaustive) [faultPlan, master] = planFaults(master, baseline, longest, spec.bounds.maxFaultsPerRun, faultProbability);
2499
2622
  const run = new Run({
2500
- mode: "explore",
2501
- schedule: {
2502
- seed: exhaustive ? 0 : runSeed,
2503
- faults: []
2504
- },
2505
2623
  bounds: spec.bounds,
2506
- faultProbability,
2507
- ...exhaustive ? { chooser: exhaustive.next() } : { faultPlan }
2624
+ chooser: exhaustive ? exhaustive.next() : seededChooser(runSeed, {
2625
+ faultPlan,
2626
+ faultProbability,
2627
+ maxFaultsPerRun: spec.bounds.maxFaultsPerRun
2628
+ })
2508
2629
  });
2509
2630
  const log = await runOnce(spec, platform, run);
2510
2631
  reached.runs++;
@@ -2609,16 +2730,14 @@ var DifferentialStuck = class extends Error {
2609
2730
  */
2610
2731
  async function proxiedSide(spec, platform, attempt) {
2611
2732
  const run = new Run({
2612
- mode: "replay",
2613
- schedule: {
2614
- seed: 0,
2615
- faults: []
2616
- },
2617
2733
  bounds: {
2618
2734
  ...spec.bounds,
2619
2735
  maxConcurrentInvocations: 1
2620
2736
  },
2621
- faultProbability: 0
2737
+ chooser: replayChooser({
2738
+ seed: 0,
2739
+ faults: []
2740
+ })
2622
2741
  });
2623
2742
  const attempts = [];
2624
2743
  const { finish, cleanup } = platform;
@@ -2736,6 +2855,6 @@ function observeCore(namespace, functions) {
2736
2855
  }
2737
2856
  };
2738
2857
  }
2739
- export { nextU32 as C, canonicalJson as E, nextInt as S, getPath as T, defaultBounds as _, explore as a, checkInvariants as b, CrashSignal as c, withoutNetwork as d, patchGlobals as f, toJson as g, patchProperty as h, proxiedSide as i, InjectedEffectError as l, settleOn as m, DifferentialStuck as n, replay as o, realTick as p, compareSides as r, restrictSpec as s, observeCore as t, installScriptedFetch as u, validateScenario as v, seedPrng as w, nextFloat as x, checkInvariant as y };
2858
+ export { writeFaults as A, toJson as C, checkInvariants as D, checkInvariant as E, getPath as F, canonicalJson as I, nextInt as M, nextU32 as N, decisionFaults as O, seedPrng as P, patchProperty as S, validateScenario as T, withoutNetwork as _, explore as a, settleOn as b, runInvocation as c, findResponse as d, installScriptedFetch as f, toResponse as g, replyOf as h, proxiedSide as i, nextFloat as j, readFaults as k, CrashSignal as l, parseBody as m, DifferentialStuck as n, replay as o, isRedirect as p, compareSides as r, restrictSpec as s, observeCore as t, InjectedEffectError as u, patchGlobals as v, defaultBounds as w, virtualEpoch as x, realTick as y };
2740
2859
 
2741
- //# sourceMappingURL=src-BRjmbzMV.mjs.map
2860
+ //# sourceMappingURL=src-DGh7w877.mjs.map