eutaxy 0.17.2 → 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.
- package/README.md +15 -12
- package/dist/aws.d.mts +2 -2
- package/dist/aws.mjs +3 -2
- package/dist/aws.mjs.map +1 -1
- package/dist/bin.mjs +1 -1
- package/dist/check-zkHLdWyf.mjs +1281 -0
- package/dist/check-zkHLdWyf.mjs.map +1 -0
- package/dist/cli-CNAKqV9R.mjs +297 -0
- package/dist/cli-CNAKqV9R.mjs.map +1 -0
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cloudflare.d.mts +56 -5
- package/dist/cloudflare.d.mts.map +1 -1
- package/dist/cloudflare.mjs +6417 -3
- package/dist/cloudflare.mjs.map +1 -0
- package/dist/{delivery-invariants-DO3j1mmD.mjs → delivery-invariants-BJDck0K8.mjs} +2 -2
- package/dist/{delivery-invariants-DO3j1mmD.mjs.map → delivery-invariants-BJDck0K8.mjs.map} +1 -1
- package/dist/{delivery-invariants-D7DI7i8x.d.mts → delivery-invariants-C3GXJIbg.d.mts} +2 -2
- package/dist/{delivery-invariants-D7DI7i8x.d.mts.map → delivery-invariants-C3GXJIbg.d.mts.map} +1 -1
- package/dist/draft-DEUDffHa.mjs +467 -0
- package/dist/draft-DEUDffHa.mjs.map +1 -0
- package/dist/{src-fxWc6oGc.mjs → generate-TBJM3-2P.mjs} +3 -574
- package/dist/generate-TBJM3-2P.mjs.map +1 -0
- package/dist/index.d.mts +45 -37
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +7 -4
- package/dist/index.mjs.map +1 -1
- package/dist/install-DkzpGA5D.mjs +611 -0
- package/dist/install-DkzpGA5D.mjs.map +1 -0
- package/dist/{explore-CkKiOuz6.d.mts → ir-KpC2epGn.d.mts} +88 -53
- package/dist/ir-KpC2epGn.d.mts.map +1 -0
- package/dist/keys-xtanNmuR.mjs +111 -0
- package/dist/keys-xtanNmuR.mjs.map +1 -0
- package/dist/mcp-B64Ko6y7.mjs +539 -0
- package/dist/mcp-B64Ko6y7.mjs.map +1 -0
- package/dist/{platform-D4hlJjm3.d.mts → platform-Cs9V9t2k.d.mts} +92 -11
- package/dist/platform-Cs9V9t2k.d.mts.map +1 -0
- package/dist/pool-CXN4CwGY.mjs +61 -0
- package/dist/pool-CXN4CwGY.mjs.map +1 -0
- package/dist/{provers-DS44OeEm.mjs → provers-D8VaY_OM.mjs} +18 -2
- package/dist/provers-D8VaY_OM.mjs.map +1 -0
- package/dist/reader-B9FSoEYW.mjs +1 -0
- package/dist/reader-Cz6_bLf6.mjs +3774 -0
- package/dist/reader-Cz6_bLf6.mjs.map +1 -0
- package/dist/report-_Vzavqg0.mjs +310 -0
- package/dist/report-_Vzavqg0.mjs.map +1 -0
- package/dist/src-B2DpVbMN.mjs +2 -0
- package/dist/src-BFGTvuA_.mjs +1235 -0
- package/dist/src-BFGTvuA_.mjs.map +1 -0
- package/dist/src-BtLZPRyG.mjs +120 -0
- package/dist/src-BtLZPRyG.mjs.map +1 -0
- package/dist/src-CB8DcvsK.mjs +1 -0
- package/dist/src-COuquJvI.mjs +269 -0
- package/dist/src-COuquJvI.mjs.map +1 -0
- package/dist/src-Chn-m_r1.mjs +1082 -0
- package/dist/src-Chn-m_r1.mjs.map +1 -0
- package/dist/src-DwYD3QQJ.mjs +346 -0
- package/dist/src-DwYD3QQJ.mjs.map +1 -0
- package/dist/{src-D_hHC_-3.mjs → src-Dx4QvrQb.mjs} +945 -548
- package/dist/src-Dx4QvrQb.mjs.map +1 -0
- package/dist/toolchain-DWfymxAJ.mjs +80 -0
- package/dist/toolchain-DWfymxAJ.mjs.map +1 -0
- package/dist/verdict-evEM5Gxx.mjs +12 -0
- package/dist/verdict-evEM5Gxx.mjs.map +1 -0
- package/package.json +4 -1
- package/dist/cli-B0Gs2mhT.mjs +0 -9445
- package/dist/cli-B0Gs2mhT.mjs.map +0 -1
- package/dist/explore-CkKiOuz6.d.mts.map +0 -1
- package/dist/platform-D4hlJjm3.d.mts.map +0 -1
- package/dist/provers-DS44OeEm.mjs.map +0 -1
- package/dist/src-D_hHC_-3.mjs.map +0 -1
- package/dist/src-fxWc6oGc.mjs.map +0 -1
- package/dist/workerd-DhrzU6AZ.mjs +0 -6300
- package/dist/workerd-DhrzU6AZ.mjs.map +0 -1
|
@@ -1,34 +1,4 @@
|
|
|
1
|
-
|
|
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,91 +87,79 @@ 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
|
-
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
return () => {
|
|
140
|
-
a = a + 2654435769 >>> 0;
|
|
141
|
-
let t = a;
|
|
142
|
-
t = Math.imul(t ^ t >>> 16, 569420461);
|
|
143
|
-
t = Math.imul(t ^ t >>> 15, 1935289751);
|
|
144
|
-
return (t ^ t >>> 15) >>> 0;
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
/** FNV-1a over UTF-16 code units, so string seeds are stable across runtimes. */
|
|
148
|
-
function hashString(s) {
|
|
149
|
-
let h = 2166136261;
|
|
150
|
-
for (let i = 0; i < s.length; i++) {
|
|
151
|
-
h ^= s.charCodeAt(i);
|
|
152
|
-
h = Math.imul(h, 16777619);
|
|
153
|
-
}
|
|
154
|
-
return h >>> 0;
|
|
155
|
-
}
|
|
156
|
-
/** Derive an initial state from a number (taken modulo 2^32) or a string. */
|
|
157
|
-
function seedPrng(seed) {
|
|
158
|
-
const next = splitmix32(typeof seed === "string" ? hashString(seed) : seed >>> 0);
|
|
159
|
-
const s = [
|
|
160
|
-
next(),
|
|
161
|
-
next(),
|
|
162
|
-
next(),
|
|
163
|
-
next()
|
|
164
|
-
];
|
|
165
|
-
if (s[0] === 0 && s[1] === 0 && s[2] === 0 && s[3] === 0) s[0] = 1;
|
|
166
|
-
return s;
|
|
167
|
-
}
|
|
168
|
-
/** Next 32-bit unsigned integer and the state that follows it. */
|
|
169
|
-
function nextU32(state) {
|
|
170
|
-
const [s0, s1, s2, s3] = state;
|
|
171
|
-
const result = Math.imul(rotl(Math.imul(s1, 5) >>> 0, 7), 9) >>> 0;
|
|
172
|
-
const t = s1 << 9 >>> 0;
|
|
173
|
-
let n2 = (s2 ^ s0) >>> 0;
|
|
174
|
-
let n3 = (s3 ^ s1) >>> 0;
|
|
175
|
-
const n1 = (s1 ^ n2) >>> 0;
|
|
176
|
-
const n0 = (s0 ^ n3) >>> 0;
|
|
177
|
-
n2 = (n2 ^ t) >>> 0;
|
|
178
|
-
n3 = rotl(n3, 11);
|
|
179
|
-
return [result, [
|
|
180
|
-
n0,
|
|
181
|
-
n1,
|
|
182
|
-
n2,
|
|
183
|
-
n3
|
|
184
|
-
]];
|
|
90
|
+
// packages/core/src/fault-sites.ts
|
|
91
|
+
/**
|
|
92
|
+
* Fault sites: where a scenario's bounds let faults go. A run spends its
|
|
93
|
+
* faults only at effect points a site matches, and only of the kinds the
|
|
94
|
+
* matching sites list, so a bug that needs faults at a few chosen points
|
|
95
|
+
* (every attempt of one step) is not left to the odds of sampling among
|
|
96
|
+
* every point a run has.
|
|
97
|
+
*/
|
|
98
|
+
/** Every fault kind, in the order the fault model lists them. */
|
|
99
|
+
const faultKinds = [
|
|
100
|
+
"crash_before",
|
|
101
|
+
"crash_after",
|
|
102
|
+
"ambiguous",
|
|
103
|
+
"error",
|
|
104
|
+
"cut_off"
|
|
105
|
+
];
|
|
106
|
+
/** Every reason the sites are not usable, under `bounds.faultsAt`; empty when they are. */
|
|
107
|
+
function validateFaultSites(sites) {
|
|
108
|
+
if (sites.length === 0) return ["bounds.faultsAt must name at least one site; leave it out for faults anywhere"];
|
|
109
|
+
return sites.flatMap((site, i) => siteErrors(site, `bounds.faultsAt[${i}]`));
|
|
185
110
|
}
|
|
186
|
-
/**
|
|
187
|
-
function
|
|
188
|
-
const
|
|
189
|
-
|
|
111
|
+
/** Every reason one site is not usable, each message starting with `label`, where it sits in the scenario. */
|
|
112
|
+
function siteErrors(site, label) {
|
|
113
|
+
const errors = [];
|
|
114
|
+
if (!site.target) errors.push(`${label} needs a target`);
|
|
115
|
+
for (const field of ["where", "atLeast"]) for (const path of Object.keys(site[field] ?? {})) if (path !== "args" && !path.startsWith("args.")) errors.push(`${label}.${field}: ${JSON.stringify(path)} is not a path into the call's arguments; a site matches the call, so its paths start with "args."`);
|
|
116
|
+
if (site.faults === void 0) return errors;
|
|
117
|
+
if (site.faults.length === 0) errors.push(`${label}.faults must name at least one fault kind; leave it out for every kind`);
|
|
118
|
+
for (const f of site.faults) if (!faultKinds.includes(f)) errors.push(`${label}.faults: ${JSON.stringify(f)} is not a fault kind (${faultKinds.join(", ")})`);
|
|
119
|
+
return errors;
|
|
190
120
|
}
|
|
191
121
|
/**
|
|
192
|
-
*
|
|
193
|
-
*
|
|
122
|
+
* The sites prepared once: for a point, the kinds it allows that some
|
|
123
|
+
* matching site lists, in the point's own order; none when no site matches.
|
|
124
|
+
* Without sites, a point keeps every kind it allows.
|
|
194
125
|
*/
|
|
195
|
-
function
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
126
|
+
function compileFaultSites(sites) {
|
|
127
|
+
if (sites === void 0) return (point) => point.allowed;
|
|
128
|
+
const compiled = sites.map(({ target, op, where, atLeast, faults }) => ({
|
|
129
|
+
matches: compileSelector({
|
|
130
|
+
target,
|
|
131
|
+
...op === void 0 ? {} : { op },
|
|
132
|
+
...where === void 0 ? {} : { where },
|
|
133
|
+
...atLeast === void 0 ? {} : { atLeast }
|
|
134
|
+
}),
|
|
135
|
+
faults
|
|
136
|
+
}));
|
|
137
|
+
return (point) => {
|
|
138
|
+
const record = {
|
|
139
|
+
seq: 0,
|
|
140
|
+
kind: "call",
|
|
141
|
+
invocation: "",
|
|
142
|
+
target: point.target,
|
|
143
|
+
op: point.op,
|
|
144
|
+
payload: { args: point.args }
|
|
145
|
+
};
|
|
146
|
+
const kinds = /* @__PURE__ */ new Set();
|
|
147
|
+
for (const { matches, faults } of compiled) {
|
|
148
|
+
if (!matches(record)) continue;
|
|
149
|
+
for (const f of faults ?? point.allowed) kinds.add(f);
|
|
150
|
+
}
|
|
151
|
+
return point.allowed.filter((f) => kinds.has(f));
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/** One line for a verdict's assumptions: which faults the sites let through, and where. */
|
|
155
|
+
function describeFaultSites(sites) {
|
|
156
|
+
const one = (s) => {
|
|
157
|
+
const kinds = s.faults === void 0 ? "any fault" : s.faults.join(" or ");
|
|
158
|
+
const where = s.where === void 0 ? "" : ` where ${canonicalJson(s.where)}`;
|
|
159
|
+
const atLeast = s.atLeast === void 0 ? "" : ` at least ${canonicalJson(s.atLeast)}`;
|
|
160
|
+
return `${kinds} at ${s.target}${s.op === void 0 ? "" : ` ${s.op}`}${where}${atLeast}`;
|
|
161
|
+
};
|
|
162
|
+
return `faults only where the scenario's bounds say: ${sites.map(one).join("; ")}`;
|
|
205
163
|
}
|
|
206
164
|
// packages/core/src/faults.ts
|
|
207
165
|
/**
|
|
@@ -506,10 +464,6 @@ function recomputePerMessageExpected(invariants, bodies) {
|
|
|
506
464
|
};
|
|
507
465
|
});
|
|
508
466
|
}
|
|
509
|
-
/** True when two violations are of the same invariant for the same keys, whatever the traces. */
|
|
510
|
-
function sameViolation(a, b) {
|
|
511
|
-
return a.invariant === b.invariant && a.keys.length === b.keys.length && a.keys.every((k, i) => k === b.keys[i]);
|
|
512
|
-
}
|
|
513
467
|
/** Check one invariant against a run's effect log; null when it holds. */
|
|
514
468
|
function checkInvariant(log, inv) {
|
|
515
469
|
switch (inv.kind) {
|
|
@@ -561,6 +515,56 @@ function checkInvariants(log, invariants) {
|
|
|
561
515
|
}
|
|
562
516
|
return out;
|
|
563
517
|
}
|
|
518
|
+
// packages/core/src/pinned-schedules.ts
|
|
519
|
+
/**
|
|
520
|
+
* Pinned schedules: runs a scenario carries, each placing its faults at
|
|
521
|
+
* calls it names by what stays put in a run (a call's target, method and
|
|
522
|
+
* arguments, and its number among the calls that match), so a schedule
|
|
523
|
+
* found once is checked on every run of the command, however the faults
|
|
524
|
+
* placed before a call move the invocations and positions a recorded
|
|
525
|
+
* schedule names.
|
|
526
|
+
*/
|
|
527
|
+
/** The seeds a pinned schedule runs under. */
|
|
528
|
+
function pinnedSeeds(pinned) {
|
|
529
|
+
return pinned.seeds ?? [0];
|
|
530
|
+
}
|
|
531
|
+
/** Every reason the pinned schedules are not usable, under `pinned`; empty when they are. */
|
|
532
|
+
function validatePinnedSchedules(pinned) {
|
|
533
|
+
if (pinned.length === 0) return ["pinned must name at least one schedule; leave it out for none"];
|
|
534
|
+
const errors = [];
|
|
535
|
+
const names = /* @__PURE__ */ new Set();
|
|
536
|
+
pinned.forEach((p, i) => {
|
|
537
|
+
const label = `pinned[${i}]`;
|
|
538
|
+
if (!p.name) errors.push(`${label} needs a name`);
|
|
539
|
+
else if (names.has(p.name)) errors.push(`duplicate pinned schedule ${JSON.stringify(p.name)}`);
|
|
540
|
+
names.add(p.name);
|
|
541
|
+
p.faults.forEach((f, j) => {
|
|
542
|
+
const at = `${label}.faults[${j}]`;
|
|
543
|
+
errors.push(...siteErrors(f.at, `${at}.at`));
|
|
544
|
+
if (f.at.faults !== void 0) errors.push(`${at}.at.faults: a pinned fault names its one kind in fault; leave it out`);
|
|
545
|
+
if (!faultKinds.includes(f.fault)) errors.push(`${at}.fault: ${JSON.stringify(f.fault)} is not a fault kind (${faultKinds.join(", ")})`);
|
|
546
|
+
if (f.call !== void 0 && !(Number.isInteger(f.call) && f.call >= 1)) errors.push(`${at}.call counts from 1, got ${String(f.call)}`);
|
|
547
|
+
});
|
|
548
|
+
if (p.seeds !== void 0) {
|
|
549
|
+
if (p.seeds.length === 0) errors.push(`${label}.seeds must name at least one seed; leave it out for seed 0`);
|
|
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)`);
|
|
551
|
+
}
|
|
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)}`);
|
|
554
|
+
});
|
|
555
|
+
return errors;
|
|
556
|
+
}
|
|
557
|
+
/** One pinned fault for people: its kind, the calls it may hit, and which of them. */
|
|
558
|
+
function describePinnedFault(f) {
|
|
559
|
+
const { target, op, where, atLeast } = f.at;
|
|
560
|
+
return [
|
|
561
|
+
`${f.fault} at ${target}`,
|
|
562
|
+
op === void 0 ? "" : ` ${op}`,
|
|
563
|
+
where === void 0 ? "" : ` where ${canonicalJson(where)}`,
|
|
564
|
+
atLeast === void 0 ? "" : ` at least ${canonicalJson(atLeast)}`,
|
|
565
|
+
`, call ${f.call ?? 1}`
|
|
566
|
+
].join("");
|
|
567
|
+
}
|
|
564
568
|
// packages/core/src/scenario.ts
|
|
565
569
|
const defaultBounds = {
|
|
566
570
|
maxFaultsPerRun: 1,
|
|
@@ -612,6 +616,8 @@ function validateScenario(spec) {
|
|
|
612
616
|
if (!(Number.isInteger(v) && v >= 0)) errors.push(`bounds.${k} must be a non-negative integer`);
|
|
613
617
|
}
|
|
614
618
|
for (const k of ["maxConcurrentInvocations", "budgetMs"]) if (!isPositiveInt(spec.bounds[k])) errors.push(`bounds.${k} must be a positive integer`);
|
|
619
|
+
if (spec.bounds.faultsAt !== void 0) errors.push(...validateFaultSites(spec.bounds.faultsAt));
|
|
620
|
+
if (spec.pinned !== void 0) errors.push(...validatePinnedSchedules(spec.pinned));
|
|
615
621
|
return errors;
|
|
616
622
|
}
|
|
617
623
|
// packages/core/src/shrink.ts
|
|
@@ -697,6 +703,11 @@ function walk(value, extra, depth, seen) {
|
|
|
697
703
|
seen.delete(object);
|
|
698
704
|
}
|
|
699
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
|
+
}
|
|
700
711
|
// packages/engine/src/chooser.ts
|
|
701
712
|
/**
|
|
702
713
|
* How a run chooses. A run's nondeterminism is a sequence of decisions: a
|
|
@@ -778,6 +789,66 @@ function replayChooser(schedule) {
|
|
|
778
789
|
};
|
|
779
790
|
}
|
|
780
791
|
/**
|
|
792
|
+
* Choices a pinned schedule makes: each of its faults at the `call`-th
|
|
793
|
+
* point of the run whose call its address matches (counting the points put
|
|
794
|
+
* to the chooser, in the order the run reaches them), none elsewhere, and
|
|
795
|
+
* turns from the seed as a seeded run draws them (or the schedule's own
|
|
796
|
+
* turns, when it has them), so a pinned schedule is replayed by its run's
|
|
797
|
+
* recorded schedule. When two of its faults want one point, the first
|
|
798
|
+
* listed takes it.
|
|
799
|
+
*/
|
|
800
|
+
function pinnedChooser(pinned, seed) {
|
|
801
|
+
const matchers = pinned.faults.map((f) => compileFaultSites([f.at]));
|
|
802
|
+
const counts = pinned.faults.map(() => 0);
|
|
803
|
+
/** Per fault: "placed", why it could not be at its call, or null while its call has not come. */
|
|
804
|
+
const outcomes = pinned.faults.map(() => null);
|
|
805
|
+
let turns = seedPrng(`turns:${seed}`);
|
|
806
|
+
const recorded = pinned.turns;
|
|
807
|
+
let replayed = 0;
|
|
808
|
+
return {
|
|
809
|
+
seed,
|
|
810
|
+
recordsTurns: recorded !== void 0,
|
|
811
|
+
choose(kind, options) {
|
|
812
|
+
if (kind === "turn") {
|
|
813
|
+
if (options.length < 2) return 0;
|
|
814
|
+
if (recorded) return recorded[replayed++] ?? 0;
|
|
815
|
+
const [i, next] = nextInt(turns, options.length);
|
|
816
|
+
turns = next;
|
|
817
|
+
return i;
|
|
818
|
+
}
|
|
819
|
+
const call = options[0]?.call;
|
|
820
|
+
if (call === void 0 || options.length < 2) return 0;
|
|
821
|
+
const allowed = options.slice(1).map((o) => o.label);
|
|
822
|
+
let taken = 0;
|
|
823
|
+
pinned.faults.forEach((f, j) => {
|
|
824
|
+
if (matchers[j]?.({
|
|
825
|
+
...call,
|
|
826
|
+
allowed
|
|
827
|
+
}).length === 0) return;
|
|
828
|
+
const n = (counts[j] ?? 0) + 1;
|
|
829
|
+
counts[j] = n;
|
|
830
|
+
if (n !== (f.call ?? 1)) return;
|
|
831
|
+
const i = options.findIndex((o) => o.label === f.fault);
|
|
832
|
+
if (i < 1) outcomes[j] = `met call ${n}, which allows only ${allowed.join(", ")}`;
|
|
833
|
+
else if (taken > 0) outcomes[j] = `met call ${n}, which an earlier fault of the schedule took`;
|
|
834
|
+
else {
|
|
835
|
+
taken = i;
|
|
836
|
+
outcomes[j] = "placed";
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
return taken;
|
|
840
|
+
},
|
|
841
|
+
unplaced() {
|
|
842
|
+
return pinned.faults.flatMap((f, j) => {
|
|
843
|
+
const outcome = outcomes[j];
|
|
844
|
+
if (outcome === "placed") return [];
|
|
845
|
+
const why = outcome ?? `met no such call: the run made ${counts[j]} matching call(s)`;
|
|
846
|
+
return [`fault ${j + 1} (${describePinnedFault(f)}) ${why}`];
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
781
852
|
* The chooser under the run's fault bound: once it has taken `max` faults,
|
|
782
853
|
* no further fault decision is put to it (the enumerator then sees no
|
|
783
854
|
* choice there).
|
|
@@ -1491,6 +1562,10 @@ var Frame = class {
|
|
|
1491
1562
|
mayPark;
|
|
1492
1563
|
/** The hosting effect this one was made inside of and waited for a turn under, if any. */
|
|
1493
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;
|
|
1494
1569
|
/** Effects the hosted code made as turns, parked or running now, and invocations hosted inside it. */
|
|
1495
1570
|
children = 0;
|
|
1496
1571
|
/** Of those, the ones given their turn that have not started performing yet: on their way. */
|
|
@@ -1713,6 +1788,16 @@ var Frames = class {
|
|
|
1713
1788
|
return hosted || store !== void 0 ? this.hosting.get(invocation)?.at(-1) : void 0;
|
|
1714
1789
|
}
|
|
1715
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
|
+
/**
|
|
1716
1801
|
* The effect whose perform the current code runs inside, whatever
|
|
1717
1802
|
* invocation it belongs to: the live frame of the async context, else the
|
|
1718
1803
|
* innermost being performed. Where another invocation's code is hosted.
|
|
@@ -2125,6 +2210,12 @@ var Run = class {
|
|
|
2125
2210
|
*/
|
|
2126
2211
|
logView = null;
|
|
2127
2212
|
faults = [];
|
|
2213
|
+
/**
|
|
2214
|
+
* The call at each point put to the chooser, in order, and the position among them of each
|
|
2215
|
+
* fault taken: what `asPinned` addresses the faults by, worked out only when asked.
|
|
2216
|
+
*/
|
|
2217
|
+
eligibleCalls = [];
|
|
2218
|
+
faultPositions = [];
|
|
2128
2219
|
effectIndex = 0;
|
|
2129
2220
|
eligibleSeen = 0;
|
|
2130
2221
|
invocations = /* @__PURE__ */ new Map();
|
|
@@ -2189,13 +2280,22 @@ var Run = class {
|
|
|
2189
2280
|
queued = [];
|
|
2190
2281
|
/** Concurrent runs only: the scheduler of turns. */
|
|
2191
2282
|
turns;
|
|
2192
|
-
/**
|
|
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
|
+
*/
|
|
2193
2288
|
concurrent;
|
|
2289
|
+
/** See `parallelCalls`. */
|
|
2290
|
+
parallel;
|
|
2194
2291
|
options;
|
|
2292
|
+
/** The kinds a point may take under the bounds' fault sites (all it allows, without sites). */
|
|
2293
|
+
sited;
|
|
2195
2294
|
constructor(options) {
|
|
2196
2295
|
this.options = options;
|
|
2296
|
+
this.sited = compileFaultSites(options.bounds.faultsAt);
|
|
2197
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());
|
|
2198
|
-
this.concurrent = options.bounds.maxConcurrentInvocations > 1;
|
|
2298
|
+
this.concurrent = options.bounds.maxConcurrentInvocations > 1 || options.turns === true;
|
|
2199
2299
|
}
|
|
2200
2300
|
get log() {
|
|
2201
2301
|
this.logView ??= { entries: [...this.entries] };
|
|
@@ -2207,7 +2307,45 @@ var Run = class {
|
|
|
2207
2307
|
return {
|
|
2208
2308
|
seed,
|
|
2209
2309
|
faults: [...this.faults],
|
|
2210
|
-
...recordsTurns ? { turns: [...this.turns.picks] } : {}
|
|
2310
|
+
...recordsTurns ? { turns: [...this.turns.picks] } : {},
|
|
2311
|
+
...this.options.turns === true ? { effectsAsTurns: true } : {}
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
/**
|
|
2315
|
+
* The run as a pinned schedule: each fault taken at the call it hit, by that call's target, op
|
|
2316
|
+
* and arguments and its number among the run's calls with all three the same (counting the points
|
|
2317
|
+
* put to the chooser, as `pinnedChooser` counts them), under the run's seed and, when it recorded
|
|
2318
|
+
* them, its turns.
|
|
2319
|
+
*/
|
|
2320
|
+
asPinned(name) {
|
|
2321
|
+
const { schedule } = this;
|
|
2322
|
+
return {
|
|
2323
|
+
name,
|
|
2324
|
+
faults: schedule.faults.map((f, k) => {
|
|
2325
|
+
const at = this.faultPositions[k] ?? 0;
|
|
2326
|
+
const call = this.eligibleCalls[at] ?? {
|
|
2327
|
+
target: f.target,
|
|
2328
|
+
op: f.op,
|
|
2329
|
+
args: null
|
|
2330
|
+
};
|
|
2331
|
+
let n = 0;
|
|
2332
|
+
for (let i = 0; i <= at; i++) {
|
|
2333
|
+
const c = this.eligibleCalls[i];
|
|
2334
|
+
if (c && c.target === call.target && c.op === call.op && jsonEqual(c.args, call.args)) n++;
|
|
2335
|
+
}
|
|
2336
|
+
return {
|
|
2337
|
+
at: {
|
|
2338
|
+
target: call.target,
|
|
2339
|
+
op: call.op,
|
|
2340
|
+
where: { args: call.args }
|
|
2341
|
+
},
|
|
2342
|
+
call: n,
|
|
2343
|
+
fault: f.fault
|
|
2344
|
+
};
|
|
2345
|
+
}),
|
|
2346
|
+
seeds: [schedule.seed],
|
|
2347
|
+
...schedule.turns === void 0 ? {} : { turns: schedule.turns },
|
|
2348
|
+
...schedule.effectsAsTurns === true ? { effectsAsTurns: true } : {}
|
|
2211
2349
|
};
|
|
2212
2350
|
}
|
|
2213
2351
|
get effectPoints() {
|
|
@@ -2238,6 +2376,22 @@ var Run = class {
|
|
|
2238
2376
|
get unsupportedReasons() {
|
|
2239
2377
|
return this.reasons;
|
|
2240
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
|
+
}
|
|
2241
2395
|
/** Replace the nondeterministic globals and `fetch` for this run. Call `uninstall` in a finally. */
|
|
2242
2396
|
install(externals = []) {
|
|
2243
2397
|
installed = this;
|
|
@@ -2766,22 +2920,33 @@ var Run = class {
|
|
|
2766
2920
|
get eligiblePoints() {
|
|
2767
2921
|
return this.eligibleSeen;
|
|
2768
2922
|
}
|
|
2769
|
-
/**
|
|
2923
|
+
/**
|
|
2924
|
+
* The fault at an eligible point, if any: the chooser's pick among none and the kinds the point
|
|
2925
|
+
* allows that the bounds' fault sites let through. A point no site matches is not eligible.
|
|
2926
|
+
*/
|
|
2770
2927
|
decide(point, ordinal) {
|
|
2771
|
-
|
|
2928
|
+
const allowed = this.sited(point);
|
|
2929
|
+
if (allowed.length === 0) return null;
|
|
2772
2930
|
this.eligibleSeen++;
|
|
2931
|
+
const call = {
|
|
2932
|
+
target: point.target,
|
|
2933
|
+
op: point.op,
|
|
2934
|
+
args: point.args
|
|
2935
|
+
};
|
|
2936
|
+
this.eligibleCalls.push(call);
|
|
2773
2937
|
const at = {
|
|
2774
2938
|
invocation: point.invocation,
|
|
2775
|
-
ordinal
|
|
2939
|
+
ordinal,
|
|
2940
|
+
call
|
|
2776
2941
|
};
|
|
2777
2942
|
const i = this.options.chooser.choose("fault", [{
|
|
2778
2943
|
label: "none",
|
|
2779
2944
|
...at
|
|
2780
|
-
}, ...
|
|
2945
|
+
}, ...allowed.map((fault) => ({
|
|
2781
2946
|
label: fault,
|
|
2782
2947
|
...at
|
|
2783
2948
|
}))]);
|
|
2784
|
-
return i === 0 ? null :
|
|
2949
|
+
return i === 0 ? null : allowed[i - 1] ?? null;
|
|
2785
2950
|
}
|
|
2786
2951
|
/** Append one record, with the next sequence number: O(1), so a long run's log stays cheap. */
|
|
2787
2952
|
append(effect) {
|
|
@@ -2807,13 +2972,16 @@ var Run = class {
|
|
|
2807
2972
|
const ordinal = inv.ordinal++;
|
|
2808
2973
|
this.record(point, "call", { args: point.args });
|
|
2809
2974
|
const fault = this.decide(point, ordinal);
|
|
2810
|
-
if (fault)
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2975
|
+
if (fault) {
|
|
2976
|
+
this.faultPositions.push(this.eligibleCalls.length - 1);
|
|
2977
|
+
this.faults.push({
|
|
2978
|
+
invocation: point.invocation,
|
|
2979
|
+
ordinal,
|
|
2980
|
+
fault,
|
|
2981
|
+
target: point.target,
|
|
2982
|
+
op: point.op
|
|
2983
|
+
});
|
|
2984
|
+
}
|
|
2817
2985
|
return fault;
|
|
2818
2986
|
}
|
|
2819
2987
|
async effect(point, perform, summarize, options = {}) {
|
|
@@ -2840,7 +3008,8 @@ var Run = class {
|
|
|
2840
3008
|
};
|
|
2841
3009
|
if (cont.isCrashed()) return hang();
|
|
2842
3010
|
const ended = ctx.frame ?? this.hostFrames.get(host);
|
|
2843
|
-
|
|
3011
|
+
const parks = this.concurrent && (ended?.mayPark() ?? true);
|
|
3012
|
+
if (parks) {
|
|
2844
3013
|
let released = false;
|
|
2845
3014
|
this.turns.park(cont, own.target, () => {
|
|
2846
3015
|
released = true;
|
|
@@ -2849,7 +3018,7 @@ var Run = class {
|
|
|
2849
3018
|
while (!released && !cont.isCrashed()) await this.hostTick(host);
|
|
2850
3019
|
if (!released) return hang();
|
|
2851
3020
|
}
|
|
2852
|
-
return this.performEffect(own, perform, summarize, options, cont, ended);
|
|
3021
|
+
return this.performEffect(own, perform, summarize, options, cont, ended, void 0, parks);
|
|
2853
3022
|
}
|
|
2854
3023
|
}
|
|
2855
3024
|
const inv = this.invocation(point.invocation);
|
|
@@ -2883,7 +3052,8 @@ var Run = class {
|
|
|
2883
3052
|
while (!released && !crashed()) await (host === void 0 ? realTick() : this.hostTick(host));
|
|
2884
3053
|
return released;
|
|
2885
3054
|
});
|
|
2886
|
-
|
|
3055
|
+
const tookTurn = this.concurrent && !nested;
|
|
3056
|
+
return this.performEffect(point, perform, summarize, options, inv, enclosing, void 0, tookTurn);
|
|
2887
3057
|
}
|
|
2888
3058
|
/**
|
|
2889
3059
|
* An effect that is a turn under `host` (the effect hosting the invocation, or the hosted code's
|
|
@@ -2912,7 +3082,7 @@ var Run = class {
|
|
|
2912
3082
|
return hang();
|
|
2913
3083
|
}
|
|
2914
3084
|
try {
|
|
2915
|
-
return await this.performEffect(point, perform, summarize, options, inv, enclosing, host);
|
|
3085
|
+
return await this.performEffect(point, perform, summarize, options, inv, enclosing, host, true);
|
|
2916
3086
|
} finally {
|
|
2917
3087
|
this.childEnds(host);
|
|
2918
3088
|
}
|
|
@@ -2926,7 +3096,7 @@ var Run = class {
|
|
|
2926
3096
|
this.frames.adjust(host, () => host.children--);
|
|
2927
3097
|
}
|
|
2928
3098
|
/** The effect once it has its turn: the fault, the perform under its deadline, the record. */
|
|
2929
|
-
async performEffect(made, perform, summarize, options, inv, enclosing, host) {
|
|
3099
|
+
async performEffect(made, perform, summarize, options, inv, enclosing, host, tookTurn = false) {
|
|
2930
3100
|
const dead = () => {
|
|
2931
3101
|
enclosing?.crash();
|
|
2932
3102
|
return hang();
|
|
@@ -2947,7 +3117,19 @@ var Run = class {
|
|
|
2947
3117
|
frame.onHostAbandoned = (h) => this.hostAbandoned(h);
|
|
2948
3118
|
frame.parent = host;
|
|
2949
3119
|
frame.attempt = this.attemptNow(enclosing, host);
|
|
3120
|
+
frame.inside = enclosing;
|
|
2950
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
|
+
}
|
|
2951
3133
|
this.frames.enter(frame);
|
|
2952
3134
|
if (enclosing) this.frames.adjust(enclosing, () => enclosing.performing++);
|
|
2953
3135
|
let ended = false;
|
|
@@ -3449,90 +3631,368 @@ function decide(hooks, point, perform, summarize) {
|
|
|
3449
3631
|
throw err;
|
|
3450
3632
|
}
|
|
3451
3633
|
}
|
|
3452
|
-
// packages/engine/src/
|
|
3634
|
+
// packages/engine/src/once.ts
|
|
3453
3635
|
/**
|
|
3454
|
-
*
|
|
3455
|
-
*
|
|
3456
|
-
*
|
|
3457
|
-
*
|
|
3458
|
-
* choices reproduces the run up to there; the enumerator walks the tree of
|
|
3459
|
-
* choice sequences depth first, one run per leaf, without saving state
|
|
3460
|
-
* (each run starts from the scenario's reset).
|
|
3461
|
-
*
|
|
3462
|
-
* Reduction, when on, uses sleep sets (Godefroid, Partial-Order Methods for
|
|
3463
|
-
* the Verification of Concurrent Systems, 1996): two turns of different
|
|
3464
|
-
* invocations whose effects have different targets commute, so after one
|
|
3465
|
-
* order of them has been explored the other is not. Starting an event and
|
|
3466
|
-
* firing a timer already due are dependent on everything (their options
|
|
3467
|
-
* have no target), so what they run is never reordered. A run whose every option is asleep repeats an
|
|
3468
|
-
* explored order; it still runs (the choices are forced up to it) but is not
|
|
3469
|
-
* 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.
|
|
3470
3640
|
*/
|
|
3471
|
-
/**
|
|
3472
|
-
function
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
reduction;
|
|
3483
|
-
constructor(options) {
|
|
3484
|
-
this.reduction = options.reduction;
|
|
3485
|
-
}
|
|
3486
|
-
/** Whether the run just made repeats an explored order (every option at some point was asleep). */
|
|
3487
|
-
get blocked() {
|
|
3488
|
-
return this.blockedAt !== null;
|
|
3489
|
-
}
|
|
3490
|
-
/** Set when a run made different choices than the same prefix did before: not deterministic. */
|
|
3491
|
-
get mismatch() {
|
|
3492
|
-
return this.mismatchReason;
|
|
3493
|
-
}
|
|
3494
|
-
/**
|
|
3495
|
-
* The chooser for the next run: the explored prefix, then the first option
|
|
3496
|
-
* not asleep. Enumerated runs pick their choices and share one seed for
|
|
3497
|
-
* the virtual globals; their turns are recorded, since they do not follow it.
|
|
3498
|
-
*/
|
|
3499
|
-
next() {
|
|
3500
|
-
this.depth = 0;
|
|
3501
|
-
this.blockedAt = null;
|
|
3502
|
-
return {
|
|
3503
|
-
seed: 0,
|
|
3504
|
-
recordsTurns: true,
|
|
3505
|
-
choose: (kind, options) => this.choose(kind, options)
|
|
3506
|
-
};
|
|
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);
|
|
3507
3652
|
}
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
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);
|
|
3514
3671
|
}
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
if (
|
|
3519
|
-
|
|
3520
|
-
|
|
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();
|
|
3521
3679
|
}
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
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`);
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
await run.quiesce();
|
|
3530
3713
|
}
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
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
|
+
}
|
|
3733
|
+
/**
|
|
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`).
|
|
3738
|
+
*/
|
|
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;
|
|
3536
3996
|
const taken = parent.options[parent.picked];
|
|
3537
3997
|
if (!taken) return asleep;
|
|
3538
3998
|
const sleep = /* @__PURE__ */ new Map();
|
|
@@ -3654,7 +4114,13 @@ async function shrink(spec, platform, schedule, violation, trace, options) {
|
|
|
3654
4114
|
if (run.unsupportedReasons.length > 0) continue;
|
|
3655
4115
|
const found = checkInvariants(log, candidateSpec.invariants).find((v) => sameViolation(v, violation));
|
|
3656
4116
|
if (found) {
|
|
3657
|
-
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;
|
|
3658
4124
|
best = {
|
|
3659
4125
|
trace: log,
|
|
3660
4126
|
violation: found
|
|
@@ -3681,9 +4147,17 @@ async function shrink(spec, platform, schedule, violation, trace, options) {
|
|
|
3681
4147
|
* an invariant breaks or the budget is spent; replay any violation before
|
|
3682
4148
|
* reporting it.
|
|
3683
4149
|
*/
|
|
4150
|
+
/** Where faults go: at any effect point, or only where the bounds' fault sites say. */
|
|
4151
|
+
function faultAssumption(bounds) {
|
|
4152
|
+
return `${bounds.faultsAt === void 0 ? "faults: crash_before, crash_after, ambiguous, error at any effect point" : describeFaultSites(bounds.faultsAt)}; redelivery per the platform's queue model`;
|
|
4153
|
+
}
|
|
4154
|
+
/** What the pinned schedules ran before exploration: each one's name, seeds and faults. */
|
|
4155
|
+
function pinnedAssumption(pinned) {
|
|
4156
|
+
const one = (p) => `${JSON.stringify(p.name)} under seed(s) ${pinnedSeeds(p).join(", ")}: ${p.faults.map(describePinnedFault).join("; ")}`;
|
|
4157
|
+
return `pinned schedules ran before exploration, each fault at the call it names, however many faults the bounds allow a run: ${pinned.map(one).join(" | ")}`;
|
|
4158
|
+
}
|
|
3684
4159
|
const engineAssumptions = [
|
|
3685
4160
|
"schedule points are effect boundaries: proxied bindings, patched timers and fetch; other awaits run in program order",
|
|
3686
|
-
"faults: crash_before, crash_after, ambiguous, error at any effect point; redelivery per the platform's queue model",
|
|
3687
4161
|
"Date, Math.random, crypto.randomUUID, crypto.getRandomValues, performance.now and timers are virtualised per run from the seed; time starts at 2026-01-01T00:00:00Z and advances 1 ms per effect and to each timer's due time",
|
|
3688
4162
|
"timers fire in due order; one at a time, only while the invocation is idle (no effect in flight); with several in flight, as the concurrency assumption says; an invocation waiting on something outside Eutaxy makes the run UNSUPPORTED",
|
|
3689
4163
|
"an effect whose real I/O takes longer than the time budget (the scenario's budgetMs, or the budgetMs option replacing it) is treated as hung: the run is UNSUPPORTED and names the effect",
|
|
@@ -3691,10 +4165,14 @@ const engineAssumptions = [
|
|
|
3691
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)",
|
|
3692
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"
|
|
3693
4167
|
];
|
|
3694
|
-
/**
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
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`;
|
|
3698
4176
|
}
|
|
3699
4177
|
/** Where two JSON values first differ, as a path into them (`.tables.audit[0].at`), with the two values there. */
|
|
3700
4178
|
function firstDifference(a, b, path = "") {
|
|
@@ -3715,170 +4193,122 @@ function firstDifference(a, b, path = "") {
|
|
|
3715
4193
|
}
|
|
3716
4194
|
return (a === void 0 || b === void 0 ? a === b : canonicalJson(a) === canonicalJson(b)) ? null : {
|
|
3717
4195
|
path,
|
|
3718
|
-
a,
|
|
3719
|
-
b
|
|
3720
|
-
};
|
|
3721
|
-
}
|
|
3722
|
-
/**
|
|
3723
|
-
* The first record a replay recorded differently from the run, or how their
|
|
3724
|
-
* lengths differ; null when the logs match. Two records of the same effect
|
|
3725
|
-
* are told apart by the first value in their payloads that differs, with its
|
|
3726
|
-
* path: a snapshot of many tables that differs in one column says which.
|
|
3727
|
-
*/
|
|
3728
|
-
function whatDiffered(run, replay) {
|
|
3729
|
-
const short = (v) => {
|
|
3730
|
-
if (v === void 0) return "nothing";
|
|
3731
|
-
const text = canonicalJson(v);
|
|
3732
|
-
return text.length > 120 ? `${text.slice(0, 117)}...` : text;
|
|
3733
|
-
};
|
|
3734
|
-
/** Two differing values, each cut to the stretch around where their texts part, so the excerpts differ too. */
|
|
3735
|
-
const apart = (x, y) => {
|
|
3736
|
-
if (x === void 0 || y === void 0) return [short(x), short(y)];
|
|
3737
|
-
const [s, t] = [canonicalJson(x), canonicalJson(y)];
|
|
3738
|
-
if (s.length <= 120 && t.length <= 120) return [s, t];
|
|
3739
|
-
let at = 0;
|
|
3740
|
-
while (at < s.length && at < t.length && s[at] === t[at]) at++;
|
|
3741
|
-
const from = Math.max(0, at - 40);
|
|
3742
|
-
const cut = (text) => `${from > 0 ? "..." : ""}${text.slice(from, from + 110)}${from + 110 < text.length ? "..." : ""}`;
|
|
3743
|
-
return [cut(s), cut(t)];
|
|
3744
|
-
};
|
|
3745
|
-
const head = (e) => `${e.kind} ${e.target} ${e.op} in ${e.invocation}`;
|
|
3746
|
-
const a = serializeLog(run).split("\n");
|
|
3747
|
-
const b = serializeLog(replay).split("\n");
|
|
3748
|
-
const n = Math.min(run.entries.length, replay.entries.length);
|
|
3749
|
-
for (let i = 0; i < n; i++) {
|
|
3750
|
-
if (a[i] === b[i]) continue;
|
|
3751
|
-
const ran = run.entries[i];
|
|
3752
|
-
const replayed = replay.entries[i];
|
|
3753
|
-
const within = head(ran) === head(replayed) && firstDifference(ran.payload, replayed.payload);
|
|
3754
|
-
if (within) {
|
|
3755
|
-
const [was, is] = apart(within.a, within.b);
|
|
3756
|
-
return `at seq ${i} the run recorded ${head(ran)} with ${was} at payload${within.path} and the replay with ${is}`;
|
|
3757
|
-
}
|
|
3758
|
-
return `at seq ${i} the run recorded ${head(ran)} ${short(ran.payload)} and the replay ${head(replayed)} ${short(replayed.payload)}`;
|
|
3759
|
-
}
|
|
3760
|
-
if (run.entries.length === replay.entries.length) return null;
|
|
3761
|
-
return `the run recorded ${run.entries.length} entries and the replay ${replay.entries.length}`;
|
|
3762
|
-
}
|
|
3763
|
-
/** Whether exhaustive exploration reduces by partial order (it does unless told not to). */
|
|
3764
|
-
function reductionOf(options) {
|
|
3765
|
-
return typeof options.exhaustive === "object" ? options.exhaustive.reduction ?? true : true;
|
|
3766
|
-
}
|
|
3767
|
-
/** What a verdict rests on about how schedules were chosen, when exploration was exhaustive. */
|
|
3768
|
-
function explorationAssumption(options) {
|
|
3769
|
-
if (!options.exhaustive) return [];
|
|
3770
|
-
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)"] : []];
|
|
3771
|
-
}
|
|
3772
|
-
/** Deliver events one at a time, each to completion; time passes until a delayed one is due. */
|
|
3773
|
-
async function deliverInOrder(spec, platform, run) {
|
|
3774
|
-
const pending = [...platform.initialEvents(spec)];
|
|
3775
|
-
for (;;) {
|
|
3776
|
-
if (pending.length === 0) pending.push(...platform.closingEvents?.(spec) ?? []);
|
|
3777
|
-
if (pending.length === 0) return;
|
|
3778
|
-
const [event] = pending.splice(earliestEvent(pending), 1);
|
|
3779
|
-
if (event.at !== void 0) await run.advanceTo(event.at);
|
|
3780
|
-
const result = await platform.deliver(event, run, spec);
|
|
3781
|
-
await run.driveAfterWork();
|
|
3782
|
-
pending.push(...run.takeQueued(), ...result.followUps);
|
|
3783
|
-
}
|
|
3784
|
-
}
|
|
3785
|
-
/**
|
|
3786
|
-
* Deliver events with up to `maxConcurrentInvocations` in flight. Each turn
|
|
3787
|
-
* is a seeded pick: one parked invocation performs its effect and runs to
|
|
3788
|
-
* its next one, while a slot is free the next event starts, or a timer
|
|
3789
|
-
* already due fires. When nothing is parked, no event can start and no
|
|
3790
|
-
* timer is due, the next timer fires (time passes to it), and when nothing
|
|
3791
|
-
* can move the remaining invocations are abandoned.
|
|
3792
|
-
*/
|
|
3793
|
-
async function deliverConcurrently(spec, platform, run) {
|
|
3794
|
-
const pending = [...platform.initialEvents(spec)];
|
|
3795
|
-
let active = [];
|
|
3796
|
-
for (;;) {
|
|
3797
|
-
const queuedBefore = pending.length;
|
|
3798
|
-
for (const d of active) {
|
|
3799
|
-
if (!d.outcome) continue;
|
|
3800
|
-
if ("error" in d.outcome) throw d.outcome.error;
|
|
3801
|
-
pending.push(...d.outcome.result.followUps);
|
|
3802
|
-
}
|
|
3803
|
-
active = active.filter((d) => !d.outcome);
|
|
3804
|
-
pending.push(...run.takeQueued());
|
|
3805
|
-
if (pending.length > queuedBefore) run.queuedEvents();
|
|
3806
|
-
if (active.length === 0 && pending.length === 0 && !run.hasAfterWork()) {
|
|
3807
|
-
pending.push(...platform.closingEvents?.(spec) ?? []);
|
|
3808
|
-
if (pending.length === 0) return;
|
|
3809
|
-
run.queuedEvents();
|
|
3810
|
-
}
|
|
3811
|
-
const next = pending.length > 0 ? earliestEvent(pending) : -1;
|
|
3812
|
-
const eventAt = pending[next]?.at ?? 0;
|
|
3813
|
-
const due = next >= 0 && eventAt <= run.now();
|
|
3814
|
-
const canStart = active.length < spec.bounds.maxConcurrentInvocations && due;
|
|
3815
|
-
const afterWorkOnly = active.length === 0 && run.hasAfterWork();
|
|
3816
|
-
const timerDue = run.nextTimerDue(afterWorkOnly);
|
|
3817
|
-
const untilEvent = next >= 0 && !due && active.length < spec.bounds.maxConcurrentInvocations && (timerDue ?? Number.POSITIVE_INFINITY) > eventAt;
|
|
3818
|
-
const turn = run.takeTurn(canStart, afterWorkOnly, untilEvent || timerDue !== void 0);
|
|
3819
|
-
if (turn === "start") {
|
|
3820
|
-
const [event] = pending.splice(next, 1);
|
|
3821
|
-
const d = {
|
|
3822
|
-
started: run.startDelivery(() => platform.deliver(event, run, spec)),
|
|
3823
|
-
outcome: null
|
|
3824
|
-
};
|
|
3825
|
-
d.started.promise.then((result) => {
|
|
3826
|
-
d.outcome = { result };
|
|
3827
|
-
run.rested();
|
|
3828
|
-
}, (error) => {
|
|
3829
|
-
d.outcome = { error };
|
|
3830
|
-
run.rested();
|
|
3831
|
-
});
|
|
3832
|
-
active.push(d);
|
|
3833
|
-
} else if (turn === "none" && untilEvent) {
|
|
3834
|
-
if (!await run.advanceTo(eventAt)) continue;
|
|
3835
|
-
} else if (turn === "none" && !(active.length > 0 || !run.hasAfterWork() ? run.fireTimer() : run.fireAfterWorkTimer()) && run.settleAfterWork() === 0) {
|
|
3836
|
-
const stuck = active.flatMap((d) => d.started.invocation() ?? []);
|
|
3837
|
-
if (run.abandon(stuck) === 0) {
|
|
3838
|
-
const ending = active.filter((d) => run.hasCrashed(d.started.invocation()));
|
|
3839
|
-
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`);
|
|
3840
|
-
}
|
|
3841
|
-
}
|
|
3842
|
-
await run.quiesce();
|
|
3843
|
-
}
|
|
4196
|
+
a,
|
|
4197
|
+
b
|
|
4198
|
+
};
|
|
3844
4199
|
}
|
|
3845
|
-
/**
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
4200
|
+
/**
|
|
4201
|
+
* The first record a replay recorded differently from the run, or how their
|
|
4202
|
+
* lengths differ; null when the logs match. Two records of the same effect
|
|
4203
|
+
* are told apart by the first value in their payloads that differs, with its
|
|
4204
|
+
* path: a snapshot of many tables that differs in one column says which.
|
|
4205
|
+
*/
|
|
4206
|
+
function whatDiffered(run, replay) {
|
|
4207
|
+
const short = (v) => {
|
|
4208
|
+
if (v === void 0) return "nothing";
|
|
4209
|
+
const text = canonicalJson(v);
|
|
4210
|
+
return text.length > 120 ? `${text.slice(0, 117)}...` : text;
|
|
4211
|
+
};
|
|
4212
|
+
/** Two differing values, each cut to the stretch around where their texts part, so the excerpts differ too. */
|
|
4213
|
+
const apart = (x, y) => {
|
|
4214
|
+
if (x === void 0 || y === void 0) return [short(x), short(y)];
|
|
4215
|
+
const [s, t] = [canonicalJson(x), canonicalJson(y)];
|
|
4216
|
+
if (s.length <= 120 && t.length <= 120) return [s, t];
|
|
4217
|
+
let at = 0;
|
|
4218
|
+
while (at < s.length && at < t.length && s[at] === t[at]) at++;
|
|
4219
|
+
const from = Math.max(0, at - 40);
|
|
4220
|
+
const cut = (text) => `${from > 0 ? "..." : ""}${text.slice(from, from + 110)}${from + 110 < text.length ? "..." : ""}`;
|
|
4221
|
+
return [cut(s), cut(t)];
|
|
4222
|
+
};
|
|
4223
|
+
const head = (e) => `${e.kind} ${e.target} ${e.op} in ${e.invocation}`;
|
|
4224
|
+
const a = serializeLog(run).split("\n");
|
|
4225
|
+
const b = serializeLog(replay).split("\n");
|
|
4226
|
+
const n = Math.min(run.entries.length, replay.entries.length);
|
|
4227
|
+
for (let i = 0; i < n; i++) {
|
|
4228
|
+
if (a[i] === b[i]) continue;
|
|
4229
|
+
const ran = run.entries[i];
|
|
4230
|
+
const replayed = replay.entries[i];
|
|
4231
|
+
const within = head(ran) === head(replayed) && firstDifference(ran.payload, replayed.payload);
|
|
4232
|
+
if (within) {
|
|
4233
|
+
const [was, is] = apart(within.a, within.b);
|
|
4234
|
+
return `at seq ${i} the run recorded ${head(ran)} with ${was} at payload${within.path} and the replay with ${is}`;
|
|
3856
4235
|
}
|
|
3857
|
-
|
|
3858
|
-
} finally {
|
|
3859
|
-
await platform.cleanup?.(spec);
|
|
4236
|
+
return `at seq ${i} the run recorded ${head(ran)} ${short(ran.payload)} and the replay ${head(replayed)} ${short(replayed.payload)}`;
|
|
3860
4237
|
}
|
|
3861
|
-
|
|
4238
|
+
if (run.entries.length === replay.entries.length) return null;
|
|
4239
|
+
return `the run recorded ${run.entries.length} entries and the replay ${replay.entries.length}`;
|
|
3862
4240
|
}
|
|
3863
|
-
/**
|
|
3864
|
-
|
|
4241
|
+
/** Whether exhaustive exploration reduces by partial order (it does unless told not to). */
|
|
4242
|
+
function reductionOf(options) {
|
|
4243
|
+
return typeof options.exhaustive === "object" ? options.exhaustive.reduction ?? true : true;
|
|
4244
|
+
}
|
|
4245
|
+
/** What a verdict rests on about how schedules were chosen, when exploration was exhaustive. */
|
|
4246
|
+
function explorationAssumption(options) {
|
|
4247
|
+
if (!options.exhaustive) return [];
|
|
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)"] : []];
|
|
4249
|
+
}
|
|
4250
|
+
/** One run of a pinned schedule under one seed: the run, its chooser and its log. */
|
|
4251
|
+
async function pinnedRun(spec, platform, pinned, seed, turns) {
|
|
4252
|
+
const chooser = pinnedChooser(pinned, seed);
|
|
3865
4253
|
const run = new Run({
|
|
3866
4254
|
bounds: spec.bounds,
|
|
3867
|
-
chooser
|
|
4255
|
+
chooser,
|
|
4256
|
+
turns: turns || pinned.effectsAsTurns === true
|
|
3868
4257
|
});
|
|
3869
|
-
|
|
3870
|
-
|
|
4258
|
+
return {
|
|
4259
|
+
run,
|
|
4260
|
+
chooser,
|
|
4261
|
+
log: await runOnce(spec, platform, run)
|
|
4262
|
+
};
|
|
4263
|
+
}
|
|
4264
|
+
/**
|
|
4265
|
+
* Run a pinned schedule once, under `seed` (default its first), each fault at the call it names:
|
|
4266
|
+
* the replay of an `UNSUPPORTED` verdict's `replay`, or of one of a scenario's pinned schedules.
|
|
4267
|
+
*/
|
|
4268
|
+
async function runPinned(spec, platform, pinned, seed = pinnedSeeds(pinned)[0] ?? 0) {
|
|
4269
|
+
const errors = validatePinnedSchedules([pinned]);
|
|
4270
|
+
if (errors.length > 0) throw new Error(errors.join("; "));
|
|
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));
|
|
4274
|
+
return {
|
|
4275
|
+
log,
|
|
4276
|
+
schedule: run.schedule,
|
|
4277
|
+
unsupportedReasons: run.unsupportedReasons,
|
|
4278
|
+
unplaced: chooser.unplaced()
|
|
4279
|
+
};
|
|
3871
4280
|
}
|
|
3872
4281
|
/** Re-run a recorded schedule exactly. */
|
|
3873
4282
|
async function replay(spec, platform, schedule) {
|
|
3874
4283
|
return (await replayRun(spec, platform, schedule)).log;
|
|
3875
4284
|
}
|
|
3876
4285
|
/**
|
|
3877
|
-
* Explore a scenario on a platform: run it under schedules drawn from the
|
|
3878
|
-
* the bounds, when exhaustive), shrink the first violation
|
|
3879
|
-
* unless `maxRuns` says otherwise.
|
|
4286
|
+
* Explore a scenario on a platform: run its pinned schedules, then run it under schedules drawn from the
|
|
4287
|
+
* seed (or every schedule within the bounds, when exhaustive), shrink the first violation exploration
|
|
4288
|
+
* found, and return the verdict. At most 100 runs of exploration unless `maxRuns` says otherwise.
|
|
3880
4289
|
*/
|
|
3881
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) {
|
|
3882
4312
|
const budgetMs = options.budgetMs;
|
|
3883
4313
|
if (budgetMs !== void 0 && !(Number.isFinite(budgetMs) && budgetMs > 0)) throw new Error(`budgetMs must be a positive finite number, got ${budgetMs}`);
|
|
3884
4314
|
const spec = budgetMs === void 0 ? scenario : {
|
|
@@ -3888,21 +4318,42 @@ async function explore(scenario, platform, options) {
|
|
|
3888
4318
|
budgetMs
|
|
3889
4319
|
}
|
|
3890
4320
|
};
|
|
4321
|
+
const specErrors = [...spec.bounds.faultsAt === void 0 ? [] : validateFaultSites(spec.bounds.faultsAt), ...spec.pinned === void 0 ? [] : validatePinnedSchedules(spec.pinned)];
|
|
4322
|
+
if (specErrors.length > 0) throw new Error(specErrors.join("; "));
|
|
3891
4323
|
const now = options.now ?? (() => Date.now());
|
|
3892
4324
|
const maxRuns = options.maxRuns ?? 100;
|
|
3893
4325
|
const faultProbability = options.faultProbability ?? .9;
|
|
3894
4326
|
const assumptions = [
|
|
3895
|
-
...engineAssumptions,
|
|
3896
|
-
|
|
4327
|
+
...engineAssumptions.slice(0, 1),
|
|
4328
|
+
faultAssumption(spec.bounds),
|
|
4329
|
+
...engineAssumptions.slice(1),
|
|
4330
|
+
concurrencyAssumption(spec.bounds, mode.turns),
|
|
3897
4331
|
...explorationAssumption(options),
|
|
4332
|
+
...spec.pinned === void 0 ? [] : [pinnedAssumption(spec.pinned)],
|
|
3898
4333
|
...platform.assumptions
|
|
3899
4334
|
];
|
|
3900
|
-
const start =
|
|
4335
|
+
const start = mode.start;
|
|
3901
4336
|
const reached = {
|
|
3902
|
-
runs:
|
|
4337
|
+
runs: mode.runs,
|
|
3903
4338
|
effectPoints: 0,
|
|
3904
4339
|
faultsInjected: 0
|
|
3905
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"})`;
|
|
3906
4357
|
const done = () => ({
|
|
3907
4358
|
...reached,
|
|
3908
4359
|
elapsedMs: now() - start
|
|
@@ -3928,14 +4379,120 @@ async function explore(scenario, platform, options) {
|
|
|
3928
4379
|
});
|
|
3929
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)");
|
|
3930
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)}`);
|
|
4384
|
+
/**
|
|
4385
|
+
* A run met something outside the model: the verdict carries its schedule and, when the run
|
|
4386
|
+
* replayed alone by its faults' calls gets there again (checked here, with one more run), the
|
|
4387
|
+
* same run as a pinned schedule, which a test can replay. A run that got there only through what
|
|
4388
|
+
* earlier runs left behind does not, and carries its schedule alone.
|
|
4389
|
+
*/
|
|
4390
|
+
const unsupportedApi = async (run) => {
|
|
4391
|
+
const reason = run.unsupportedReasons.join("; ");
|
|
4392
|
+
const verdict = unsupported("unsupported_api", reason, run.schedule);
|
|
4393
|
+
const replay = run.asPinned("the run that reached UNSUPPORTED");
|
|
4394
|
+
const again = await pinnedRun(spec, platform, replay, run.schedule.seed, mode.turns);
|
|
4395
|
+
reached.runs++;
|
|
4396
|
+
return again.chooser.unplaced().length === 0 && again.run.unsupportedReasons.join("; ") === reason ? {
|
|
4397
|
+
...verdict,
|
|
4398
|
+
replay,
|
|
4399
|
+
reached: doneNow()
|
|
4400
|
+
} : {
|
|
4401
|
+
...verdict,
|
|
4402
|
+
reached: doneNow()
|
|
4403
|
+
};
|
|
4404
|
+
};
|
|
4405
|
+
/**
|
|
4406
|
+
* A run broke an invariant: replay it, which must give the same log, then report it, shrunk
|
|
4407
|
+
* when exploration found it and as it ran when it is a pinned schedule's.
|
|
4408
|
+
*/
|
|
4409
|
+
const violated = async (run, log, violation, pinned) => {
|
|
4410
|
+
const schedule = run.schedule;
|
|
4411
|
+
const replayedRun = await replayRun(spec, platform, schedule);
|
|
4412
|
+
const replayed = replayedRun.log;
|
|
4413
|
+
reached.runs++;
|
|
4414
|
+
if (startsOver(replayedRun)) return over(replayedRun);
|
|
4415
|
+
leftToRealTime ??= replayedRun.parallelCalls;
|
|
4416
|
+
if (replayedRun.unsupportedReasons.length > 0) return unsupported("unsupported_api", replayedRun.unsupportedReasons.join("; "), schedule);
|
|
4417
|
+
const differed = whatDiffered(log, replayed);
|
|
4418
|
+
if (differed) return unsupported("not_replayable", `the violating run of seed ${schedule.seed} did not reproduce on replay: ${differed}${unorderedCalls()}`, schedule);
|
|
4419
|
+
if (pinned !== void 0) return {
|
|
4420
|
+
...base,
|
|
4421
|
+
kind: "VIOLATED",
|
|
4422
|
+
violation,
|
|
4423
|
+
trace: replayed,
|
|
4424
|
+
schedule,
|
|
4425
|
+
keptEvents: platform.initialEvents(spec).map((e) => e.id),
|
|
4426
|
+
shrunk: {
|
|
4427
|
+
faultsRemoved: 0,
|
|
4428
|
+
eventsRemoved: 0,
|
|
4429
|
+
runs: 0
|
|
4430
|
+
},
|
|
4431
|
+
pinned: pinned.name,
|
|
4432
|
+
...pinned.unplaced.length === 0 ? {} : { unplaced: pinned.unplaced },
|
|
4433
|
+
reached: doneNow()
|
|
4434
|
+
};
|
|
4435
|
+
const shrunk = await shrink(spec, platform, schedule, violation, replayed, {
|
|
4436
|
+
maxRuns: options.maxShrinkRuns ?? 200,
|
|
4437
|
+
deadline: now() + spec.bounds.budgetMs,
|
|
4438
|
+
now
|
|
4439
|
+
});
|
|
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
|
+
};
|
|
4445
|
+
return {
|
|
4446
|
+
...base,
|
|
4447
|
+
kind: "VIOLATED",
|
|
4448
|
+
violation: shrunk.violation,
|
|
4449
|
+
trace: shrunk.trace,
|
|
4450
|
+
schedule: shrunk.schedule,
|
|
4451
|
+
keptEvents: shrunk.keptEvents,
|
|
4452
|
+
shrunk: {
|
|
4453
|
+
faultsRemoved: shrunk.faultsRemoved,
|
|
4454
|
+
eventsRemoved: shrunk.eventsRemoved,
|
|
4455
|
+
runs: shrunk.runs
|
|
4456
|
+
},
|
|
4457
|
+
reached: doneNow()
|
|
4458
|
+
};
|
|
4459
|
+
};
|
|
4460
|
+
/** Whether any run had a point that may take a fault: sites that matched none say nothing. */
|
|
4461
|
+
let anyEligible = false;
|
|
3931
4462
|
const leakCheckRuns = options.leakCheckRuns ?? 2;
|
|
3932
|
-
/**
|
|
4463
|
+
/**
|
|
4464
|
+
* The first runs' schedules and logs, the pinned ones' included, replayed in reverse order before
|
|
4465
|
+
* BOUNDED: state a first run leaves behind shows as a difference wherever that run came from.
|
|
4466
|
+
*/
|
|
3933
4467
|
const witnesses = [];
|
|
4468
|
+
for (const pinned of spec.pinned ?? []) for (const seed of pinnedSeeds(pinned)) {
|
|
4469
|
+
const { run, chooser, log } = await pinnedRun(spec, platform, pinned, seed, mode.turns);
|
|
4470
|
+
reached.runs++;
|
|
4471
|
+
if (startsOver(run)) return over(run);
|
|
4472
|
+
leftToRealTime ??= run.parallelCalls;
|
|
4473
|
+
reached.effectPoints += run.effectPoints;
|
|
4474
|
+
reached.faultsInjected += run.faultsInjected;
|
|
4475
|
+
if (run.unsupportedReasons.length > 0) return await unsupportedApi(run);
|
|
4476
|
+
if (run.eligiblePoints > 0) anyEligible = true;
|
|
4477
|
+
const unplaced = chooser.unplaced();
|
|
4478
|
+
const violation = checkInvariants(log, spec.invariants)[0];
|
|
4479
|
+
if (violation) return await violated(run, log, violation, {
|
|
4480
|
+
name: pinned.name,
|
|
4481
|
+
unplaced
|
|
4482
|
+
});
|
|
4483
|
+
if (unplaced.length > 0) return unsupported("pin_not_placed", `pinned schedule ${JSON.stringify(pinned.name)} under seed ${seed}: ${unplaced.join("; ")}`, run.schedule);
|
|
4484
|
+
if (witnesses.length < leakCheckRuns) witnesses.push({
|
|
4485
|
+
schedule: run.schedule,
|
|
4486
|
+
log
|
|
4487
|
+
});
|
|
4488
|
+
}
|
|
4489
|
+
/** Runs before exploration (the pinned schedules'), which the run cap does not count. */
|
|
4490
|
+
const pinnedRuns = reached.runs;
|
|
3934
4491
|
let master = seedPrng(options.seed);
|
|
3935
4492
|
/** Eligible points of a run without faults, and the most any run has had: seeded fault positions. */
|
|
3936
4493
|
let baseline = 0;
|
|
3937
4494
|
let longest = 0;
|
|
3938
|
-
while ((exhaustive?.hasMore ?? true) && reached.runs < maxRuns && now() - start < spec.bounds.budgetMs) {
|
|
4495
|
+
while ((exhaustive?.hasMore ?? true) && reached.runs - pinnedRuns < maxRuns && (reached.runs === pinnedRuns || now() - start < spec.bounds.budgetMs)) {
|
|
3939
4496
|
const [runSeed, next] = nextU32(master);
|
|
3940
4497
|
master = next;
|
|
3941
4498
|
let faultPlan = [];
|
|
@@ -3946,12 +4503,16 @@ async function explore(scenario, platform, options) {
|
|
|
3946
4503
|
faultPlan,
|
|
3947
4504
|
faultProbability,
|
|
3948
4505
|
maxFaultsPerRun: spec.bounds.maxFaultsPerRun
|
|
3949
|
-
})
|
|
4506
|
+
}),
|
|
4507
|
+
turns: mode.turns
|
|
3950
4508
|
});
|
|
3951
4509
|
const log = await runOnce(spec, platform, run);
|
|
3952
4510
|
reached.runs++;
|
|
4511
|
+
if (startsOver(run)) return over(run);
|
|
4512
|
+
leftToRealTime ??= run.parallelCalls;
|
|
3953
4513
|
if (run.faultsInjected === 0) baseline = Math.max(baseline, run.eligiblePoints);
|
|
3954
4514
|
longest = Math.max(longest, run.eligiblePoints);
|
|
4515
|
+
if (run.eligiblePoints > 0) anyEligible = true;
|
|
3955
4516
|
if (exhaustive) {
|
|
3956
4517
|
if (exhaustive.mismatch) return unsupported("not_replayable", `exhaustive exploration needs deterministic runs: ${exhaustive.mismatch}`, run.schedule);
|
|
3957
4518
|
if (!exhaustive.ran(() => run.turnsMayNotCommute)) continue;
|
|
@@ -3962,45 +4523,20 @@ async function explore(scenario, platform, options) {
|
|
|
3962
4523
|
schedule: run.schedule,
|
|
3963
4524
|
log
|
|
3964
4525
|
});
|
|
3965
|
-
if (run.unsupportedReasons.length > 0) return
|
|
4526
|
+
if (run.unsupportedReasons.length > 0) return await unsupportedApi(run);
|
|
3966
4527
|
const violation = checkInvariants(log, spec.invariants)[0];
|
|
3967
|
-
if (violation)
|
|
3968
|
-
const schedule = run.schedule;
|
|
3969
|
-
const replayedRun = await replayRun(spec, platform, schedule);
|
|
3970
|
-
const replayed = replayedRun.log;
|
|
3971
|
-
reached.runs++;
|
|
3972
|
-
if (replayedRun.unsupportedReasons.length > 0) return unsupported("unsupported_api", replayedRun.unsupportedReasons.join("; "), schedule);
|
|
3973
|
-
const differed = whatDiffered(log, replayed);
|
|
3974
|
-
if (differed) return unsupported("not_replayable", `the violating run of seed ${schedule.seed} did not reproduce on replay: ${differed}`, schedule);
|
|
3975
|
-
const shrunk = await shrink(spec, platform, schedule, violation, replayed, {
|
|
3976
|
-
maxRuns: options.maxShrinkRuns ?? 200,
|
|
3977
|
-
deadline: now() + spec.bounds.budgetMs,
|
|
3978
|
-
now
|
|
3979
|
-
});
|
|
3980
|
-
reached.runs += shrunk.runs;
|
|
3981
|
-
return {
|
|
3982
|
-
...base,
|
|
3983
|
-
kind: "VIOLATED",
|
|
3984
|
-
violation: shrunk.violation,
|
|
3985
|
-
trace: shrunk.trace,
|
|
3986
|
-
schedule: shrunk.schedule,
|
|
3987
|
-
keptEvents: shrunk.keptEvents,
|
|
3988
|
-
shrunk: {
|
|
3989
|
-
faultsRemoved: shrunk.faultsRemoved,
|
|
3990
|
-
eventsRemoved: shrunk.eventsRemoved,
|
|
3991
|
-
runs: shrunk.runs
|
|
3992
|
-
},
|
|
3993
|
-
reached: doneNow()
|
|
3994
|
-
};
|
|
3995
|
-
}
|
|
4528
|
+
if (violation) return await violated(run, log, violation);
|
|
3996
4529
|
exhaustive?.checked();
|
|
3997
4530
|
}
|
|
4531
|
+
if (spec.bounds.faultsAt !== void 0 && spec.bounds.maxFaultsPerRun > 0 && !anyEligible) return unsupported("unsupported_bounds", `bounds.faultsAt matched no effect point that may take a fault in ${reached.runs - pinnedRuns} run(s) of exploration, so no fault was injected; compare the sites' targets, ops, conditions and kinds with the effects a trace shows`);
|
|
3998
4532
|
for (const witness of [...witnesses].reverse()) {
|
|
3999
4533
|
const again = await replayRun(spec, platform, witness.schedule);
|
|
4000
4534
|
reached.runs++;
|
|
4535
|
+
if (startsOver(again)) return over(again);
|
|
4536
|
+
leftToRealTime ??= again.parallelCalls;
|
|
4001
4537
|
if (again.unsupportedReasons.length > 0) return unsupported("unsupported_api", again.unsupportedReasons.join("; "), witness.schedule);
|
|
4002
4538
|
const differed = whatDiffered(witness.log, again.log);
|
|
4003
|
-
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);
|
|
4004
4540
|
}
|
|
4005
4541
|
return {
|
|
4006
4542
|
...base,
|
|
@@ -4009,145 +4545,6 @@ async function explore(scenario, platform, options) {
|
|
|
4009
4545
|
reached: doneNow()
|
|
4010
4546
|
};
|
|
4011
4547
|
}
|
|
4012
|
-
// packages/engine/src/differential.ts
|
|
4013
|
-
/**
|
|
4014
|
-
* The platform-neutral part of a differential check: the same fault-free
|
|
4015
|
-
* scenario once through Eutaxy and once against the raw bindings, then a
|
|
4016
|
-
* comparison of what each attempt decided and of the final state. Any
|
|
4017
|
-
* difference is a bug in the proxies or the platform model, not in the
|
|
4018
|
-
* handler. The raw side's loop is here too (the same virtual globals and
|
|
4019
|
-
* scripted externals as the proxied side, the same pick of the next event
|
|
4020
|
-
* and the same redelivery rule); a platform writes only how one raw attempt
|
|
4021
|
-
* calls its handler, sharing no proxy code.
|
|
4022
|
-
*/
|
|
4023
|
-
/** The raw side cannot abandon an invocation the way the engine does; a stuck handler ends the comparison. */
|
|
4024
|
-
var DifferentialStuck = class extends Error {
|
|
4025
|
-
name = "DifferentialStuck";
|
|
4026
|
-
constructor(message = "raw side: the handler is waiting on something outside the run (no effect in flight, no timer due)") {
|
|
4027
|
-
super(message);
|
|
4028
|
-
}
|
|
4029
|
-
};
|
|
4030
|
-
/**
|
|
4031
|
-
* The Eutaxy side: one run with no faults, one event at a time whatever the
|
|
4032
|
-
* scenario's bound (the raw side cannot interleave), with `attempt` given
|
|
4033
|
-
* each delivery's event, result and log entries.
|
|
4034
|
-
*/
|
|
4035
|
-
async function proxiedSide(spec, platform, attempt) {
|
|
4036
|
-
const run = new Run({
|
|
4037
|
-
bounds: {
|
|
4038
|
-
...spec.bounds,
|
|
4039
|
-
maxConcurrentInvocations: 1
|
|
4040
|
-
},
|
|
4041
|
-
chooser: replayChooser({
|
|
4042
|
-
seed: 0,
|
|
4043
|
-
faults: []
|
|
4044
|
-
})
|
|
4045
|
-
});
|
|
4046
|
-
const attempts = [];
|
|
4047
|
-
const { finish, cleanup } = platform;
|
|
4048
|
-
await runOnce(spec, {
|
|
4049
|
-
name: platform.name,
|
|
4050
|
-
assumptions: platform.assumptions,
|
|
4051
|
-
...platform.concurrent === void 0 ? {} : { concurrent: platform.concurrent },
|
|
4052
|
-
reset: (s) => platform.reset(s),
|
|
4053
|
-
initialEvents: (s) => platform.initialEvents(s),
|
|
4054
|
-
restrictEvents: (s, keep) => platform.restrictEvents(s, keep),
|
|
4055
|
-
async deliver(event, hooks, s) {
|
|
4056
|
-
const before = run.log.entries.length;
|
|
4057
|
-
const result = await platform.deliver(event, hooks, s);
|
|
4058
|
-
attempts.push(attempt(event, result, run.log.entries.slice(before)));
|
|
4059
|
-
return result;
|
|
4060
|
-
},
|
|
4061
|
-
...finish ? { finish: (s, hooks) => finish.call(platform, s, hooks) } : {},
|
|
4062
|
-
...cleanup ? { cleanup: (s) => cleanup.call(platform, s) } : {}
|
|
4063
|
-
}, run);
|
|
4064
|
-
return {
|
|
4065
|
-
attempts,
|
|
4066
|
-
unsupported: run.unsupportedReasons
|
|
4067
|
-
};
|
|
4068
|
-
}
|
|
4069
|
-
/**
|
|
4070
|
-
* The raw side: every event delivered as the engine would deliver it with
|
|
4071
|
-
* no faults and one invocation at a time (the earliest due first, time
|
|
4072
|
-
* moved to a delayed one, an unhandled one delivered again under core's
|
|
4073
|
-
* redelivery rule), each attempt performed by the platform. The attempts'
|
|
4074
|
-
* records, in order.
|
|
4075
|
-
*/
|
|
4076
|
-
async function rawRun(spec, side) {
|
|
4077
|
-
const patched = patchGlobals(0);
|
|
4078
|
-
const reasons = [];
|
|
4079
|
-
const unsupported = (reason) => {
|
|
4080
|
-
reasons.push(reason);
|
|
4081
|
-
};
|
|
4082
|
-
const restoreFetch = installScriptedFetch(spec.externals, null, unsupported, () => patched.clock.advance(1));
|
|
4083
|
-
const io = { n: 0 };
|
|
4084
|
-
const settle = (promise) => settleOn(promise, {
|
|
4085
|
-
clock: patched.clock,
|
|
4086
|
-
inFlight: () => io.n,
|
|
4087
|
-
crashed: () => false,
|
|
4088
|
-
stuck: () => {
|
|
4089
|
-
throw new DifferentialStuck();
|
|
4090
|
-
}
|
|
4091
|
-
});
|
|
4092
|
-
const call = async (code) => {
|
|
4093
|
-
try {
|
|
4094
|
-
return {
|
|
4095
|
-
status: "completed",
|
|
4096
|
-
value: await settle(Promise.resolve().then(code))
|
|
4097
|
-
};
|
|
4098
|
-
} catch (error) {
|
|
4099
|
-
if (error instanceof DifferentialStuck) throw error;
|
|
4100
|
-
return {
|
|
4101
|
-
status: "errored",
|
|
4102
|
-
error
|
|
4103
|
-
};
|
|
4104
|
-
}
|
|
4105
|
-
};
|
|
4106
|
-
const attempts = [];
|
|
4107
|
-
const pending = [...side.events];
|
|
4108
|
-
let restore;
|
|
4109
|
-
try {
|
|
4110
|
-
const installed = side.install({
|
|
4111
|
-
clock: patched.clock,
|
|
4112
|
-
io,
|
|
4113
|
-
libraryIo: (perform) => patched.libraryIo(perform),
|
|
4114
|
-
unsupported,
|
|
4115
|
-
settle,
|
|
4116
|
-
call
|
|
4117
|
-
});
|
|
4118
|
-
restore = installed.restore;
|
|
4119
|
-
const { attempt } = installed;
|
|
4120
|
-
while (pending.length > 0) {
|
|
4121
|
-
const [event] = pending.splice(earliestEvent(pending), 1);
|
|
4122
|
-
if (event.at !== void 0 && event.at > patched.clock.now()) patched.clock.advance(event.at - patched.clock.now());
|
|
4123
|
-
const { record, handled } = await attempt(event);
|
|
4124
|
-
attempts.push(record);
|
|
4125
|
-
const next = handled ? null : redelivery(event, side.limit, spec.bounds);
|
|
4126
|
-
if (next) pending.push(next);
|
|
4127
|
-
}
|
|
4128
|
-
} finally {
|
|
4129
|
-
restore?.();
|
|
4130
|
-
restoreFetch();
|
|
4131
|
-
patched.restore();
|
|
4132
|
-
}
|
|
4133
|
-
if (reasons.length > 0) throw new DifferentialStuck(`raw side: ${reasons.join("; ")}`);
|
|
4134
|
-
return attempts;
|
|
4135
|
-
}
|
|
4136
|
-
/** Every difference between the two sides, one readable entry each; none means they agree. */
|
|
4137
|
-
function compareSides(eutaxy, raw, unsupported) {
|
|
4138
|
-
const differences = [];
|
|
4139
|
-
if (unsupported.length > 0) differences.push(`the proxied run touched unsupported APIs: ${unsupported.join("; ")}`);
|
|
4140
|
-
const a = canonicalJson(eutaxy.attempts);
|
|
4141
|
-
const b = canonicalJson(raw.attempts);
|
|
4142
|
-
if (a !== b) differences.push(`attempts differ:\n eutaxy ${a}\n raw ${b}`);
|
|
4143
|
-
const names = /* @__PURE__ */ new Set([...Object.keys(eutaxy.state), ...Object.keys(raw.state)]);
|
|
4144
|
-
for (const name of [...names].sort()) {
|
|
4145
|
-
const x = canonicalJson(eutaxy.state[name] ?? []);
|
|
4146
|
-
const y = canonicalJson(raw.state[name] ?? []);
|
|
4147
|
-
if (x !== y) differences.push(`${name} differs:\n eutaxy ${x}\n raw ${y}`);
|
|
4148
|
-
}
|
|
4149
|
-
return differences;
|
|
4150
|
-
}
|
|
4151
4548
|
// packages/engine/src/observe.ts
|
|
4152
4549
|
/**
|
|
4153
4550
|
* Observe a module's pure core functions while runs are installed: each call
|
|
@@ -4227,6 +4624,6 @@ function observeCore(namespace, functions) {
|
|
|
4227
4624
|
}
|
|
4228
4625
|
};
|
|
4229
4626
|
}
|
|
4230
|
-
export {
|
|
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 };
|
|
4231
4628
|
|
|
4232
|
-
//# sourceMappingURL=src-
|
|
4629
|
+
//# sourceMappingURL=src-Dx4QvrQb.mjs.map
|