eutaxy 0.18.0 → 0.19.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 (74) hide show
  1. package/README.md +15 -12
  2. package/dist/aws.d.mts +2 -2
  3. package/dist/aws.mjs +3 -2
  4. package/dist/aws.mjs.map +1 -1
  5. package/dist/bin.mjs +1 -1
  6. package/dist/check-zkHLdWyf.mjs +1281 -0
  7. package/dist/check-zkHLdWyf.mjs.map +1 -0
  8. package/dist/cli-CNAKqV9R.mjs +297 -0
  9. package/dist/cli-CNAKqV9R.mjs.map +1 -0
  10. package/dist/cli.d.mts.map +1 -1
  11. package/dist/cli.mjs +1 -1
  12. package/dist/cloudflare.d.mts +37 -5
  13. package/dist/cloudflare.d.mts.map +1 -1
  14. package/dist/cloudflare.mjs +6417 -3
  15. package/dist/cloudflare.mjs.map +1 -0
  16. package/dist/{delivery-invariants-BRwfZJrs.mjs → delivery-invariants-BJDck0K8.mjs} +2 -2
  17. package/dist/{delivery-invariants-BRwfZJrs.mjs.map → delivery-invariants-BJDck0K8.mjs.map} +1 -1
  18. package/dist/{delivery-invariants-D-_GPOqE.d.mts → delivery-invariants-C3GXJIbg.d.mts} +2 -2
  19. package/dist/{delivery-invariants-D-_GPOqE.d.mts.map → delivery-invariants-C3GXJIbg.d.mts.map} +1 -1
  20. package/dist/draft-DEUDffHa.mjs +467 -0
  21. package/dist/draft-DEUDffHa.mjs.map +1 -0
  22. package/dist/{src-H1Q8ytEx.mjs → generate-TBJM3-2P.mjs} +3 -618
  23. package/dist/generate-TBJM3-2P.mjs.map +1 -0
  24. package/dist/index.d.mts +36 -36
  25. package/dist/index.d.mts.map +1 -1
  26. package/dist/index.mjs +6 -3
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/install-DkzpGA5D.mjs +611 -0
  29. package/dist/install-DkzpGA5D.mjs.map +1 -0
  30. package/dist/{explore-D33RP9hF.d.mts → ir-KpC2epGn.d.mts} +70 -70
  31. package/dist/ir-KpC2epGn.d.mts.map +1 -0
  32. package/dist/keys-xtanNmuR.mjs +111 -0
  33. package/dist/keys-xtanNmuR.mjs.map +1 -0
  34. package/dist/mcp-B64Ko6y7.mjs +539 -0
  35. package/dist/mcp-B64Ko6y7.mjs.map +1 -0
  36. package/dist/{platform-CawKCUru.d.mts → platform-Cs9V9t2k.d.mts} +25 -11
  37. package/dist/platform-Cs9V9t2k.d.mts.map +1 -0
  38. package/dist/pool-CXN4CwGY.mjs +61 -0
  39. package/dist/pool-CXN4CwGY.mjs.map +1 -0
  40. package/dist/{provers-DS44OeEm.mjs → provers-D8VaY_OM.mjs} +18 -2
  41. package/dist/provers-D8VaY_OM.mjs.map +1 -0
  42. package/dist/reader-B9FSoEYW.mjs +1 -0
  43. package/dist/reader-Cz6_bLf6.mjs +3774 -0
  44. package/dist/reader-Cz6_bLf6.mjs.map +1 -0
  45. package/dist/report-_Vzavqg0.mjs +310 -0
  46. package/dist/report-_Vzavqg0.mjs.map +1 -0
  47. package/dist/src-B2DpVbMN.mjs +2 -0
  48. package/dist/src-BFGTvuA_.mjs +1235 -0
  49. package/dist/src-BFGTvuA_.mjs.map +1 -0
  50. package/dist/src-BtLZPRyG.mjs +120 -0
  51. package/dist/src-BtLZPRyG.mjs.map +1 -0
  52. package/dist/src-CB8DcvsK.mjs +1 -0
  53. package/dist/src-COuquJvI.mjs +269 -0
  54. package/dist/src-COuquJvI.mjs.map +1 -0
  55. package/dist/src-Chn-m_r1.mjs +1082 -0
  56. package/dist/src-Chn-m_r1.mjs.map +1 -0
  57. package/dist/src-DwYD3QQJ.mjs +346 -0
  58. package/dist/src-DwYD3QQJ.mjs.map +1 -0
  59. package/dist/{src-Whn0RMSh.mjs → src-Dx4QvrQb.mjs} +559 -517
  60. package/dist/src-Dx4QvrQb.mjs.map +1 -0
  61. package/dist/toolchain-DWfymxAJ.mjs +80 -0
  62. package/dist/toolchain-DWfymxAJ.mjs.map +1 -0
  63. package/dist/verdict-evEM5Gxx.mjs +12 -0
  64. package/dist/verdict-evEM5Gxx.mjs.map +1 -0
  65. package/package.json +4 -1
  66. package/dist/cli-DyA7uTBg.mjs +0 -9447
  67. package/dist/cli-DyA7uTBg.mjs.map +0 -1
  68. package/dist/explore-D33RP9hF.d.mts.map +0 -1
  69. package/dist/platform-CawKCUru.d.mts.map +0 -1
  70. package/dist/provers-DS44OeEm.mjs.map +0 -1
  71. package/dist/src-H1Q8ytEx.mjs.map +0 -1
  72. package/dist/src-Whn0RMSh.mjs.map +0 -1
  73. package/dist/workerd-tI8INa6v.mjs +0 -6334
  74. package/dist/workerd-tI8INa6v.mjs.map +0 -1
@@ -1,34 +1,4 @@
1
- // packages/core/src/canonical-json.ts
2
- function canonicalJson(value) {
3
- if (value === null) return "null";
4
- switch (typeof value) {
5
- case "boolean": return value ? "true" : "false";
6
- case "number":
7
- if (!Number.isFinite(value)) throw new TypeError(`non-finite number: ${value}`);
8
- return Object.is(value, -0) ? "0" : JSON.stringify(value);
9
- case "string": return JSON.stringify(value);
10
- case "object": {
11
- if (Array.isArray(value)) {
12
- const items = [];
13
- for (let i = 0; i < value.length; i++) {
14
- const v = value[i];
15
- if (v === void 0) throw new TypeError(`hole or undefined at index ${i}`);
16
- items.push(canonicalJson(v));
17
- }
18
- return `[${items.join(",")}]`;
19
- }
20
- const keys = Object.keys(value).sort();
21
- const parts = [];
22
- for (const k of keys) {
23
- const v = value[k];
24
- if (v === void 0) throw new TypeError(`undefined at key ${JSON.stringify(k)}`);
25
- parts.push(`${JSON.stringify(k)}:${canonicalJson(v)}`);
26
- }
27
- return `{${parts.join(",")}}`;
28
- }
29
- default: throw new TypeError(`not JSON data: ${typeof value}`);
30
- }
31
- }
1
+ import { a as serializeLog, i as seedPrng, n as nextInt, o as canonicalJson, r as nextU32, t as nextFloat } from "./src-BtLZPRyG.mjs";
32
2
  // packages/core/src/delivery.ts
33
3
  /** The invocation one attempt of an event runs as: `<event>#<attempt>`, so a schedule's faults stay keyed when other events are removed. */
34
4
  function invocationOf(event) {
@@ -117,18 +87,6 @@ function keyOf(record, path) {
117
87
  const v = getPath(record.payload, path);
118
88
  return v === void 0 ? void 0 : canonicalJson(v);
119
89
  }
120
- Object.freeze({ entries: Object.freeze([]) });
121
- /** One canonical JSON object per line, in sequence order. */
122
- function serializeLog(log) {
123
- return log.entries.map((e) => canonicalJson({
124
- seq: e.seq,
125
- kind: e.kind,
126
- invocation: e.invocation,
127
- target: e.target,
128
- op: e.op,
129
- payload: e.payload
130
- })).join("\n");
131
- }
132
90
  // packages/core/src/fault-sites.ts
133
91
  /**
134
92
  * Fault sites: where a scenario's bounds let faults go. A run spends its
@@ -203,80 +161,6 @@ function describeFaultSites(sites) {
203
161
  };
204
162
  return `faults only where the scenario's bounds say: ${sites.map(one).join("; ")}`;
205
163
  }
206
- // packages/core/src/prng.ts
207
- function rotl(x, k) {
208
- return (x << k | x >>> 32 - k) >>> 0;
209
- }
210
- /** splitmix32: expands a 32-bit seed into well-mixed words for seeding. */
211
- function splitmix32(seed) {
212
- let a = seed >>> 0;
213
- return () => {
214
- a = a + 2654435769 >>> 0;
215
- let t = a;
216
- t = Math.imul(t ^ t >>> 16, 569420461);
217
- t = Math.imul(t ^ t >>> 15, 1935289751);
218
- return (t ^ t >>> 15) >>> 0;
219
- };
220
- }
221
- /** FNV-1a over UTF-16 code units, so string seeds are stable across runtimes. */
222
- function hashString(s) {
223
- let h = 2166136261;
224
- for (let i = 0; i < s.length; i++) {
225
- h ^= s.charCodeAt(i);
226
- h = Math.imul(h, 16777619);
227
- }
228
- return h >>> 0;
229
- }
230
- /** Derive an initial state from a number (taken modulo 2^32) or a string. */
231
- function seedPrng(seed) {
232
- const next = splitmix32(typeof seed === "string" ? hashString(seed) : seed >>> 0);
233
- const s = [
234
- next(),
235
- next(),
236
- next(),
237
- next()
238
- ];
239
- if (s[0] === 0 && s[1] === 0 && s[2] === 0 && s[3] === 0) s[0] = 1;
240
- return s;
241
- }
242
- /** Next 32-bit unsigned integer and the state that follows it. */
243
- function nextU32(state) {
244
- const [s0, s1, s2, s3] = state;
245
- const result = Math.imul(rotl(Math.imul(s1, 5) >>> 0, 7), 9) >>> 0;
246
- const t = s1 << 9 >>> 0;
247
- let n2 = (s2 ^ s0) >>> 0;
248
- let n3 = (s3 ^ s1) >>> 0;
249
- const n1 = (s1 ^ n2) >>> 0;
250
- const n0 = (s0 ^ n3) >>> 0;
251
- n2 = (n2 ^ t) >>> 0;
252
- n3 = rotl(n3, 11);
253
- return [result, [
254
- n0,
255
- n1,
256
- n2,
257
- n3
258
- ]];
259
- }
260
- /** Next float in [0, 1) with 24 bits of precision. */
261
- function nextFloat(state) {
262
- const [u, next] = nextU32(state);
263
- return [(u >>> 8) * 2 ** -24, next];
264
- }
265
- /**
266
- * Next integer in [0, bound). Uses rejection sampling, so every value is
267
- * equally likely; a bound of 1 always yields 0 without consuming state.
268
- */
269
- function nextInt(state, bound) {
270
- if (!Number.isInteger(bound) || bound < 1 || bound > 4294967296) throw new RangeError(`nextInt bound must be an integer in [1, 2^32], got ${bound}`);
271
- if (bound === 1) return [0, state];
272
- const limit = 4294967296 - 4294967296 % bound;
273
- let s = state;
274
- for (;;) {
275
- const [u, next] = nextU32(s);
276
- s = next;
277
- if (u < limit) return [u % bound, s];
278
- }
279
- }
280
164
  // packages/core/src/faults.ts
281
165
  /**
282
166
  * The fault model and the schedule. A schedule is the complete, replayable
@@ -580,10 +464,6 @@ function recomputePerMessageExpected(invariants, bodies) {
580
464
  };
581
465
  });
582
466
  }
583
- /** True when two violations are of the same invariant for the same keys, whatever the traces. */
584
- function sameViolation(a, b) {
585
- return a.invariant === b.invariant && a.keys.length === b.keys.length && a.keys.every((k, i) => k === b.keys[i]);
586
- }
587
467
  /** Check one invariant against a run's effect log; null when it holds. */
588
468
  function checkInvariant(log, inv) {
589
469
  switch (inv.kind) {
@@ -670,6 +550,7 @@ function validatePinnedSchedules(pinned) {
670
550
  for (const s of p.seeds) if (!(Number.isInteger(s) && s >= 0 && s <= 4294967295)) errors.push(`${label}.seeds: ${String(s)} is not a run seed (an integer, 0 to 2^32 - 1)`);
671
551
  }
672
552
  for (const t of p.turns ?? []) if (!(Number.isInteger(t) && t >= 0)) errors.push(`${label}.turns: ${String(t)} is not a turn (an index from 0)`);
553
+ if (p.effectsAsTurns !== void 0 && p.effectsAsTurns !== true) errors.push(`${label}.effectsAsTurns is true or left out, got ${String(p.effectsAsTurns)}`);
673
554
  });
674
555
  return errors;
675
556
  }
@@ -822,6 +703,11 @@ function walk(value, extra, depth, seen) {
822
703
  seen.delete(object);
823
704
  }
824
705
  }
706
+ // packages/core/src/violation.ts
707
+ /** True when two violations are of the same invariant for the same keys, whatever the traces. */
708
+ function sameViolation(a, b) {
709
+ return a.invariant === b.invariant && a.keys.length === b.keys.length && a.keys.every((k, i) => k === b.keys[i]);
710
+ }
825
711
  // packages/engine/src/chooser.ts
826
712
  /**
827
713
  * How a run chooses. A run's nondeterminism is a sequence of decisions: a
@@ -1676,6 +1562,10 @@ var Frame = class {
1676
1562
  mayPark;
1677
1563
  /** The hosting effect this one was made inside of and waited for a turn under, if any. */
1678
1564
  parent;
1565
+ /** The effect whose perform this one was made inside of, if any (`Frames.enclosing`), set by the run. */
1566
+ inside;
1567
+ /** Whether the effect waited for a turn before being performed, set by the run: the order of such effects is the chooser's. */
1568
+ tookTurn = false;
1679
1569
  /** Effects the hosted code made as turns, parked or running now, and invocations hosted inside it. */
1680
1570
  children = 0;
1681
1571
  /** Of those, the ones given their turn that have not started performing yet: on their way. */
@@ -1898,6 +1788,16 @@ var Frames = class {
1898
1788
  return hosted || store !== void 0 ? this.hosting.get(invocation)?.at(-1) : void 0;
1899
1789
  }
1900
1790
  /**
1791
+ * An effect of `invocation`'s being performed now, without having waited
1792
+ * for a turn, that was made where a new one is being made: inside
1793
+ * `enclosing` (or outside every effect), by the same attempt's code. Two
1794
+ * such are two chains of the invocation's effects in flight at once (a
1795
+ * handler awaiting two calls together), whose order is real time's.
1796
+ */
1797
+ beside(invocation, enclosing, attempt) {
1798
+ return this.stack.find((f) => !f.tookTurn && f.invocation === invocation && f.inside === enclosing && f.attempt === attempt);
1799
+ }
1800
+ /**
1901
1801
  * The effect whose perform the current code runs inside, whatever
1902
1802
  * invocation it belongs to: the live frame of the async context, else the
1903
1803
  * innermost being performed. Where another invocation's code is hosted.
@@ -2380,8 +2280,14 @@ var Run = class {
2380
2280
  queued = [];
2381
2281
  /** Concurrent runs only: the scheduler of turns. */
2382
2282
  turns;
2383
- /** Whether several invocations may be in flight (`maxConcurrentInvocations` above 1). */
2283
+ /**
2284
+ * Whether asynchronous effects are turns: several invocations may be in
2285
+ * flight (`maxConcurrentInvocations` above 1), or the run was asked to
2286
+ * make them turns with one at a time (`RunOptions.turns`).
2287
+ */
2384
2288
  concurrent;
2289
+ /** See `parallelCalls`. */
2290
+ parallel;
2385
2291
  options;
2386
2292
  /** The kinds a point may take under the bounds' fault sites (all it allows, without sites). */
2387
2293
  sited;
@@ -2389,7 +2295,7 @@ var Run = class {
2389
2295
  this.options = options;
2390
2296
  this.sited = compileFaultSites(options.bounds.faultsAt);
2391
2297
  this.turns = new Turns(options.chooser, this.frames, (id) => this.runAs(id), () => this.patched?.reads, () => this.firedPending() + this.releasedUnseen(), () => this.hasAfterWork(), () => this.timersAllowed() !== null || this.idleBehindParked());
2392
- this.concurrent = options.bounds.maxConcurrentInvocations > 1;
2298
+ this.concurrent = options.bounds.maxConcurrentInvocations > 1 || options.turns === true;
2393
2299
  }
2394
2300
  get log() {
2395
2301
  this.logView ??= { entries: [...this.entries] };
@@ -2401,7 +2307,8 @@ var Run = class {
2401
2307
  return {
2402
2308
  seed,
2403
2309
  faults: [...this.faults],
2404
- ...recordsTurns ? { turns: [...this.turns.picks] } : {}
2310
+ ...recordsTurns ? { turns: [...this.turns.picks] } : {},
2311
+ ...this.options.turns === true ? { effectsAsTurns: true } : {}
2405
2312
  };
2406
2313
  }
2407
2314
  /**
@@ -2437,7 +2344,8 @@ var Run = class {
2437
2344
  };
2438
2345
  }),
2439
2346
  seeds: [schedule.seed],
2440
- ...schedule.turns === void 0 ? {} : { turns: schedule.turns }
2347
+ ...schedule.turns === void 0 ? {} : { turns: schedule.turns },
2348
+ ...schedule.effectsAsTurns === true ? { effectsAsTurns: true } : {}
2441
2349
  };
2442
2350
  }
2443
2351
  get effectPoints() {
@@ -2468,6 +2376,22 @@ var Run = class {
2468
2376
  get unsupportedReasons() {
2469
2377
  return this.reasons;
2470
2378
  }
2379
+ /**
2380
+ * The first time an invocation made an effect, without a turn, while
2381
+ * another of its effects made in the same place, also without a turn, was
2382
+ * still being performed (a handler awaiting two calls together), or the
2383
+ * first such pair turns would order when there is one; undefined when
2384
+ * none did. Which of two such calls lands first is real
2385
+ * time's to say, so the run is one of several the same schedule allows.
2386
+ * In a run whose effects are not turns, `explore` and the replays run the
2387
+ * scenario again with every effect a turn (`RunOptions.turns`) where that
2388
+ * would order them and the platform can. A host without async context
2389
+ * cannot tell two such calls from one made inside the other, and reports
2390
+ * none.
2391
+ */
2392
+ get parallelCalls() {
2393
+ return this.parallel;
2394
+ }
2471
2395
  /** Replace the nondeterministic globals and `fetch` for this run. Call `uninstall` in a finally. */
2472
2396
  install(externals = []) {
2473
2397
  installed = this;
@@ -3084,7 +3008,8 @@ var Run = class {
3084
3008
  };
3085
3009
  if (cont.isCrashed()) return hang();
3086
3010
  const ended = ctx.frame ?? this.hostFrames.get(host);
3087
- if (this.concurrent && (ended?.mayPark() ?? true)) {
3011
+ const parks = this.concurrent && (ended?.mayPark() ?? true);
3012
+ if (parks) {
3088
3013
  let released = false;
3089
3014
  this.turns.park(cont, own.target, () => {
3090
3015
  released = true;
@@ -3093,7 +3018,7 @@ var Run = class {
3093
3018
  while (!released && !cont.isCrashed()) await this.hostTick(host);
3094
3019
  if (!released) return hang();
3095
3020
  }
3096
- return this.performEffect(own, perform, summarize, options, cont, ended);
3021
+ return this.performEffect(own, perform, summarize, options, cont, ended, void 0, parks);
3097
3022
  }
3098
3023
  }
3099
3024
  const inv = this.invocation(point.invocation);
@@ -3127,7 +3052,8 @@ var Run = class {
3127
3052
  while (!released && !crashed()) await (host === void 0 ? realTick() : this.hostTick(host));
3128
3053
  return released;
3129
3054
  });
3130
- return this.performEffect(point, perform, summarize, options, inv, enclosing);
3055
+ const tookTurn = this.concurrent && !nested;
3056
+ return this.performEffect(point, perform, summarize, options, inv, enclosing, void 0, tookTurn);
3131
3057
  }
3132
3058
  /**
3133
3059
  * An effect that is a turn under `host` (the effect hosting the invocation, or the hosted code's
@@ -3156,7 +3082,7 @@ var Run = class {
3156
3082
  return hang();
3157
3083
  }
3158
3084
  try {
3159
- return await this.performEffect(point, perform, summarize, options, inv, enclosing, host);
3085
+ return await this.performEffect(point, perform, summarize, options, inv, enclosing, host, true);
3160
3086
  } finally {
3161
3087
  this.childEnds(host);
3162
3088
  }
@@ -3170,7 +3096,7 @@ var Run = class {
3170
3096
  this.frames.adjust(host, () => host.children--);
3171
3097
  }
3172
3098
  /** The effect once it has its turn: the fault, the perform under its deadline, the record. */
3173
- async performEffect(made, perform, summarize, options, inv, enclosing, host) {
3099
+ async performEffect(made, perform, summarize, options, inv, enclosing, host, tookTurn = false) {
3174
3100
  const dead = () => {
3175
3101
  enclosing?.crash();
3176
3102
  return hang();
@@ -3191,7 +3117,19 @@ var Run = class {
3191
3117
  frame.onHostAbandoned = (h) => this.hostAbandoned(h);
3192
3118
  frame.parent = host;
3193
3119
  frame.attempt = this.attemptNow(enclosing, host);
3120
+ frame.inside = enclosing;
3194
3121
  frame.issuer = (hostScope?.getStore() ?? this.hostedWithin.get(made.invocation))?.host;
3122
+ frame.tookTurn = tookTurn;
3123
+ if (!tookTurn) {
3124
+ const turnsWouldOrder = !this.concurrent && (enclosing === void 0 || enclosing.hosts && enclosing.mayPark());
3125
+ if (this.parallel === void 0 || turnsWouldOrder && !this.parallel.turnsWouldOrder) {
3126
+ const beside = this.frames.beside(point.invocation, enclosing, frame.attempt);
3127
+ if (beside) this.parallel = {
3128
+ calls: `${point.invocation} made ${point.target} ${point.op} while its ${beside.target} ${beside.op} was in flight`,
3129
+ turnsWouldOrder
3130
+ };
3131
+ }
3132
+ }
3195
3133
  this.frames.enter(frame);
3196
3134
  if (enclosing) this.frames.adjust(enclosing, () => enclosing.performing++);
3197
3135
  let ended = false;
@@ -3693,146 +3631,424 @@ function decide(hooks, point, perform, summarize) {
3693
3631
  throw err;
3694
3632
  }
3695
3633
  }
3696
- // packages/engine/src/exhaustive.ts
3634
+ // packages/engine/src/once.ts
3697
3635
  /**
3698
- * Exhaustive exploration: every schedule within the bounds, each once. A
3699
- * schedule is the sequence of choices a run makes: a fault or none at each
3700
- * effect point that may still take one, and the next turn at each decision
3701
- * of a concurrent run. Runs are deterministic, so forcing a prefix of
3702
- * choices reproduces the run up to there; the enumerator walks the tree of
3703
- * choice sequences depth first, one run per leaf, without saving state
3704
- * (each run starts from the scenario's reset).
3705
- *
3706
- * Reduction, when on, uses sleep sets (Godefroid, Partial-Order Methods for
3707
- * the Verification of Concurrent Systems, 1996): two turns of different
3708
- * invocations whose effects have different targets commute, so after one
3709
- * order of them has been explored the other is not. Starting an event and
3710
- * firing a timer already due are dependent on everything (their options
3711
- * have no target), so what they run is never reordered. A run whose every option is asleep repeats an
3712
- * explored order; it still runs (the choices are forced up to it) but is not
3713
- * counted as a schedule and nothing below it is explored.
3636
+ * One run of a scenario from reset to its log: the events delivered one at
3637
+ * a time, or with several invocations in flight and each turn the run's
3638
+ * pick (`runOnce`), and a recorded schedule run again exactly
3639
+ * (`replayRun`). Exploring and shrinking both stand on these.
3714
3640
  */
3715
- /** Whether two turns commute: different invocations, effects on different targets. */
3716
- function independent(a, b) {
3717
- 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;
3718
- }
3719
- const asleep = /* @__PURE__ */ new Map();
3720
- var Enumerator = class {
3721
- stack = [];
3722
- depth = 0;
3723
- /** The depth of the first node in the run just made whose every option was asleep, or null. */
3724
- blockedAt = null;
3725
- mismatchReason = null;
3726
- reduction;
3727
- constructor(options) {
3728
- this.reduction = options.reduction;
3729
- }
3730
- /** Whether the run just made repeats an explored order (every option at some point was asleep). */
3731
- get blocked() {
3732
- return this.blockedAt !== null;
3733
- }
3734
- /** Set when a run made different choices than the same prefix did before: not deterministic. */
3735
- get mismatch() {
3736
- return this.mismatchReason;
3737
- }
3738
- /**
3739
- * The chooser for the next run: the explored prefix, then the first option
3740
- * not asleep. Enumerated runs pick their choices and share one seed for
3741
- * the virtual globals; their turns are recorded, since they do not follow it.
3742
- */
3743
- next() {
3744
- this.depth = 0;
3745
- this.blockedAt = null;
3746
- return {
3747
- seed: 0,
3748
- recordsTurns: true,
3749
- choose: (kind, options) => this.choose(kind, options)
3750
- };
3641
+ /** Deliver events one at a time, each to completion; time passes until a delayed one is due. */
3642
+ async function deliverInOrder(spec, platform, run) {
3643
+ const pending = [...platform.initialEvents(spec)];
3644
+ for (;;) {
3645
+ if (pending.length === 0) pending.push(...platform.closingEvents?.(spec) ?? []);
3646
+ if (pending.length === 0) return;
3647
+ const [event] = pending.splice(earliestEvent(pending), 1);
3648
+ if (event.at !== void 0) await run.advanceTo(event.at);
3649
+ const result = await platform.deliver(event, run, spec);
3650
+ await run.driveAfterWork();
3651
+ pending.push(...run.takeQueued(), ...result.followUps);
3751
3652
  }
3752
- choose(kind, options) {
3753
- const i = this.depth++;
3754
- const known = this.stack[i];
3755
- if (known) {
3756
- 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(", ")})`;
3757
- return known.picked < options.length ? known.picked : 0;
3653
+ }
3654
+ /**
3655
+ * Deliver events with up to `maxConcurrentInvocations` in flight. Each turn
3656
+ * is a seeded pick: one parked invocation performs its effect and runs to
3657
+ * its next one, while a slot is free the next event starts, or a timer
3658
+ * already due fires. When nothing is parked, no event can start and no
3659
+ * timer is due, the next timer fires (time passes to it), and when nothing
3660
+ * can move the remaining invocations are abandoned.
3661
+ */
3662
+ async function deliverConcurrently(spec, platform, run) {
3663
+ const pending = [...platform.initialEvents(spec)];
3664
+ let active = [];
3665
+ for (;;) {
3666
+ const queuedBefore = pending.length;
3667
+ for (const d of active) {
3668
+ if (!d.outcome) continue;
3669
+ if ("error" in d.outcome) throw d.outcome.error;
3670
+ pending.push(...d.outcome.result.followUps);
3758
3671
  }
3759
- if (this.blockedAt !== null) return 0;
3760
- const sleep = this.sleepAt(i);
3761
- let picked = kind === "turn" ? options.findIndex((o) => !sleep.has(o.label)) : 0;
3762
- if (picked < 0) {
3763
- this.blockedAt = i;
3764
- picked = 0;
3672
+ active = active.filter((d) => !d.outcome);
3673
+ pending.push(...run.takeQueued());
3674
+ if (pending.length > queuedBefore) run.queuedEvents();
3675
+ if (active.length === 0 && pending.length === 0 && !run.hasAfterWork()) {
3676
+ pending.push(...platform.closingEvents?.(spec) ?? []);
3677
+ if (pending.length === 0) return;
3678
+ run.queuedEvents();
3765
3679
  }
3766
- this.stack.push({
3767
- kind,
3768
- options,
3769
- picked,
3770
- done: [],
3771
- sleep
3772
- });
3773
- return picked;
3774
- }
3775
- /** The sleep set of a new node at depth i, from its parent's. */
3776
- sleepAt(i) {
3777
- const parent = this.stack[i - 1];
3778
- if (!this.reduction || !parent) return asleep;
3779
- if (parent.kind === "fault") return parent.sleep;
3780
- const taken = parent.options[parent.picked];
3781
- if (!taken) return asleep;
3782
- const sleep = /* @__PURE__ */ new Map();
3783
- const candidates = [...parent.sleep.values(), ...parent.done.map((j) => parent.options[j])];
3784
- for (const c of candidates) if (c && independent(c, taken)) sleep.set(c.label, c);
3785
- return sleep;
3786
- }
3787
- /** Move to the next schedule after a run. False once every schedule has been explored. */
3788
- advance() {
3789
- this.stack.length = Math.min(this.stack.length, this.depth, (this.blockedAt ?? Infinity) + 1);
3790
- while (this.stack.length > 0) {
3791
- const node = this.stack[this.stack.length - 1];
3792
- if (!node.done.includes(node.picked)) node.done.push(node.picked);
3793
- const next = node.options.findIndex((o, j) => !node.done.includes(j) && (node.kind === "fault" || !node.sleep.has(o.label)));
3794
- if (next >= 0) {
3795
- node.picked = next;
3796
- return true;
3680
+ const next = pending.length > 0 ? earliestEvent(pending) : -1;
3681
+ const eventAt = pending[next]?.at ?? 0;
3682
+ const due = next >= 0 && eventAt <= run.now();
3683
+ const resting = spec.bounds.maxConcurrentInvocations === 1 && run.hasAfterWork();
3684
+ const canStart = active.length < spec.bounds.maxConcurrentInvocations && due && !resting;
3685
+ const afterWorkOnly = active.length === 0 && run.hasAfterWork();
3686
+ const timerDue = run.nextTimerDue(afterWorkOnly);
3687
+ const untilEvent = next >= 0 && !due && active.length < spec.bounds.maxConcurrentInvocations && (timerDue ?? Number.POSITIVE_INFINITY) > eventAt;
3688
+ const turn = run.takeTurn(canStart, afterWorkOnly, untilEvent || timerDue !== void 0);
3689
+ if (turn === "start") {
3690
+ const [event] = pending.splice(next, 1);
3691
+ const d = {
3692
+ started: run.startDelivery(() => platform.deliver(event, run, spec)),
3693
+ outcome: null
3694
+ };
3695
+ d.started.promise.then((result) => {
3696
+ d.outcome = { result };
3697
+ run.rested();
3698
+ }, (error) => {
3699
+ d.outcome = { error };
3700
+ run.rested();
3701
+ });
3702
+ active.push(d);
3703
+ } else if (turn === "none" && untilEvent) {
3704
+ if (!await run.advanceTo(eventAt)) continue;
3705
+ } else if (turn === "none" && !(active.length > 0 || !run.hasAfterWork() ? run.fireTimer() : run.fireAfterWorkTimer()) && run.settleAfterWork() === 0) {
3706
+ const stuck = active.flatMap((d) => d.started.invocation() ?? []);
3707
+ if (run.abandon(stuck) === 0) {
3708
+ const ending = active.filter((d) => run.hasCrashed(d.started.invocation()));
3709
+ if (!await run.ended(ending.map((d) => d.started.promise))) throw new Error(`the ${platform.name} platform's delivery made no progress and cannot be abandoned`);
3797
3710
  }
3798
- this.stack.pop();
3799
3711
  }
3800
- return false;
3712
+ await run.quiesce();
3801
3713
  }
3802
- };
3714
+ }
3715
+ /** Run the scenario once under the given run's fault decisions and return its log. */
3716
+ async function runOnce(spec, platform, run) {
3717
+ await platform.reset(spec);
3718
+ run.install(spec.externals);
3719
+ try {
3720
+ try {
3721
+ if (!run.concurrent) await deliverInOrder(spec, platform, run);
3722
+ else if (platform.concurrent) await deliverConcurrently(spec, platform, run);
3723
+ else throw new Error(`the ${platform.name} platform delivers one event at a time`);
3724
+ } finally {
3725
+ run.uninstall();
3726
+ }
3727
+ await platform.finish?.(spec, run);
3728
+ } finally {
3729
+ await platform.cleanup?.(spec);
3730
+ }
3731
+ return run.log;
3732
+ }
3803
3733
  /**
3804
- * The exhaustive half of `explore`: the chooser for each run, what a run
3805
- * counts for, and starting the enumeration again with the reduction off
3806
- * once a run shows its turns may not commute.
3734
+ * Whether a run on this platform can make every effect a turn: the host
3735
+ * carries async context and the platform delivers with several invocations
3736
+ * in flight. One invocation at a time needs the same once its calls run in
3737
+ * parallel (`Run.parallelCalls`).
3807
3738
  */
3808
- var ExhaustiveDriver = class {
3809
- reduction;
3810
- enumerator;
3811
- maxFaultsPerRun;
3812
- schedules = 0;
3813
- more = true;
3814
- restart = false;
3815
- constructor(reduction, maxFaultsPerRun) {
3816
- this.reduction = reduction;
3817
- this.maxFaultsPerRun = maxFaultsPerRun;
3818
- this.enumerator = new Enumerator({ reduction });
3819
- }
3820
- /** Whether schedules are left to run. */
3821
- get hasMore() {
3822
- return this.more;
3823
- }
3824
- /** See `Enumerator.mismatch`. */
3825
- get mismatch() {
3826
- return this.enumerator.mismatch;
3827
- }
3828
- /** The chooser for the next run, under the run's fault bound. */
3829
- next() {
3830
- return limitFaults(this.enumerator.next(), this.maxFaultsPerRun);
3831
- }
3832
- /**
3833
- * Account for the run just made. False when it only repeated an order the
3834
- * reduction had covered: it is not a new schedule and its checks repeat
3835
- * others'. A run that shows its turns may not commute counts and is
3739
+ function takesTurns(platform) {
3740
+ return concurrencySupported && platform.concurrent === true;
3741
+ }
3742
+ /** Refuse a schedule recorded with every effect a turn on a platform or a host that cannot run it so. */
3743
+ function mustTakeTurns(platform, what) {
3744
+ if (takesTurns(platform)) return;
3745
+ throw new Error(`${what} was recorded with every effect a turn (effectsAsTurns), which ${cannotTakeTurns(platform)}`);
3746
+ }
3747
+ /** Why effects cannot be turns here, for a reason; call only where `takesTurns` is false. */
3748
+ function cannotTakeTurns(platform) {
3749
+ return concurrencySupported ? `the ${platform.name} platform cannot do: it delivers one event at a time` : "needs AsyncLocalStorage (Node, or workerd with nodejs_compat or nodejs_als)";
3750
+ }
3751
+ /**
3752
+ * Re-run a recorded schedule exactly and return the whole run (log and
3753
+ * support status): with every effect a turn where the schedule says its run
3754
+ * had them so (`Schedule.effectsAsTurns`). A schedule that does not say so,
3755
+ * replayed in a run that shows an invocation's calls in parallel, is run
3756
+ * again that way where the platform can: `explore` would have recorded it so.
3757
+ */
3758
+ async function replayRun(spec, platform, schedule) {
3759
+ const turns = schedule.effectsAsTurns === true;
3760
+ if (turns) mustTakeTurns(platform, "the schedule");
3761
+ const run = new Run({
3762
+ bounds: spec.bounds,
3763
+ chooser: replayChooser(schedule),
3764
+ turns
3765
+ });
3766
+ await runOnce(spec, platform, run);
3767
+ if (!turns && run.parallelCalls?.turnsWouldOrder === true && takesTurns(platform)) return replayRun(spec, platform, {
3768
+ ...schedule,
3769
+ effectsAsTurns: true
3770
+ });
3771
+ return run;
3772
+ }
3773
+ // packages/engine/src/differential.ts
3774
+ /**
3775
+ * The platform-neutral part of a differential check: the same fault-free
3776
+ * scenario once through Eutaxy and once against the raw bindings, then a
3777
+ * comparison of what each attempt decided and of the final state. Any
3778
+ * difference is a bug in the proxies or the platform model, not in the
3779
+ * handler. The raw side's loop is here too (the same virtual globals and
3780
+ * scripted externals as the proxied side, the same pick of the next event
3781
+ * and the same redelivery rule); a platform writes only how one raw attempt
3782
+ * calls its handler, sharing no proxy code.
3783
+ */
3784
+ /** The raw side cannot abandon an invocation the way the engine does; a stuck handler ends the comparison. */
3785
+ var DifferentialStuck = class extends Error {
3786
+ name = "DifferentialStuck";
3787
+ constructor(message = "raw side: the handler is waiting on something outside the run (no effect in flight, no timer due)") {
3788
+ super(message);
3789
+ }
3790
+ };
3791
+ /**
3792
+ * The Eutaxy side: one run with no faults, one event at a time whatever the
3793
+ * scenario's bound (the raw side cannot interleave), with `attempt` given
3794
+ * each delivery's event, result and log entries.
3795
+ */
3796
+ async function proxiedSide(spec, platform, attempt) {
3797
+ const run = new Run({
3798
+ bounds: {
3799
+ ...spec.bounds,
3800
+ maxConcurrentInvocations: 1
3801
+ },
3802
+ chooser: replayChooser({
3803
+ seed: 0,
3804
+ faults: []
3805
+ })
3806
+ });
3807
+ const attempts = [];
3808
+ const { finish, cleanup } = platform;
3809
+ await runOnce(spec, {
3810
+ name: platform.name,
3811
+ assumptions: platform.assumptions,
3812
+ ...platform.concurrent === void 0 ? {} : { concurrent: platform.concurrent },
3813
+ reset: (s) => platform.reset(s),
3814
+ initialEvents: (s) => platform.initialEvents(s),
3815
+ restrictEvents: (s, keep) => platform.restrictEvents(s, keep),
3816
+ async deliver(event, hooks, s) {
3817
+ const before = run.log.entries.length;
3818
+ const result = await platform.deliver(event, hooks, s);
3819
+ attempts.push(attempt(event, result, run.log.entries.slice(before)));
3820
+ return result;
3821
+ },
3822
+ ...finish ? { finish: (s, hooks) => finish.call(platform, s, hooks) } : {},
3823
+ ...cleanup ? { cleanup: (s) => cleanup.call(platform, s) } : {}
3824
+ }, run);
3825
+ return {
3826
+ attempts,
3827
+ unsupported: run.unsupportedReasons
3828
+ };
3829
+ }
3830
+ /**
3831
+ * The raw side: every event delivered as the engine would deliver it with
3832
+ * no faults and one invocation at a time (the earliest due first, time
3833
+ * moved to a delayed one, an unhandled one delivered again under core's
3834
+ * redelivery rule), each attempt performed by the platform. The attempts'
3835
+ * records, in order.
3836
+ */
3837
+ async function rawRun(spec, side) {
3838
+ const patched = patchGlobals(0);
3839
+ const reasons = [];
3840
+ const unsupported = (reason) => {
3841
+ reasons.push(reason);
3842
+ };
3843
+ const restoreFetch = installScriptedFetch(spec.externals, null, unsupported, () => patched.clock.advance(1));
3844
+ const io = { n: 0 };
3845
+ const settle = (promise) => settleOn(promise, {
3846
+ clock: patched.clock,
3847
+ inFlight: () => io.n,
3848
+ crashed: () => false,
3849
+ stuck: () => {
3850
+ throw new DifferentialStuck();
3851
+ }
3852
+ });
3853
+ const call = async (code) => {
3854
+ try {
3855
+ return {
3856
+ status: "completed",
3857
+ value: await settle(Promise.resolve().then(code))
3858
+ };
3859
+ } catch (error) {
3860
+ if (error instanceof DifferentialStuck) throw error;
3861
+ return {
3862
+ status: "errored",
3863
+ error
3864
+ };
3865
+ }
3866
+ };
3867
+ const attempts = [];
3868
+ const pending = [...side.events];
3869
+ let restore;
3870
+ try {
3871
+ const installed = side.install({
3872
+ clock: patched.clock,
3873
+ io,
3874
+ libraryIo: (perform) => patched.libraryIo(perform),
3875
+ unsupported,
3876
+ settle,
3877
+ call
3878
+ });
3879
+ restore = installed.restore;
3880
+ const { attempt } = installed;
3881
+ while (pending.length > 0) {
3882
+ const [event] = pending.splice(earliestEvent(pending), 1);
3883
+ if (event.at !== void 0 && event.at > patched.clock.now()) patched.clock.advance(event.at - patched.clock.now());
3884
+ const { record, handled } = await attempt(event);
3885
+ attempts.push(record);
3886
+ const next = handled ? null : redelivery(event, side.limit, spec.bounds);
3887
+ if (next) pending.push(next);
3888
+ }
3889
+ } finally {
3890
+ restore?.();
3891
+ restoreFetch();
3892
+ patched.restore();
3893
+ }
3894
+ if (reasons.length > 0) throw new DifferentialStuck(`raw side: ${reasons.join("; ")}`);
3895
+ return attempts;
3896
+ }
3897
+ /** Every difference between the two sides, one readable entry each; none means they agree. */
3898
+ function compareSides(eutaxy, raw, unsupported) {
3899
+ const differences = [];
3900
+ if (unsupported.length > 0) differences.push(`the proxied run touched unsupported APIs: ${unsupported.join("; ")}`);
3901
+ const a = canonicalJson(eutaxy.attempts);
3902
+ const b = canonicalJson(raw.attempts);
3903
+ if (a !== b) differences.push(`attempts differ:\n eutaxy ${a}\n raw ${b}`);
3904
+ const names = /* @__PURE__ */ new Set([...Object.keys(eutaxy.state), ...Object.keys(raw.state)]);
3905
+ for (const name of [...names].sort()) {
3906
+ const x = canonicalJson(eutaxy.state[name] ?? []);
3907
+ const y = canonicalJson(raw.state[name] ?? []);
3908
+ if (x !== y) differences.push(`${name} differs:\n eutaxy ${x}\n raw ${y}`);
3909
+ }
3910
+ return differences;
3911
+ }
3912
+ // packages/engine/src/exhaustive.ts
3913
+ /**
3914
+ * Exhaustive exploration: every schedule within the bounds, each once. A
3915
+ * schedule is the sequence of choices a run makes: a fault or none at each
3916
+ * effect point that may still take one, and the next turn at each decision
3917
+ * of a concurrent run. Runs are deterministic, so forcing a prefix of
3918
+ * choices reproduces the run up to there; the enumerator walks the tree of
3919
+ * choice sequences depth first, one run per leaf, without saving state
3920
+ * (each run starts from the scenario's reset).
3921
+ *
3922
+ * Reduction, when on, uses sleep sets (Godefroid, Partial-Order Methods for
3923
+ * the Verification of Concurrent Systems, 1996): two turns of different
3924
+ * invocations whose effects have different targets commute, so after one
3925
+ * order of them has been explored the other is not. Starting an event and
3926
+ * firing a timer already due are dependent on everything (their options
3927
+ * have no target), so what they run is never reordered. A run whose every option is asleep repeats an
3928
+ * explored order; it still runs (the choices are forced up to it) but is not
3929
+ * counted as a schedule and nothing below it is explored.
3930
+ */
3931
+ /** Whether two turns commute: different invocations, effects on different targets. */
3932
+ function independent(a, b) {
3933
+ 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;
3934
+ }
3935
+ const asleep = /* @__PURE__ */ new Map();
3936
+ var Enumerator = class {
3937
+ stack = [];
3938
+ depth = 0;
3939
+ /** The depth of the first node in the run just made whose every option was asleep, or null. */
3940
+ blockedAt = null;
3941
+ mismatchReason = null;
3942
+ reduction;
3943
+ constructor(options) {
3944
+ this.reduction = options.reduction;
3945
+ }
3946
+ /** Whether the run just made repeats an explored order (every option at some point was asleep). */
3947
+ get blocked() {
3948
+ return this.blockedAt !== null;
3949
+ }
3950
+ /** Set when a run made different choices than the same prefix did before: not deterministic. */
3951
+ get mismatch() {
3952
+ return this.mismatchReason;
3953
+ }
3954
+ /**
3955
+ * The chooser for the next run: the explored prefix, then the first option
3956
+ * not asleep. Enumerated runs pick their choices and share one seed for
3957
+ * the virtual globals; their turns are recorded, since they do not follow it.
3958
+ */
3959
+ next() {
3960
+ this.depth = 0;
3961
+ this.blockedAt = null;
3962
+ return {
3963
+ seed: 0,
3964
+ recordsTurns: true,
3965
+ choose: (kind, options) => this.choose(kind, options)
3966
+ };
3967
+ }
3968
+ choose(kind, options) {
3969
+ const i = this.depth++;
3970
+ const known = this.stack[i];
3971
+ if (known) {
3972
+ 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(", ")})`;
3973
+ return known.picked < options.length ? known.picked : 0;
3974
+ }
3975
+ if (this.blockedAt !== null) return 0;
3976
+ const sleep = this.sleepAt(i);
3977
+ let picked = kind === "turn" ? options.findIndex((o) => !sleep.has(o.label)) : 0;
3978
+ if (picked < 0) {
3979
+ this.blockedAt = i;
3980
+ picked = 0;
3981
+ }
3982
+ this.stack.push({
3983
+ kind,
3984
+ options,
3985
+ picked,
3986
+ done: [],
3987
+ sleep
3988
+ });
3989
+ return picked;
3990
+ }
3991
+ /** The sleep set of a new node at depth i, from its parent's. */
3992
+ sleepAt(i) {
3993
+ const parent = this.stack[i - 1];
3994
+ if (!this.reduction || !parent) return asleep;
3995
+ if (parent.kind === "fault") return parent.sleep;
3996
+ const taken = parent.options[parent.picked];
3997
+ if (!taken) return asleep;
3998
+ const sleep = /* @__PURE__ */ new Map();
3999
+ const candidates = [...parent.sleep.values(), ...parent.done.map((j) => parent.options[j])];
4000
+ for (const c of candidates) if (c && independent(c, taken)) sleep.set(c.label, c);
4001
+ return sleep;
4002
+ }
4003
+ /** Move to the next schedule after a run. False once every schedule has been explored. */
4004
+ advance() {
4005
+ this.stack.length = Math.min(this.stack.length, this.depth, (this.blockedAt ?? Infinity) + 1);
4006
+ while (this.stack.length > 0) {
4007
+ const node = this.stack[this.stack.length - 1];
4008
+ if (!node.done.includes(node.picked)) node.done.push(node.picked);
4009
+ const next = node.options.findIndex((o, j) => !node.done.includes(j) && (node.kind === "fault" || !node.sleep.has(o.label)));
4010
+ if (next >= 0) {
4011
+ node.picked = next;
4012
+ return true;
4013
+ }
4014
+ this.stack.pop();
4015
+ }
4016
+ return false;
4017
+ }
4018
+ };
4019
+ /**
4020
+ * The exhaustive half of `explore`: the chooser for each run, what a run
4021
+ * counts for, and starting the enumeration again with the reduction off
4022
+ * once a run shows its turns may not commute.
4023
+ */
4024
+ var ExhaustiveDriver = class {
4025
+ reduction;
4026
+ enumerator;
4027
+ maxFaultsPerRun;
4028
+ schedules = 0;
4029
+ more = true;
4030
+ restart = false;
4031
+ constructor(reduction, maxFaultsPerRun) {
4032
+ this.reduction = reduction;
4033
+ this.maxFaultsPerRun = maxFaultsPerRun;
4034
+ this.enumerator = new Enumerator({ reduction });
4035
+ }
4036
+ /** Whether schedules are left to run. */
4037
+ get hasMore() {
4038
+ return this.more;
4039
+ }
4040
+ /** See `Enumerator.mismatch`. */
4041
+ get mismatch() {
4042
+ return this.enumerator.mismatch;
4043
+ }
4044
+ /** The chooser for the next run, under the run's fault bound. */
4045
+ next() {
4046
+ return limitFaults(this.enumerator.next(), this.maxFaultsPerRun);
4047
+ }
4048
+ /**
4049
+ * Account for the run just made. False when it only repeated an order the
4050
+ * reduction had covered: it is not a new schedule and its checks repeat
4051
+ * others'. A run that shows its turns may not commute counts and is
3836
4052
  * checked, and `checked` then starts again over every order.
3837
4053
  */
3838
4054
  ran(turnsMayNotCommute) {
@@ -3898,7 +4114,13 @@ async function shrink(spec, platform, schedule, violation, trace, options) {
3898
4114
  if (run.unsupportedReasons.length > 0) continue;
3899
4115
  const found = checkInvariants(log, candidateSpec.invariants).find((v) => sameViolation(v, violation));
3900
4116
  if (found) {
3901
- state = candidate;
4117
+ state = run.schedule.effectsAsTurns === true && candidate.schedule.effectsAsTurns !== true ? {
4118
+ ...candidate,
4119
+ schedule: {
4120
+ ...candidate.schedule,
4121
+ effectsAsTurns: true
4122
+ }
4123
+ } : candidate;
3902
4124
  best = {
3903
4125
  trace: log,
3904
4126
  violation: found
@@ -3943,10 +4165,14 @@ const engineAssumptions = [
3943
4165
  "module-level state cannot be reset between runs; before BOUNDED the first runs are replayed in reverse order and any difference makes the run UNSUPPORTED (module_state_leak)",
3944
4166
  "outbound fetch never reaches the network: requests are answered from the scenario's declared externals, an external's dedupeBy guarantee is honoured by replaying the first response per key, and an undeclared host makes the run UNSUPPORTED"
3945
4167
  ];
3946
- /** What a verdict rests on about concurrency, for these bounds. */
3947
- function concurrencyAssumption(bounds) {
3948
- if (bounds.maxConcurrentInvocations === 1) return "one invocation at a time (maxConcurrentInvocations = 1)";
3949
- return `up to ${bounds.maxConcurrentInvocations} invocations in flight, interleaved only at asynchronous effects (proxied bindings, fetch): code between two such effects runs without interruption (except continuations of a promise it settles for another invocation, which run then and are still attributed to their own invocation), Web Crypto calls are waited for like I/O, other non-effect awaits (body reads included) settle within one turn of the event loop, synchronous effects are not interleaving points, an effect made by code another effect hosts (an object calling out during a call) is a turn of its own unless that code cannot be interrupted (an object inside blockConcurrencyWhile), when it runs within the hosting effect's turn, the next turn is a seeded pick among parked invocations, starting a new event while a slot is free, and firing the earliest timer already due (at or before the virtual now, which effects advance), timers firing in due order among themselves, and a timer not yet due fires (virtual time passing to it) only when nothing else can move`;
4168
+ /**
4169
+ * What a verdict rests on about concurrency, for these bounds. `turns`: one
4170
+ * invocation at a time, with every effect a turn since an invocation made
4171
+ * calls in parallel.
4172
+ */
4173
+ function concurrencyAssumption(bounds, turns) {
4174
+ if (bounds.maxConcurrentInvocations === 1 && !turns) return "one invocation at a time (maxConcurrentInvocations = 1)";
4175
+ return `${bounds.maxConcurrentInvocations === 1 ? "one invocation at a time (maxConcurrentInvocations = 1), an object's work after its answer running to rest before the next event starts, the calls an invocation makes in parallel (two awaited together)" : `up to ${bounds.maxConcurrentInvocations} invocations in flight,`} interleaved only at asynchronous effects (proxied bindings, fetch): code between two such effects runs without interruption (except continuations of a promise it settles for another invocation, which run then and are still attributed to their own invocation), Web Crypto calls are waited for like I/O, other non-effect awaits (body reads included) settle within one turn of the event loop, synchronous effects are not interleaving points, an effect made by code another effect hosts (an object calling out during a call) is a turn of its own unless that code cannot be interrupted (an object inside blockConcurrencyWhile), when it runs within the hosting effect's turn, the next turn is a seeded pick among parked invocations, starting a new event while a slot is free, and firing the earliest timer already due (at or before the virtual now, which effects advance), timers firing in due order among themselves, and a timer not yet due fires (virtual time passing to it) only when nothing else can move`;
3950
4176
  }
3951
4177
  /** Where two JSON values first differ, as a path into them (`.tables.audit[0].at`), with the two values there. */
3952
4178
  function firstDifference(a, b, path = "") {
@@ -4021,112 +4247,13 @@ function explorationAssumption(options) {
4021
4247
  if (!options.exhaustive) return [];
4022
4248
  return ["exhaustive: every placement of faults within maxFaultsPerRun and every order of turns, each run once, until complete or the budget ends (reached.exhaustive says which)", ...reductionOf(options) ? ["partial-order reduction: turns of different invocations whose effects have different targets commute, so one order of them is run; this assumes code between an invocation's effects shares no state with other invocations except through effects and the virtual globals, and once a turn other than an event's start performs an effect on another target than its own, queues an event, or reads virtual time or randomness, or schedules a timer, the reduction is off and every order is run (reached.exhaustive.reduction says whether it stayed on)"] : []];
4023
4249
  }
4024
- /** Deliver events one at a time, each to completion; time passes until a delayed one is due. */
4025
- async function deliverInOrder(spec, platform, run) {
4026
- const pending = [...platform.initialEvents(spec)];
4027
- for (;;) {
4028
- if (pending.length === 0) pending.push(...platform.closingEvents?.(spec) ?? []);
4029
- if (pending.length === 0) return;
4030
- const [event] = pending.splice(earliestEvent(pending), 1);
4031
- if (event.at !== void 0) await run.advanceTo(event.at);
4032
- const result = await platform.deliver(event, run, spec);
4033
- await run.driveAfterWork();
4034
- pending.push(...run.takeQueued(), ...result.followUps);
4035
- }
4036
- }
4037
- /**
4038
- * Deliver events with up to `maxConcurrentInvocations` in flight. Each turn
4039
- * is a seeded pick: one parked invocation performs its effect and runs to
4040
- * its next one, while a slot is free the next event starts, or a timer
4041
- * already due fires. When nothing is parked, no event can start and no
4042
- * timer is due, the next timer fires (time passes to it), and when nothing
4043
- * can move the remaining invocations are abandoned.
4044
- */
4045
- async function deliverConcurrently(spec, platform, run) {
4046
- const pending = [...platform.initialEvents(spec)];
4047
- let active = [];
4048
- for (;;) {
4049
- const queuedBefore = pending.length;
4050
- for (const d of active) {
4051
- if (!d.outcome) continue;
4052
- if ("error" in d.outcome) throw d.outcome.error;
4053
- pending.push(...d.outcome.result.followUps);
4054
- }
4055
- active = active.filter((d) => !d.outcome);
4056
- pending.push(...run.takeQueued());
4057
- if (pending.length > queuedBefore) run.queuedEvents();
4058
- if (active.length === 0 && pending.length === 0 && !run.hasAfterWork()) {
4059
- pending.push(...platform.closingEvents?.(spec) ?? []);
4060
- if (pending.length === 0) return;
4061
- run.queuedEvents();
4062
- }
4063
- const next = pending.length > 0 ? earliestEvent(pending) : -1;
4064
- const eventAt = pending[next]?.at ?? 0;
4065
- const due = next >= 0 && eventAt <= run.now();
4066
- const canStart = active.length < spec.bounds.maxConcurrentInvocations && due;
4067
- const afterWorkOnly = active.length === 0 && run.hasAfterWork();
4068
- const timerDue = run.nextTimerDue(afterWorkOnly);
4069
- const untilEvent = next >= 0 && !due && active.length < spec.bounds.maxConcurrentInvocations && (timerDue ?? Number.POSITIVE_INFINITY) > eventAt;
4070
- const turn = run.takeTurn(canStart, afterWorkOnly, untilEvent || timerDue !== void 0);
4071
- if (turn === "start") {
4072
- const [event] = pending.splice(next, 1);
4073
- const d = {
4074
- started: run.startDelivery(() => platform.deliver(event, run, spec)),
4075
- outcome: null
4076
- };
4077
- d.started.promise.then((result) => {
4078
- d.outcome = { result };
4079
- run.rested();
4080
- }, (error) => {
4081
- d.outcome = { error };
4082
- run.rested();
4083
- });
4084
- active.push(d);
4085
- } else if (turn === "none" && untilEvent) {
4086
- if (!await run.advanceTo(eventAt)) continue;
4087
- } else if (turn === "none" && !(active.length > 0 || !run.hasAfterWork() ? run.fireTimer() : run.fireAfterWorkTimer()) && run.settleAfterWork() === 0) {
4088
- const stuck = active.flatMap((d) => d.started.invocation() ?? []);
4089
- if (run.abandon(stuck) === 0) {
4090
- const ending = active.filter((d) => run.hasCrashed(d.started.invocation()));
4091
- if (!await run.ended(ending.map((d) => d.started.promise))) throw new Error(`the ${platform.name} platform's delivery made no progress and cannot be abandoned`);
4092
- }
4093
- }
4094
- await run.quiesce();
4095
- }
4096
- }
4097
- /** Run the scenario once under the given run's fault decisions and return its log. */
4098
- async function runOnce(spec, platform, run) {
4099
- await platform.reset(spec);
4100
- run.install(spec.externals);
4101
- try {
4102
- try {
4103
- if (!run.concurrent) await deliverInOrder(spec, platform, run);
4104
- else if (platform.concurrent) await deliverConcurrently(spec, platform, run);
4105
- else throw new Error(`the ${platform.name} platform delivers one event at a time`);
4106
- } finally {
4107
- run.uninstall();
4108
- }
4109
- await platform.finish?.(spec, run);
4110
- } finally {
4111
- await platform.cleanup?.(spec);
4112
- }
4113
- return run.log;
4114
- }
4115
- /** Re-run a recorded schedule exactly and return the whole run (log and support status). */
4116
- async function replayRun(spec, platform, schedule) {
4117
- const run = new Run({
4118
- bounds: spec.bounds,
4119
- chooser: replayChooser(schedule)
4120
- });
4121
- await runOnce(spec, platform, run);
4122
- return run;
4123
- }
4124
4250
  /** One run of a pinned schedule under one seed: the run, its chooser and its log. */
4125
- async function pinnedRun(spec, platform, pinned, seed) {
4251
+ async function pinnedRun(spec, platform, pinned, seed, turns) {
4126
4252
  const chooser = pinnedChooser(pinned, seed);
4127
4253
  const run = new Run({
4128
4254
  bounds: spec.bounds,
4129
- chooser
4255
+ chooser,
4256
+ turns: turns || pinned.effectsAsTurns === true
4130
4257
  });
4131
4258
  return {
4132
4259
  run,
@@ -4141,7 +4268,9 @@ async function pinnedRun(spec, platform, pinned, seed) {
4141
4268
  async function runPinned(spec, platform, pinned, seed = pinnedSeeds(pinned)[0] ?? 0) {
4142
4269
  const errors = validatePinnedSchedules([pinned]);
4143
4270
  if (errors.length > 0) throw new Error(errors.join("; "));
4144
- const { run, chooser, log } = await pinnedRun(spec, platform, pinned, seed);
4271
+ if (pinned.effectsAsTurns === true) mustTakeTurns(platform, `pinned schedule ${JSON.stringify(pinned.name)}`);
4272
+ let { run, chooser, log } = await pinnedRun(spec, platform, pinned, seed, false);
4273
+ if (run.parallelCalls?.turnsWouldOrder === true && takesTurns(platform)) ({run, chooser, log} = await pinnedRun(spec, platform, pinned, seed, true));
4145
4274
  return {
4146
4275
  log,
4147
4276
  schedule: run.schedule,
@@ -4159,6 +4288,27 @@ async function replay(spec, platform, schedule) {
4159
4288
  * found, and return the verdict. At most 100 runs of exploration unless `maxRuns` says otherwise.
4160
4289
  */
4161
4290
  async function explore(scenario, platform, options) {
4291
+ const start = (options.now ?? (() => Date.now()))();
4292
+ const first = await exploreAs(scenario, platform, options, {
4293
+ turns: false,
4294
+ start,
4295
+ runs: 0
4296
+ });
4297
+ if (!("parallelCalls" in first)) return first;
4298
+ const again = await exploreAs(scenario, platform, options, {
4299
+ turns: true,
4300
+ start,
4301
+ runs: first.runs
4302
+ });
4303
+ if ("parallelCalls" in again) throw new Error("a run whose effects are turns reported parallel calls");
4304
+ return again;
4305
+ }
4306
+ /**
4307
+ * `explore`, with every effect a turn whatever the bounds (`mode.turns`) or
4308
+ * not; `mode.start` and `mode.runs` are when the exploration began and the
4309
+ * runs it has made already.
4310
+ */
4311
+ async function exploreAs(scenario, platform, options, mode) {
4162
4312
  const budgetMs = options.budgetMs;
4163
4313
  if (budgetMs !== void 0 && !(Number.isFinite(budgetMs) && budgetMs > 0)) throw new Error(`budgetMs must be a positive finite number, got ${budgetMs}`);
4164
4314
  const spec = budgetMs === void 0 ? scenario : {
@@ -4177,17 +4327,33 @@ async function explore(scenario, platform, options) {
4177
4327
  ...engineAssumptions.slice(0, 1),
4178
4328
  faultAssumption(spec.bounds),
4179
4329
  ...engineAssumptions.slice(1),
4180
- concurrencyAssumption(spec.bounds),
4330
+ concurrencyAssumption(spec.bounds, mode.turns),
4181
4331
  ...explorationAssumption(options),
4182
4332
  ...spec.pinned === void 0 ? [] : [pinnedAssumption(spec.pinned)],
4183
4333
  ...platform.assumptions
4184
4334
  ];
4185
- const start = now();
4335
+ const start = mode.start;
4186
4336
  const reached = {
4187
- runs: 0,
4337
+ runs: mode.runs,
4188
4338
  effectPoints: 0,
4189
4339
  faultsInjected: 0
4190
4340
  };
4341
+ /**
4342
+ * Whether `run` showed an invocation's calls in parallel in an exploration that leaves them to
4343
+ * real time, on a platform where their effects can be turns: the exploration starts over.
4344
+ */
4345
+ const startsOver = (run) => !mode.turns && takesTurns(platform) && (run.parallelCalls?.turnsWouldOrder === true || run.schedule.effectsAsTurns === true);
4346
+ const over = (run) => ({
4347
+ parallelCalls: run.parallelCalls?.calls ?? "a replay showed calls in parallel",
4348
+ runs: reached.runs
4349
+ });
4350
+ /** The first parallel calls a run showed that nothing orders: their effects cannot be turns. */
4351
+ let leftToRealTime;
4352
+ /**
4353
+ * What a run that did not replay may owe to such calls, added to its reason; empty when none
4354
+ * were seen. It says they can make two runs differ, not that they did.
4355
+ */
4356
+ const unorderedCalls = () => leftToRealTime === void 0 ? "" : `; the run made calls in parallel that nothing orders here, and which of them lands first is real time's to say: ${leftToRealTime.calls} (${leftToRealTime.turnsWouldOrder ? `the ${platform.name} platform delivers one event at a time` : "they were made inside an effect that runs as one turn, as an object's are inside blockConcurrencyWhile"})`;
4191
4357
  const done = () => ({
4192
4358
  ...reached,
4193
4359
  elapsedMs: now() - start
@@ -4213,6 +4379,8 @@ async function explore(scenario, platform, options) {
4213
4379
  });
4214
4380
  if (spec.bounds.maxConcurrentInvocations > 1 && !concurrencySupported) return unsupported("unsupported_bounds", "maxConcurrentInvocations above 1 needs AsyncLocalStorage (Node, or workerd with nodejs_compat or nodejs_als)");
4215
4381
  if (spec.bounds.maxConcurrentInvocations > 1 && !platform.concurrent) return unsupported("unsupported_bounds", `maxConcurrentInvocations above 1 is not supported on the ${platform.name} platform yet`);
4382
+ const marked = (spec.pinned ?? []).find((p) => p.effectsAsTurns === true);
4383
+ if (marked !== void 0 && !takesTurns(platform)) return unsupported("unsupported_bounds", `pinned schedule ${JSON.stringify(marked.name)} was recorded with every effect a turn (effectsAsTurns), which ${cannotTakeTurns(platform)}`);
4216
4384
  /**
4217
4385
  * A run met something outside the model: the verdict carries its schedule and, when the run
4218
4386
  * replayed alone by its faults' calls gets there again (checked here, with one more run), the
@@ -4223,7 +4391,7 @@ async function explore(scenario, platform, options) {
4223
4391
  const reason = run.unsupportedReasons.join("; ");
4224
4392
  const verdict = unsupported("unsupported_api", reason, run.schedule);
4225
4393
  const replay = run.asPinned("the run that reached UNSUPPORTED");
4226
- const again = await pinnedRun(spec, platform, replay, run.schedule.seed);
4394
+ const again = await pinnedRun(spec, platform, replay, run.schedule.seed, mode.turns);
4227
4395
  reached.runs++;
4228
4396
  return again.chooser.unplaced().length === 0 && again.run.unsupportedReasons.join("; ") === reason ? {
4229
4397
  ...verdict,
@@ -4243,9 +4411,11 @@ async function explore(scenario, platform, options) {
4243
4411
  const replayedRun = await replayRun(spec, platform, schedule);
4244
4412
  const replayed = replayedRun.log;
4245
4413
  reached.runs++;
4414
+ if (startsOver(replayedRun)) return over(replayedRun);
4415
+ leftToRealTime ??= replayedRun.parallelCalls;
4246
4416
  if (replayedRun.unsupportedReasons.length > 0) return unsupported("unsupported_api", replayedRun.unsupportedReasons.join("; "), schedule);
4247
4417
  const differed = whatDiffered(log, replayed);
4248
- if (differed) return unsupported("not_replayable", `the violating run of seed ${schedule.seed} did not reproduce on replay: ${differed}`, schedule);
4418
+ if (differed) return unsupported("not_replayable", `the violating run of seed ${schedule.seed} did not reproduce on replay: ${differed}${unorderedCalls()}`, schedule);
4249
4419
  if (pinned !== void 0) return {
4250
4420
  ...base,
4251
4421
  kind: "VIOLATED",
@@ -4268,6 +4438,10 @@ async function explore(scenario, platform, options) {
4268
4438
  now
4269
4439
  });
4270
4440
  reached.runs += shrunk.runs;
4441
+ if (!mode.turns && shrunk.schedule.effectsAsTurns === true) return {
4442
+ parallelCalls: "a replay showed calls in parallel",
4443
+ runs: reached.runs
4444
+ };
4271
4445
  return {
4272
4446
  ...base,
4273
4447
  kind: "VIOLATED",
@@ -4292,8 +4466,10 @@ async function explore(scenario, platform, options) {
4292
4466
  */
4293
4467
  const witnesses = [];
4294
4468
  for (const pinned of spec.pinned ?? []) for (const seed of pinnedSeeds(pinned)) {
4295
- const { run, chooser, log } = await pinnedRun(spec, platform, pinned, seed);
4469
+ const { run, chooser, log } = await pinnedRun(spec, platform, pinned, seed, mode.turns);
4296
4470
  reached.runs++;
4471
+ if (startsOver(run)) return over(run);
4472
+ leftToRealTime ??= run.parallelCalls;
4297
4473
  reached.effectPoints += run.effectPoints;
4298
4474
  reached.faultsInjected += run.faultsInjected;
4299
4475
  if (run.unsupportedReasons.length > 0) return await unsupportedApi(run);
@@ -4327,10 +4503,13 @@ async function explore(scenario, platform, options) {
4327
4503
  faultPlan,
4328
4504
  faultProbability,
4329
4505
  maxFaultsPerRun: spec.bounds.maxFaultsPerRun
4330
- })
4506
+ }),
4507
+ turns: mode.turns
4331
4508
  });
4332
4509
  const log = await runOnce(spec, platform, run);
4333
4510
  reached.runs++;
4511
+ if (startsOver(run)) return over(run);
4512
+ leftToRealTime ??= run.parallelCalls;
4334
4513
  if (run.faultsInjected === 0) baseline = Math.max(baseline, run.eligiblePoints);
4335
4514
  longest = Math.max(longest, run.eligiblePoints);
4336
4515
  if (run.eligiblePoints > 0) anyEligible = true;
@@ -4353,9 +4532,11 @@ async function explore(scenario, platform, options) {
4353
4532
  for (const witness of [...witnesses].reverse()) {
4354
4533
  const again = await replayRun(spec, platform, witness.schedule);
4355
4534
  reached.runs++;
4535
+ if (startsOver(again)) return over(again);
4536
+ leftToRealTime ??= again.parallelCalls;
4356
4537
  if (again.unsupportedReasons.length > 0) return unsupported("unsupported_api", again.unsupportedReasons.join("; "), witness.schedule);
4357
4538
  const differed = whatDiffered(witness.log, again.log);
4358
- if (differed) return unsupported("module_state_leak", `run seed ${witness.schedule.seed} produced a different log when replayed after other runs: state is leaking between runs (module-level variables, or a binding Eutaxy does not reset); ${differed}`, witness.schedule);
4539
+ if (differed) return leftToRealTime === void 0 ? unsupported("module_state_leak", `run seed ${witness.schedule.seed} produced a different log when replayed after other runs: state is leaking between runs (module-level variables, or a binding Eutaxy does not reset); ${differed}`, witness.schedule) : unsupported("not_replayable", `run seed ${witness.schedule.seed} produced a different log when replayed after other runs: either state is leaking between runs (module-level variables, or a binding Eutaxy does not reset) or two calls made in parallel landed in another order; ${differed}${unorderedCalls()}`, witness.schedule);
4359
4540
  }
4360
4541
  return {
4361
4542
  ...base,
@@ -4364,145 +4545,6 @@ async function explore(scenario, platform, options) {
4364
4545
  reached: doneNow()
4365
4546
  };
4366
4547
  }
4367
- // packages/engine/src/differential.ts
4368
- /**
4369
- * The platform-neutral part of a differential check: the same fault-free
4370
- * scenario once through Eutaxy and once against the raw bindings, then a
4371
- * comparison of what each attempt decided and of the final state. Any
4372
- * difference is a bug in the proxies or the platform model, not in the
4373
- * handler. The raw side's loop is here too (the same virtual globals and
4374
- * scripted externals as the proxied side, the same pick of the next event
4375
- * and the same redelivery rule); a platform writes only how one raw attempt
4376
- * calls its handler, sharing no proxy code.
4377
- */
4378
- /** The raw side cannot abandon an invocation the way the engine does; a stuck handler ends the comparison. */
4379
- var DifferentialStuck = class extends Error {
4380
- name = "DifferentialStuck";
4381
- constructor(message = "raw side: the handler is waiting on something outside the run (no effect in flight, no timer due)") {
4382
- super(message);
4383
- }
4384
- };
4385
- /**
4386
- * The Eutaxy side: one run with no faults, one event at a time whatever the
4387
- * scenario's bound (the raw side cannot interleave), with `attempt` given
4388
- * each delivery's event, result and log entries.
4389
- */
4390
- async function proxiedSide(spec, platform, attempt) {
4391
- const run = new Run({
4392
- bounds: {
4393
- ...spec.bounds,
4394
- maxConcurrentInvocations: 1
4395
- },
4396
- chooser: replayChooser({
4397
- seed: 0,
4398
- faults: []
4399
- })
4400
- });
4401
- const attempts = [];
4402
- const { finish, cleanup } = platform;
4403
- await runOnce(spec, {
4404
- name: platform.name,
4405
- assumptions: platform.assumptions,
4406
- ...platform.concurrent === void 0 ? {} : { concurrent: platform.concurrent },
4407
- reset: (s) => platform.reset(s),
4408
- initialEvents: (s) => platform.initialEvents(s),
4409
- restrictEvents: (s, keep) => platform.restrictEvents(s, keep),
4410
- async deliver(event, hooks, s) {
4411
- const before = run.log.entries.length;
4412
- const result = await platform.deliver(event, hooks, s);
4413
- attempts.push(attempt(event, result, run.log.entries.slice(before)));
4414
- return result;
4415
- },
4416
- ...finish ? { finish: (s, hooks) => finish.call(platform, s, hooks) } : {},
4417
- ...cleanup ? { cleanup: (s) => cleanup.call(platform, s) } : {}
4418
- }, run);
4419
- return {
4420
- attempts,
4421
- unsupported: run.unsupportedReasons
4422
- };
4423
- }
4424
- /**
4425
- * The raw side: every event delivered as the engine would deliver it with
4426
- * no faults and one invocation at a time (the earliest due first, time
4427
- * moved to a delayed one, an unhandled one delivered again under core's
4428
- * redelivery rule), each attempt performed by the platform. The attempts'
4429
- * records, in order.
4430
- */
4431
- async function rawRun(spec, side) {
4432
- const patched = patchGlobals(0);
4433
- const reasons = [];
4434
- const unsupported = (reason) => {
4435
- reasons.push(reason);
4436
- };
4437
- const restoreFetch = installScriptedFetch(spec.externals, null, unsupported, () => patched.clock.advance(1));
4438
- const io = { n: 0 };
4439
- const settle = (promise) => settleOn(promise, {
4440
- clock: patched.clock,
4441
- inFlight: () => io.n,
4442
- crashed: () => false,
4443
- stuck: () => {
4444
- throw new DifferentialStuck();
4445
- }
4446
- });
4447
- const call = async (code) => {
4448
- try {
4449
- return {
4450
- status: "completed",
4451
- value: await settle(Promise.resolve().then(code))
4452
- };
4453
- } catch (error) {
4454
- if (error instanceof DifferentialStuck) throw error;
4455
- return {
4456
- status: "errored",
4457
- error
4458
- };
4459
- }
4460
- };
4461
- const attempts = [];
4462
- const pending = [...side.events];
4463
- let restore;
4464
- try {
4465
- const installed = side.install({
4466
- clock: patched.clock,
4467
- io,
4468
- libraryIo: (perform) => patched.libraryIo(perform),
4469
- unsupported,
4470
- settle,
4471
- call
4472
- });
4473
- restore = installed.restore;
4474
- const { attempt } = installed;
4475
- while (pending.length > 0) {
4476
- const [event] = pending.splice(earliestEvent(pending), 1);
4477
- if (event.at !== void 0 && event.at > patched.clock.now()) patched.clock.advance(event.at - patched.clock.now());
4478
- const { record, handled } = await attempt(event);
4479
- attempts.push(record);
4480
- const next = handled ? null : redelivery(event, side.limit, spec.bounds);
4481
- if (next) pending.push(next);
4482
- }
4483
- } finally {
4484
- restore?.();
4485
- restoreFetch();
4486
- patched.restore();
4487
- }
4488
- if (reasons.length > 0) throw new DifferentialStuck(`raw side: ${reasons.join("; ")}`);
4489
- return attempts;
4490
- }
4491
- /** Every difference between the two sides, one readable entry each; none means they agree. */
4492
- function compareSides(eutaxy, raw, unsupported) {
4493
- const differences = [];
4494
- if (unsupported.length > 0) differences.push(`the proxied run touched unsupported APIs: ${unsupported.join("; ")}`);
4495
- const a = canonicalJson(eutaxy.attempts);
4496
- const b = canonicalJson(raw.attempts);
4497
- if (a !== b) differences.push(`attempts differ:\n eutaxy ${a}\n raw ${b}`);
4498
- const names = /* @__PURE__ */ new Set([...Object.keys(eutaxy.state), ...Object.keys(raw.state)]);
4499
- for (const name of [...names].sort()) {
4500
- const x = canonicalJson(eutaxy.state[name] ?? []);
4501
- const y = canonicalJson(raw.state[name] ?? []);
4502
- if (x !== y) differences.push(`${name} differs:\n eutaxy ${x}\n raw ${y}`);
4503
- }
4504
- return differences;
4505
- }
4506
4548
  // packages/engine/src/observe.ts
4507
4549
  /**
4508
4550
  * Observe a module's pure core functions while runs are installed: each call
@@ -4582,6 +4624,6 @@ function observeCore(namespace, functions) {
4582
4624
  }
4583
4625
  };
4584
4626
  }
4585
- export { readFaults as A, patchProperty as C, checkInvariant as D, validateScenario as E, seedPrng as F, getPath as I, invocationOf as L, nextFloat as M, nextInt as N, checkInvariants as O, nextU32 as P, redelivery as R, virtualEpoch as S, defaultBounds as T, parseBody as _, explore as a, withoutNetwork as b, restrictSpec as c, note as d, runInvocation as f, isRedirect as g, findResponse as h, rawRun as i, writeFaults as j, decisionFaults as k, decide as l, InjectedEffectError as m, compareSides as n, replay as o, CrashSignal as p, proxiedSide as r, runPinned as s, observeCore as t, hostInvocation as u, replyOf as v, toJson as w, realTick as x, toResponse as y, canonicalJson as z };
4627
+ export { readFaults as A, patchProperty as C, checkInvariant as D, validateScenario as E, redelivery as F, getPath as M, jsonEqual as N, checkInvariants as O, invocationOf as P, virtualEpoch as S, defaultBounds as T, parseBody as _, restrictSpec as a, withoutNetwork as b, rawRun as c, note as d, runInvocation as f, isRedirect as g, findResponse as h, runPinned as i, writeFaults as j, decisionFaults as k, decide as l, InjectedEffectError as m, explore as n, compareSides as o, CrashSignal as p, replay as r, proxiedSide as s, observeCore as t, hostInvocation as u, replyOf as v, toJson as w, realTick as x, toResponse as y };
4586
4628
 
4587
- //# sourceMappingURL=src-Whn0RMSh.mjs.map
4629
+ //# sourceMappingURL=src-Dx4QvrQb.mjs.map