eutaxy 0.9.0 → 0.10.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 +12 -9
- package/dist/aws.d.mts +2 -2
- package/dist/aws.d.mts.map +1 -1
- package/dist/aws.mjs +20 -36
- package/dist/aws.mjs.map +1 -1
- package/dist/bin.mjs +2 -2
- package/dist/cli-Di86EM3f.mjs +2 -0
- package/dist/cli.mjs +2 -2
- package/dist/cloudflare.d.mts +149 -14
- package/dist/cloudflare.d.mts.map +1 -1
- package/dist/cloudflare.mjs +3 -3
- package/dist/delivery-invariants-Br29H7Rg.mjs +62 -0
- package/dist/delivery-invariants-Br29H7Rg.mjs.map +1 -0
- package/dist/{delivery-invariants-DfPkJL0Q.d.mts → delivery-invariants-DZOBkCMR.d.mts} +2 -2
- package/dist/{delivery-invariants-DfPkJL0Q.d.mts.map → delivery-invariants-DZOBkCMR.d.mts.map} +1 -1
- package/dist/{explore-Rwe1PPqX.d.mts → explore-B7aR_5Hy.d.mts} +2 -2
- package/dist/{explore-Rwe1PPqX.d.mts.map → explore-B7aR_5Hy.d.mts.map} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{platform-Bpnav0kn.d.mts → platform-CCz48WF9.d.mts} +30 -30
- package/dist/platform-CCz48WF9.d.mts.map +1 -0
- package/dist/{src-BZtuuu_j.mjs → src-CWVQEhTr.mjs} +2 -2
- package/dist/{src-BZtuuu_j.mjs.map → src-CWVQEhTr.mjs.map} +1 -1
- package/dist/{src-BO7I3f-1.mjs → src-DGh7w877.mjs} +470 -265
- package/dist/src-DGh7w877.mjs.map +1 -0
- package/dist/{src-BzZU6eGF.mjs → src-MX90l1IH.mjs} +5301 -3469
- package/dist/src-MX90l1IH.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/cli-DpeAhtU5.mjs +0 -2
- package/dist/delivery-invariants-hmhwh_qD.mjs +0 -39
- package/dist/delivery-invariants-hmhwh_qD.mjs.map +0 -1
- package/dist/platform-Bpnav0kn.d.mts.map +0 -1
- package/dist/src-BO7I3f-1.mjs.map +0 -1
- package/dist/src-BzZU6eGF.mjs.map +0 -1
|
@@ -214,6 +214,26 @@ function nextInt(state, bound) {
|
|
|
214
214
|
* record of which fault was injected at which effect point in one run.
|
|
215
215
|
*/
|
|
216
216
|
/**
|
|
217
|
+
* The ladders of faults an effect's kind admits, written once; a proxy names
|
|
218
|
+
* one as a point's `allowed` faults. A point with a meaning of its own (the
|
|
219
|
+
* response point, a Workflow step, the background point) lists its own.
|
|
220
|
+
*/
|
|
221
|
+
/** An effect that may commit and whose answer may be lost: a write, a call into another system, an outbound request. */
|
|
222
|
+
const writeFaults = [
|
|
223
|
+
"crash_before",
|
|
224
|
+
"crash_after",
|
|
225
|
+
"ambiguous",
|
|
226
|
+
"error"
|
|
227
|
+
];
|
|
228
|
+
/** An effect with nothing to be ambiguous about: a read, or a handler run whose failure is seen either way. */
|
|
229
|
+
const readFaults = [
|
|
230
|
+
"crash_before",
|
|
231
|
+
"crash_after",
|
|
232
|
+
"error"
|
|
233
|
+
];
|
|
234
|
+
/** A decision a platform records on the invocation's behalf (an ack, a delete): the invocation may die either side of it; it neither errors nor goes missing. */
|
|
235
|
+
const decisionFaults = ["crash_before", "crash_after"];
|
|
236
|
+
/**
|
|
217
237
|
* Decide whether to inject a fault at an effect point during exploration.
|
|
218
238
|
* Pure: the same state and inputs always give the same decision. The PRNG is
|
|
219
239
|
* only consumed when a fault is possible, so adding an ineligible point does
|
|
@@ -667,6 +687,105 @@ function walk(value, extra, depth, seen) {
|
|
|
667
687
|
seen.delete(object);
|
|
668
688
|
}
|
|
669
689
|
}
|
|
690
|
+
// packages/engine/src/chooser.ts
|
|
691
|
+
/**
|
|
692
|
+
* How a run chooses. A run's nondeterminism is a sequence of decisions: a
|
|
693
|
+
* fault (or none) at each effect point that may take one, and the next turn
|
|
694
|
+
* at each scheduling decision of a concurrent run. One object makes them
|
|
695
|
+
* all. Exploring from a seed draws them (`seededChooser`), replaying a
|
|
696
|
+
* schedule looks them up (`replayChooser`), and exhaustive exploration picks
|
|
697
|
+
* them from the enumerator (`exhaustive.ts`), which walks every sequence of
|
|
698
|
+
* choices once. The run only asks; which faults a run may take, how many and
|
|
699
|
+
* where is the chooser's, so the run loop holds no policy.
|
|
700
|
+
*/
|
|
701
|
+
/**
|
|
702
|
+
* Choices drawn from the seed: faults from a stream seeded by it, placed by
|
|
703
|
+
* the plan; turns from a separate stream (`turns:<seed>`), so a fault more
|
|
704
|
+
* or less does not move the picks after it.
|
|
705
|
+
*/
|
|
706
|
+
function seededChooser(seed, placement) {
|
|
707
|
+
let faults = seedPrng(seed);
|
|
708
|
+
let turns = seedPrng(`turns:${seed}`);
|
|
709
|
+
let position = 0;
|
|
710
|
+
let injected = 0;
|
|
711
|
+
return {
|
|
712
|
+
seed,
|
|
713
|
+
recordsTurns: false,
|
|
714
|
+
choose(kind, options) {
|
|
715
|
+
if (kind === "turn") {
|
|
716
|
+
if (options.length < 2) return 0;
|
|
717
|
+
const [i, next] = nextInt(turns, options.length);
|
|
718
|
+
turns = next;
|
|
719
|
+
return i;
|
|
720
|
+
}
|
|
721
|
+
if (options.length < 2) return 0;
|
|
722
|
+
const at = position++;
|
|
723
|
+
let i = 0;
|
|
724
|
+
if (placement.faultPlan) {
|
|
725
|
+
if (injected >= placement.maxFaultsPerRun || !placement.faultPlan.includes(at)) return 0;
|
|
726
|
+
const [k, next] = nextInt(faults, options.length - 1);
|
|
727
|
+
faults = next;
|
|
728
|
+
i = k + 1;
|
|
729
|
+
} else {
|
|
730
|
+
const kinds = options.slice(1).map((o) => o.label);
|
|
731
|
+
const [fault, next] = decideFault(faults, kinds, injected, placement);
|
|
732
|
+
faults = next;
|
|
733
|
+
i = fault === null ? 0 : kinds.indexOf(fault) + 1;
|
|
734
|
+
}
|
|
735
|
+
if (i > 0) injected++;
|
|
736
|
+
return i;
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Choices a recorded schedule made: its fault at the point (none when it
|
|
742
|
+
* recorded none, or one the point no longer allows), its turns when it
|
|
743
|
+
* recorded them (the run takes one past the options as the first), else the
|
|
744
|
+
* seed's.
|
|
745
|
+
*/
|
|
746
|
+
function replayChooser(schedule) {
|
|
747
|
+
const recorded = schedule.turns;
|
|
748
|
+
let replayed = 0;
|
|
749
|
+
let turns = seedPrng(`turns:${schedule.seed}`);
|
|
750
|
+
return {
|
|
751
|
+
seed: schedule.seed,
|
|
752
|
+
recordsTurns: recorded !== void 0,
|
|
753
|
+
choose(kind, options) {
|
|
754
|
+
if (kind === "turn") {
|
|
755
|
+
if (options.length < 2) return 0;
|
|
756
|
+
if (recorded) return recorded[replayed++] ?? 0;
|
|
757
|
+
const [i, next] = nextInt(turns, options.length);
|
|
758
|
+
turns = next;
|
|
759
|
+
return i;
|
|
760
|
+
}
|
|
761
|
+
if (options.length < 2) return 0;
|
|
762
|
+
const at = options[0];
|
|
763
|
+
const decision = schedule.faults.find((f) => f.invocation === at?.invocation && f.ordinal === at?.ordinal);
|
|
764
|
+
if (!decision) return 0;
|
|
765
|
+
const i = options.findIndex((o) => o.label === decision.fault);
|
|
766
|
+
return Math.max(i, 0);
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* The chooser under the run's fault bound: once it has taken `max` faults,
|
|
772
|
+
* no further fault decision is put to it (the enumerator then sees no
|
|
773
|
+
* choice there).
|
|
774
|
+
*/
|
|
775
|
+
function limitFaults(chooser, max) {
|
|
776
|
+
let injected = 0;
|
|
777
|
+
return {
|
|
778
|
+
seed: chooser.seed,
|
|
779
|
+
recordsTurns: chooser.recordsTurns,
|
|
780
|
+
choose(kind, options) {
|
|
781
|
+
if (kind !== "fault") return chooser.choose(kind, options);
|
|
782
|
+
if (injected >= max) return 0;
|
|
783
|
+
const i = chooser.choose(kind, options);
|
|
784
|
+
if (i > 0) injected++;
|
|
785
|
+
return i;
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
}
|
|
670
789
|
// packages/engine/src/context.ts
|
|
671
790
|
/** A new async context slot, or null where the host has no AsyncLocalStorage. */
|
|
672
791
|
function asyncScope() {
|
|
@@ -965,14 +1084,24 @@ function realDeadline(ms) {
|
|
|
965
1084
|
function realTick() {
|
|
966
1085
|
return new Promise((resolve) => realSetTimeout(() => resolve(), 0));
|
|
967
1086
|
}
|
|
968
|
-
const
|
|
1087
|
+
const hostSetImmediate = globalThis.setImmediate;
|
|
1088
|
+
const inWorkerd = globalThis.navigator?.userAgent === "Cloudflare-Workers" || typeof globalThis.WebSocketPair === "function";
|
|
969
1089
|
/**
|
|
970
|
-
*
|
|
971
|
-
* one
|
|
972
|
-
*
|
|
1090
|
+
* A turn of the real event loop without a timer's delay, where the host
|
|
1091
|
+
* gives one cheaply: Node's `setImmediate` (microseconds), after which every
|
|
1092
|
+
* pending microtask has run and I/O callbacks that were due have been
|
|
1093
|
+
* delivered. Null in workerd, which has `setImmediate` too but runs it as a
|
|
1094
|
+
* timer, about a millisecond like `setTimeout(0)`, and where nothing else
|
|
1095
|
+
* reaches the event loop (streams, bodies, message ports, crypto and the
|
|
1096
|
+
* cache all resolve without a turn of it), so a zero timer is the turn.
|
|
1097
|
+
* Measured in the Cloudflare Vitest pool (workerd 1.2026-10, 2026-10-30),
|
|
1098
|
+
* not documented: a workerd whose `setImmediate` became cheap would only
|
|
1099
|
+
* run slower here, never wrong.
|
|
973
1100
|
*/
|
|
974
|
-
|
|
975
|
-
|
|
1101
|
+
const cheapEventLoopTurn = hostSetImmediate && !inWorkerd ? () => new Promise((resolve) => hostSetImmediate.call(globalThis, () => resolve())) : null;
|
|
1102
|
+
/** One turn of the real event loop: the cheap one where the host has it, else a zero timer. */
|
|
1103
|
+
function eventLoopTurn() {
|
|
1104
|
+
return cheapEventLoopTurn ? cheapEventLoopTurn() : realTick();
|
|
976
1105
|
}
|
|
977
1106
|
/**
|
|
978
1107
|
* Wait for a promise under the virtual clock: while it is pending, let real
|
|
@@ -1004,152 +1133,19 @@ async function settleOn(promise, ctx) {
|
|
|
1004
1133
|
return new Promise(() => {});
|
|
1005
1134
|
}
|
|
1006
1135
|
}
|
|
1007
|
-
// packages/engine/src/
|
|
1008
|
-
/** Whether two turns commute: different invocations, effects on different targets. */
|
|
1009
|
-
function independent(a, b) {
|
|
1010
|
-
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;
|
|
1011
|
-
}
|
|
1012
|
-
const asleep = /* @__PURE__ */ new Map();
|
|
1013
|
-
var Enumerator = class {
|
|
1014
|
-
stack = [];
|
|
1015
|
-
depth = 0;
|
|
1016
|
-
/** The depth of the first node in the run just made whose every option was asleep, or null. */
|
|
1017
|
-
blockedAt = null;
|
|
1018
|
-
mismatchReason = null;
|
|
1019
|
-
reduction;
|
|
1020
|
-
constructor(options) {
|
|
1021
|
-
this.reduction = options.reduction;
|
|
1022
|
-
}
|
|
1023
|
-
/** Whether the run just made repeats an explored order (every option at some point was asleep). */
|
|
1024
|
-
get blocked() {
|
|
1025
|
-
return this.blockedAt !== null;
|
|
1026
|
-
}
|
|
1027
|
-
/** Set when a run made different choices than the same prefix did before: not deterministic. */
|
|
1028
|
-
get mismatch() {
|
|
1029
|
-
return this.mismatchReason;
|
|
1030
|
-
}
|
|
1031
|
-
/** The chooser for the next run: the explored prefix, then the first option not asleep. */
|
|
1032
|
-
next() {
|
|
1033
|
-
this.depth = 0;
|
|
1034
|
-
this.blockedAt = null;
|
|
1035
|
-
return { choose: (kind, options) => this.choose(kind, options) };
|
|
1036
|
-
}
|
|
1037
|
-
choose(kind, options) {
|
|
1038
|
-
const i = this.depth++;
|
|
1039
|
-
const known = this.stack[i];
|
|
1040
|
-
if (known) {
|
|
1041
|
-
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(", ")})`;
|
|
1042
|
-
return known.picked < options.length ? known.picked : 0;
|
|
1043
|
-
}
|
|
1044
|
-
if (this.blockedAt !== null) return 0;
|
|
1045
|
-
const sleep = this.sleepAt(i);
|
|
1046
|
-
let picked = kind === "turn" ? options.findIndex((o) => !sleep.has(o.label)) : 0;
|
|
1047
|
-
if (picked < 0) {
|
|
1048
|
-
this.blockedAt = i;
|
|
1049
|
-
picked = 0;
|
|
1050
|
-
}
|
|
1051
|
-
this.stack.push({
|
|
1052
|
-
kind,
|
|
1053
|
-
options,
|
|
1054
|
-
picked,
|
|
1055
|
-
done: [],
|
|
1056
|
-
sleep
|
|
1057
|
-
});
|
|
1058
|
-
return picked;
|
|
1059
|
-
}
|
|
1060
|
-
/** The sleep set of a new node at depth i, from its parent's. */
|
|
1061
|
-
sleepAt(i) {
|
|
1062
|
-
const parent = this.stack[i - 1];
|
|
1063
|
-
if (!this.reduction || !parent) return asleep;
|
|
1064
|
-
if (parent.kind === "fault") return parent.sleep;
|
|
1065
|
-
const taken = parent.options[parent.picked];
|
|
1066
|
-
if (!taken) return asleep;
|
|
1067
|
-
const sleep = /* @__PURE__ */ new Map();
|
|
1068
|
-
const candidates = [...parent.sleep.values(), ...parent.done.map((j) => parent.options[j])];
|
|
1069
|
-
for (const c of candidates) if (c && independent(c, taken)) sleep.set(c.label, c);
|
|
1070
|
-
return sleep;
|
|
1071
|
-
}
|
|
1072
|
-
/** Move to the next schedule after a run. False once every schedule has been explored. */
|
|
1073
|
-
advance() {
|
|
1074
|
-
this.stack.length = Math.min(this.stack.length, this.depth, (this.blockedAt ?? Infinity) + 1);
|
|
1075
|
-
while (this.stack.length > 0) {
|
|
1076
|
-
const node = this.stack[this.stack.length - 1];
|
|
1077
|
-
if (!node.done.includes(node.picked)) node.done.push(node.picked);
|
|
1078
|
-
const next = node.options.findIndex((o, j) => !node.done.includes(j) && (node.kind === "fault" || !node.sleep.has(o.label)));
|
|
1079
|
-
if (next >= 0) {
|
|
1080
|
-
node.picked = next;
|
|
1081
|
-
return true;
|
|
1082
|
-
}
|
|
1083
|
-
this.stack.pop();
|
|
1084
|
-
}
|
|
1085
|
-
return false;
|
|
1086
|
-
}
|
|
1087
|
-
};
|
|
1136
|
+
// packages/engine/src/fetch.ts
|
|
1088
1137
|
/**
|
|
1089
|
-
*
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1138
|
+
* Scripted outbound fetch. During a run, `fetch` is replaced by a function
|
|
1139
|
+
* that answers from the scenario's declared externals instead of the
|
|
1140
|
+
* network. Each request is an effect point (with every fault available) when
|
|
1141
|
+
* run hooks are given; without hooks it is the same scripted behaviour with
|
|
1142
|
+
* no recording, which the differential's raw side uses.
|
|
1143
|
+
*
|
|
1144
|
+
* An external that declares `dedupeBy` remembers the first response per key
|
|
1145
|
+
* for the run: a repeated key gets that response back and is recorded as
|
|
1146
|
+
* not effective. A request to an undeclared host, or one no scripted
|
|
1147
|
+
* response answers, makes the run unsupported.
|
|
1092
1148
|
*/
|
|
1093
|
-
var ExhaustiveDriver = class {
|
|
1094
|
-
reduction;
|
|
1095
|
-
enumerator;
|
|
1096
|
-
schedules = 0;
|
|
1097
|
-
more = true;
|
|
1098
|
-
restart = false;
|
|
1099
|
-
constructor(reduction) {
|
|
1100
|
-
this.reduction = reduction;
|
|
1101
|
-
this.enumerator = new Enumerator({ reduction });
|
|
1102
|
-
}
|
|
1103
|
-
/** Whether schedules are left to run. */
|
|
1104
|
-
get hasMore() {
|
|
1105
|
-
return this.more;
|
|
1106
|
-
}
|
|
1107
|
-
/** See `Enumerator.mismatch`. */
|
|
1108
|
-
get mismatch() {
|
|
1109
|
-
return this.enumerator.mismatch;
|
|
1110
|
-
}
|
|
1111
|
-
/** The chooser for the next run. */
|
|
1112
|
-
next() {
|
|
1113
|
-
return this.enumerator.next();
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* Account for the run just made. False when it only repeated an order the
|
|
1117
|
-
* reduction had covered: it is not a new schedule and its checks repeat
|
|
1118
|
-
* others'. A run that shows its turns may not commute counts and is
|
|
1119
|
-
* checked, and `checked` then starts again over every order.
|
|
1120
|
-
*/
|
|
1121
|
-
ran(turnsMayNotCommute) {
|
|
1122
|
-
this.restart = this.reduction && turnsMayNotCommute();
|
|
1123
|
-
if (!this.restart) {
|
|
1124
|
-
this.more = this.enumerator.advance();
|
|
1125
|
-
if (this.enumerator.blocked) return false;
|
|
1126
|
-
}
|
|
1127
|
-
this.schedules++;
|
|
1128
|
-
return true;
|
|
1129
|
-
}
|
|
1130
|
-
/** The run's checks passed: if it turned the reduction off, every order from the start. */
|
|
1131
|
-
checked() {
|
|
1132
|
-
if (!this.restart) return;
|
|
1133
|
-
this.reduction = false;
|
|
1134
|
-
this.enumerator = new Enumerator({ reduction: false });
|
|
1135
|
-
this.schedules = 0;
|
|
1136
|
-
}
|
|
1137
|
-
/** What the verdict reports (see `BoundsReached.exhaustive`). */
|
|
1138
|
-
get reached() {
|
|
1139
|
-
return {
|
|
1140
|
-
complete: !this.more,
|
|
1141
|
-
schedules: this.schedules,
|
|
1142
|
-
reduction: this.reduction
|
|
1143
|
-
};
|
|
1144
|
-
}
|
|
1145
|
-
};
|
|
1146
|
-
// packages/engine/src/fetch.ts
|
|
1147
|
-
const FAULTS = [
|
|
1148
|
-
"crash_before",
|
|
1149
|
-
"crash_after",
|
|
1150
|
-
"ambiguous",
|
|
1151
|
-
"error"
|
|
1152
|
-
];
|
|
1153
1149
|
/** Match a host against an exact host or a "*.suffix" pattern. */
|
|
1154
1150
|
function hostMatches(pattern, host) {
|
|
1155
1151
|
if (pattern.startsWith("*.")) {
|
|
@@ -1176,6 +1172,11 @@ const REDIRECTS = /* @__PURE__ */ new Set([
|
|
|
1176
1172
|
307,
|
|
1177
1173
|
308
|
|
1178
1174
|
]);
|
|
1175
|
+
/** Whether a status is a redirect `fetch` would follow unless told `redirect: "manual"`. */
|
|
1176
|
+
function isRedirect(status) {
|
|
1177
|
+
return REDIRECTS.has(status);
|
|
1178
|
+
}
|
|
1179
|
+
/** The reply a scripted response stands for; `null` is the default reply, 200 with an empty body. */
|
|
1179
1180
|
function replyOf(r) {
|
|
1180
1181
|
if (r === null) return {
|
|
1181
1182
|
status: 200,
|
|
@@ -1199,6 +1200,7 @@ function toResponse(reply) {
|
|
|
1199
1200
|
headers: reply.headers
|
|
1200
1201
|
});
|
|
1201
1202
|
}
|
|
1203
|
+
/** A request or reply body as effect-log data: JSON when it parses, the text otherwise, null when empty. */
|
|
1202
1204
|
function parseBody(text) {
|
|
1203
1205
|
if (text === "") return null;
|
|
1204
1206
|
try {
|
|
@@ -1252,7 +1254,7 @@ function createScriptedFetch(externals, hooks, unsupported, afterRequest = () =>
|
|
|
1252
1254
|
throw new TypeError(`fetch failed: no scripted response for ${method} ${url.pathname}`);
|
|
1253
1255
|
}
|
|
1254
1256
|
const reply = replyOf(script);
|
|
1255
|
-
if (
|
|
1257
|
+
if (isRedirect(reply.status) && request.redirect !== "manual") {
|
|
1256
1258
|
unsupported(`external ${external.name} answers ${method} ${url.pathname} with a ${reply.status} redirect; script the final reply or fetch with redirect: "manual"`);
|
|
1257
1259
|
throw new TypeError(`fetch failed: redirects are not modelled (${reply.status} from ${url.host})`);
|
|
1258
1260
|
}
|
|
@@ -1272,7 +1274,7 @@ function createScriptedFetch(externals, hooks, unsupported, afterRequest = () =>
|
|
|
1272
1274
|
target: `Fetch:${external.name}`,
|
|
1273
1275
|
op: method,
|
|
1274
1276
|
args,
|
|
1275
|
-
allowed:
|
|
1277
|
+
allowed: writeFaults
|
|
1276
1278
|
}, perform, (r) => ({
|
|
1277
1279
|
status: r.reply.status,
|
|
1278
1280
|
effective: r.effective,
|
|
@@ -1439,17 +1441,8 @@ var Frames = class {
|
|
|
1439
1441
|
}
|
|
1440
1442
|
};
|
|
1441
1443
|
// packages/engine/src/turns.ts
|
|
1442
|
-
/**
|
|
1443
|
-
* The concurrent scheduler. Each asynchronous effect of a concurrent run is
|
|
1444
|
-
* a turn: the invocation parks there, and once every invocation has parked,
|
|
1445
|
-
* finished or gone idle the run picks which parked one goes next (or whether
|
|
1446
|
-
* a new event starts): from the recorded turns when replaying them, from the
|
|
1447
|
-
* chooser when exploring exhaustively, else from a stream seeded by the
|
|
1448
|
-
* schedule's seed. It also tracks whether turns told apart by their parked
|
|
1449
|
-
* effects' targets may not commute, which partial-order reduction needs.
|
|
1450
|
-
*/
|
|
1451
1444
|
var Turns = class {
|
|
1452
|
-
|
|
1445
|
+
chooser;
|
|
1453
1446
|
frames;
|
|
1454
1447
|
/** Makes an invocation the running one. */
|
|
1455
1448
|
runAs;
|
|
@@ -1460,25 +1453,26 @@ var Turns = class {
|
|
|
1460
1453
|
parkSeq = 0;
|
|
1461
1454
|
/** The turns picked at decisions with more than one option, in order (see Schedule.turns). */
|
|
1462
1455
|
picked = [];
|
|
1463
|
-
/** Turns taken from `schedule.turns` so far, when replaying recorded turns. */
|
|
1464
|
-
replayed = 0;
|
|
1465
1456
|
/** Events started so far, to name the next start the same in every run. */
|
|
1466
1457
|
starts = 0;
|
|
1467
1458
|
/** The target of the turn running since the last decision; null for an event's start or none. */
|
|
1468
1459
|
turnTarget = null;
|
|
1469
1460
|
commuteNot = false;
|
|
1470
|
-
/** Woken whenever an invocation parks, a delivery ends or I/O completes. */
|
|
1461
|
+
/** Woken whenever an invocation parks, a delivery ends or I/O completes (see `progressed`). */
|
|
1471
1462
|
progressWaiters = [];
|
|
1463
|
+
/** Times something moved, hosted code's moves included, and the count the last wait or step saw. */
|
|
1464
|
+
moves = 0;
|
|
1465
|
+
seenMoves = 0;
|
|
1466
|
+
/** Parks and delivery ends so far, and the count when the current step began. */
|
|
1467
|
+
rests = 0;
|
|
1468
|
+
restsAtStep = 0;
|
|
1472
1469
|
/** The order invocations started in, which orders the parked ones. */
|
|
1473
1470
|
startOrder = /* @__PURE__ */ new Map();
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
constructor(options, frames, runAs, reads) {
|
|
1477
|
-
this.options = options;
|
|
1471
|
+
constructor(chooser, frames, runAs, reads) {
|
|
1472
|
+
this.chooser = chooser;
|
|
1478
1473
|
this.frames = frames;
|
|
1479
1474
|
this.runAs = runAs;
|
|
1480
1475
|
this.reads = reads;
|
|
1481
|
-
this.prng = seedPrng(`turns:${options.schedule.seed}`);
|
|
1482
1476
|
}
|
|
1483
1477
|
/** The turns picked so far, as a copy. */
|
|
1484
1478
|
get picks() {
|
|
@@ -1502,8 +1496,22 @@ var Turns = class {
|
|
|
1502
1496
|
option,
|
|
1503
1497
|
...host ? { host } : {}
|
|
1504
1498
|
});
|
|
1499
|
+
this.rested();
|
|
1500
|
+
}
|
|
1501
|
+
/** See `Run.rested`. */
|
|
1502
|
+
rested() {
|
|
1503
|
+
this.rests++;
|
|
1505
1504
|
this.progressed();
|
|
1506
1505
|
}
|
|
1506
|
+
/**
|
|
1507
|
+
* A step begins: a turn is released, an event starts or a timer fires.
|
|
1508
|
+
* `quiesce` then waits for what the step set off to come to rest. Called
|
|
1509
|
+
* by `takeTurn` and, for timers, by the run.
|
|
1510
|
+
*/
|
|
1511
|
+
step() {
|
|
1512
|
+
this.restsAtStep = this.rests;
|
|
1513
|
+
this.seenMoves = this.moves;
|
|
1514
|
+
}
|
|
1507
1515
|
/** See `Run.turnsMayNotCommute`. */
|
|
1508
1516
|
get mayNotCommute() {
|
|
1509
1517
|
this.endSegment();
|
|
@@ -1526,6 +1534,7 @@ var Turns = class {
|
|
|
1526
1534
|
}
|
|
1527
1535
|
/** See `Run.progressed`. */
|
|
1528
1536
|
progressed() {
|
|
1537
|
+
this.moves++;
|
|
1529
1538
|
if (this.frames.hostingNow > 0) return;
|
|
1530
1539
|
const waiters = this.progressWaiters;
|
|
1531
1540
|
this.progressWaiters = [];
|
|
@@ -1534,10 +1543,40 @@ var Turns = class {
|
|
|
1534
1543
|
/** See `Run.quiesce`. */
|
|
1535
1544
|
async quiesce() {
|
|
1536
1545
|
for (;;) {
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
if (this.
|
|
1546
|
+
const moved = await this.wait();
|
|
1547
|
+
if (this.frames.inFlight > 0) continue;
|
|
1548
|
+
if (this.rests !== this.restsAtStep) return;
|
|
1549
|
+
if (!moved) return;
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Wait for a move (see `progressed`) or one real zero timer, whichever
|
|
1554
|
+
* comes first (no wait when something moved since the last one), then
|
|
1555
|
+
* let everything the move set off run before the caller looks: one turn
|
|
1556
|
+
* of the event loop, the cheap one where the host has it, else the timer
|
|
1557
|
+
* armed for the wait, after which the microtask queue is empty too.
|
|
1558
|
+
* Returns whether anything moved since the last wait.
|
|
1559
|
+
*/
|
|
1560
|
+
async wait() {
|
|
1561
|
+
const before = this.seenMoves;
|
|
1562
|
+
const racing = this.moves === before;
|
|
1563
|
+
const tick = racing || !cheapEventLoopTurn ? realDeadline(0) : void 0;
|
|
1564
|
+
if (racing && tick) {
|
|
1565
|
+
let wake = () => {};
|
|
1566
|
+
const woken = new Promise((resolve) => {
|
|
1567
|
+
wake = resolve;
|
|
1568
|
+
});
|
|
1569
|
+
this.progressWaiters.push(wake);
|
|
1570
|
+
await Promise.race([woken, tick.expired]);
|
|
1571
|
+
const i = this.progressWaiters.indexOf(wake);
|
|
1572
|
+
if (i >= 0) this.progressWaiters.splice(i, 1);
|
|
1540
1573
|
}
|
|
1574
|
+
if (cheapEventLoopTurn) {
|
|
1575
|
+
tick?.cancel();
|
|
1576
|
+
await cheapEventLoopTurn();
|
|
1577
|
+
} else await tick?.expired;
|
|
1578
|
+
this.seenMoves = this.moves;
|
|
1579
|
+
return this.moves !== before;
|
|
1541
1580
|
}
|
|
1542
1581
|
/** See `Run.takeTurn`. */
|
|
1543
1582
|
takeTurn(canStart) {
|
|
@@ -1546,12 +1585,11 @@ var Turns = class {
|
|
|
1546
1585
|
const options = this.parked.length + (canStart ? 1 : 0);
|
|
1547
1586
|
this.endSegment();
|
|
1548
1587
|
this.turnTarget = null;
|
|
1588
|
+
this.step();
|
|
1549
1589
|
if (options === 0) return "none";
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
this.picked.push(pick);
|
|
1554
|
-
} else if (this.options.chooser && this.options.mode === "explore") this.options.chooser.choose("turn", this.turnOptions(canStart));
|
|
1590
|
+
const answer = this.chooser.choose("turn", this.turnOptions(canStart));
|
|
1591
|
+
const pick = answer < options ? answer : 0;
|
|
1592
|
+
if (options > 1) this.picked.push(pick);
|
|
1555
1593
|
const [chosen] = pick < this.parked.length ? this.parked.splice(pick, 1) : [];
|
|
1556
1594
|
if (!chosen) {
|
|
1557
1595
|
this.starts++;
|
|
@@ -1568,25 +1606,12 @@ var Turns = class {
|
|
|
1568
1606
|
turnOptions(canStart) {
|
|
1569
1607
|
return [...this.parked.map((p) => p.option), ...canStart ? [{ label: `start:${this.starts}` }] : []];
|
|
1570
1608
|
}
|
|
1571
|
-
/** The turn at a decision with more than one option: recorded, chosen, or drawn from the seed. */
|
|
1572
|
-
pickTurn(options, canStart) {
|
|
1573
|
-
const recorded = this.options.schedule.turns;
|
|
1574
|
-
if (this.options.mode === "replay" && recorded) {
|
|
1575
|
-
const i = recorded[this.replayed++] ?? 0;
|
|
1576
|
-
return i < options ? i : 0;
|
|
1577
|
-
}
|
|
1578
|
-
const chooser = this.options.chooser;
|
|
1579
|
-
if (chooser && this.options.mode === "explore") return chooser.choose("turn", this.turnOptions(canStart));
|
|
1580
|
-
const [i, next] = nextInt(this.prng, options);
|
|
1581
|
-
this.prng = next;
|
|
1582
|
-
return i;
|
|
1583
|
-
}
|
|
1584
1609
|
};
|
|
1585
1610
|
// packages/engine/src/run.ts
|
|
1586
1611
|
/**
|
|
1587
1612
|
* One run of a scenario: the effect log being built, the fault decisions
|
|
1588
|
-
* (
|
|
1589
|
-
*
|
|
1613
|
+
* (made by the run's chooser, see `chooser.ts`), and the invocations in
|
|
1614
|
+
* flight. Proxies in the platform package call `effect`/`effectSync`
|
|
1590
1615
|
* around every real effect; everything else is engine-internal.
|
|
1591
1616
|
*
|
|
1592
1617
|
* With `maxConcurrentInvocations` above 1 the run is concurrent: several
|
|
@@ -1666,7 +1691,6 @@ var Run = class {
|
|
|
1666
1691
|
faults = [];
|
|
1667
1692
|
effectIndex = 0;
|
|
1668
1693
|
eligibleSeen = 0;
|
|
1669
|
-
prng;
|
|
1670
1694
|
invocations = /* @__PURE__ */ new Map();
|
|
1671
1695
|
reasons = [];
|
|
1672
1696
|
frames = new Frames();
|
|
@@ -1683,20 +1707,19 @@ var Run = class {
|
|
|
1683
1707
|
options;
|
|
1684
1708
|
constructor(options) {
|
|
1685
1709
|
this.options = options;
|
|
1686
|
-
this.
|
|
1687
|
-
this.turns = new Turns(options, this.frames, (id) => this.runAs(id), () => this.patched?.reads);
|
|
1710
|
+
this.turns = new Turns(options.chooser, this.frames, (id) => this.runAs(id), () => this.patched?.reads);
|
|
1688
1711
|
this.concurrent = options.bounds.maxConcurrentInvocations > 1;
|
|
1689
1712
|
}
|
|
1690
1713
|
get log() {
|
|
1691
1714
|
return this.logState;
|
|
1692
1715
|
}
|
|
1693
|
-
/** The schedule as actually executed:
|
|
1716
|
+
/** The schedule as actually executed: the faults taken and, when they do not follow the seed, the turns. */
|
|
1694
1717
|
get schedule() {
|
|
1695
|
-
const
|
|
1718
|
+
const { seed, recordsTurns } = this.options.chooser;
|
|
1696
1719
|
return {
|
|
1697
|
-
seed
|
|
1720
|
+
seed,
|
|
1698
1721
|
faults: [...this.faults],
|
|
1699
|
-
...
|
|
1722
|
+
...recordsTurns ? { turns: [...this.turns.picks] } : {}
|
|
1700
1723
|
};
|
|
1701
1724
|
}
|
|
1702
1725
|
get effectPoints() {
|
|
@@ -1731,7 +1754,7 @@ var Run = class {
|
|
|
1731
1754
|
install(externals = []) {
|
|
1732
1755
|
installed = this;
|
|
1733
1756
|
if (!this.patched) {
|
|
1734
|
-
this.patched = patchGlobals(this.options.
|
|
1757
|
+
this.patched = patchGlobals(this.options.chooser.seed, { trackIo: (work) => {
|
|
1735
1758
|
this.frames.inFlight++;
|
|
1736
1759
|
return work.finally(() => {
|
|
1737
1760
|
this.frames.inFlight--;
|
|
@@ -1817,36 +1840,26 @@ var Run = class {
|
|
|
1817
1840
|
if (!inv) throw new Error(`effect from unknown invocation ${id}`);
|
|
1818
1841
|
return inv;
|
|
1819
1842
|
}
|
|
1820
|
-
/** Effect points so far that could take a fault (
|
|
1843
|
+
/** Effect points so far that could take a fault (the positions a seeded chooser's plan counts). */
|
|
1821
1844
|
get eligiblePoints() {
|
|
1822
1845
|
return this.eligibleSeen;
|
|
1823
1846
|
}
|
|
1847
|
+
/** The fault at an eligible point, if any: the chooser's pick among none and the allowed kinds. */
|
|
1824
1848
|
decide(point, ordinal) {
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
}
|
|
1840
|
-
if (this.options.mode === "replay") {
|
|
1841
|
-
const d = this.options.schedule.faults.find((f) => f.invocation === point.invocation && f.ordinal === ordinal);
|
|
1842
|
-
return d && point.allowed.includes(d.fault) ? d.fault : null;
|
|
1843
|
-
}
|
|
1844
|
-
const [fault, next] = decideFault(this.prng, point.allowed, this.faults.length, {
|
|
1845
|
-
maxFaultsPerRun: this.options.bounds.maxFaultsPerRun,
|
|
1846
|
-
faultProbability: this.options.faultProbability
|
|
1847
|
-
});
|
|
1848
|
-
this.prng = next;
|
|
1849
|
-
return fault;
|
|
1849
|
+
if (point.allowed.length === 0) return null;
|
|
1850
|
+
this.eligibleSeen++;
|
|
1851
|
+
const at = {
|
|
1852
|
+
invocation: point.invocation,
|
|
1853
|
+
ordinal
|
|
1854
|
+
};
|
|
1855
|
+
const i = this.options.chooser.choose("fault", [{
|
|
1856
|
+
label: "none",
|
|
1857
|
+
...at
|
|
1858
|
+
}, ...point.allowed.map((fault) => ({
|
|
1859
|
+
label: fault,
|
|
1860
|
+
...at
|
|
1861
|
+
}))]);
|
|
1862
|
+
return i === 0 ? null : point.allowed[i - 1] ?? null;
|
|
1850
1863
|
}
|
|
1851
1864
|
record(point, kind, payload) {
|
|
1852
1865
|
if (kind === "result") this.turns.performed(point.target);
|
|
@@ -2076,16 +2089,24 @@ var Run = class {
|
|
|
2076
2089
|
invocation: () => cell.id
|
|
2077
2090
|
};
|
|
2078
2091
|
}
|
|
2079
|
-
/** Concurrent runs: something moved (
|
|
2092
|
+
/** Concurrent runs: something moved (I/O completed, an event was queued). */
|
|
2080
2093
|
progressed() {
|
|
2081
2094
|
this.turns.progressed();
|
|
2082
2095
|
}
|
|
2096
|
+
/** Concurrent runs: a delivery ended. */
|
|
2097
|
+
rested() {
|
|
2098
|
+
this.turns.rested();
|
|
2099
|
+
}
|
|
2083
2100
|
/**
|
|
2084
|
-
* Concurrent runs: wait until the
|
|
2085
|
-
*
|
|
2086
|
-
*
|
|
2087
|
-
*
|
|
2088
|
-
*
|
|
2101
|
+
* Concurrent runs: wait until what the last step set off (a turn
|
|
2102
|
+
* released, an event started, a timer fired) has parked, finished or
|
|
2103
|
+
* gone idle. Parking, a delivery ending and I/O completing wake the wait
|
|
2104
|
+
* at once, except while a Durable Object's code runs, which cannot wake
|
|
2105
|
+
* it (the wait's zero timer polls then); every continuation they set off
|
|
2106
|
+
* runs before it returns (one turn of the event loop), so code another
|
|
2107
|
+
* invocation's promise resumed reaches its own effect too. Code waiting
|
|
2108
|
+
* on anything else gets one such turn, the same allowance the sequential
|
|
2109
|
+
* path gives, before it counts as idle.
|
|
2089
2110
|
*/
|
|
2090
2111
|
quiesce() {
|
|
2091
2112
|
return this.turns.quiesce();
|
|
@@ -2102,19 +2123,21 @@ var Run = class {
|
|
|
2102
2123
|
/**
|
|
2103
2124
|
* Let virtual time pass until `at`: timers due by then fire first, in due
|
|
2104
2125
|
* order, as the invocations that set them, each followed by the work it
|
|
2105
|
-
* sets off. No-op when `at` is not ahead.
|
|
2126
|
+
* sets off. No-op when `at` is not ahead. Returns whether a timer fired.
|
|
2106
2127
|
*/
|
|
2107
2128
|
async advanceTo(at) {
|
|
2108
2129
|
const clock = this.patched?.clock;
|
|
2109
|
-
if (!clock) return;
|
|
2130
|
+
if (!clock) return false;
|
|
2131
|
+
let fired = false;
|
|
2110
2132
|
for (let due = clock.nextDue(); due !== void 0 && due <= at; due = clock.nextDue()) {
|
|
2111
|
-
this.
|
|
2112
|
-
|
|
2133
|
+
this.fireNextTimer(clock);
|
|
2134
|
+
fired = true;
|
|
2113
2135
|
do
|
|
2114
|
-
await
|
|
2136
|
+
await eventLoopTurn();
|
|
2115
2137
|
while (this.frames.inFlight > 0);
|
|
2116
2138
|
}
|
|
2117
2139
|
clock.advance(at - clock.now());
|
|
2140
|
+
return fired;
|
|
2118
2141
|
}
|
|
2119
2142
|
/** When the next virtual timer is due, or undefined when none is pending. */
|
|
2120
2143
|
nextTimerDue() {
|
|
@@ -2123,10 +2146,13 @@ var Run = class {
|
|
|
2123
2146
|
/** Concurrent runs: fire the next due timer as the invocation that set it. False when none is pending. */
|
|
2124
2147
|
fireTimer() {
|
|
2125
2148
|
const clock = this.patched?.clock;
|
|
2126
|
-
if (!clock) return false;
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2149
|
+
if (!clock || clock.nextOwner() === void 0) return false;
|
|
2150
|
+
return this.fireNextTimer(clock);
|
|
2151
|
+
}
|
|
2152
|
+
/** Fire the next due timer as the invocation that set it (a step of a concurrent run). */
|
|
2153
|
+
fireNextTimer(clock) {
|
|
2154
|
+
this.runAs(clock.nextOwner() ?? null);
|
|
2155
|
+
if (this.concurrent) this.turns.step();
|
|
2130
2156
|
return clock.fireNext();
|
|
2131
2157
|
}
|
|
2132
2158
|
/**
|
|
@@ -2164,6 +2190,190 @@ var Run = class {
|
|
|
2164
2190
|
});
|
|
2165
2191
|
}
|
|
2166
2192
|
};
|
|
2193
|
+
// packages/engine/src/deliver.ts
|
|
2194
|
+
/**
|
|
2195
|
+
* Run user code as an invocation: under `RunHooks.settle` (real I/O
|
|
2196
|
+
* completes, timers fire while it is idle) and ended as "crashed" when an
|
|
2197
|
+
* injected fault crashes the invocation, whether the code saw the crash as
|
|
2198
|
+
* a `CrashSignal` or an effect of its hung, as "errored" when it threw
|
|
2199
|
+
* anything else.
|
|
2200
|
+
*/
|
|
2201
|
+
async function runInvocation(hooks, inv, work) {
|
|
2202
|
+
const outcome = Promise.resolve().then(work).then((value) => ({
|
|
2203
|
+
status: "completed",
|
|
2204
|
+
value
|
|
2205
|
+
}), (error) => error instanceof CrashSignal ? { status: "crashed" } : {
|
|
2206
|
+
status: "errored",
|
|
2207
|
+
error
|
|
2208
|
+
});
|
|
2209
|
+
return Promise.race([hooks.settle(outcome, inv.id), inv.crashed.then(() => ({ status: "crashed" }))]);
|
|
2210
|
+
}
|
|
2211
|
+
// packages/engine/src/exhaustive.ts
|
|
2212
|
+
/**
|
|
2213
|
+
* Exhaustive exploration: every schedule within the bounds, each once. A
|
|
2214
|
+
* schedule is the sequence of choices a run makes: a fault or none at each
|
|
2215
|
+
* effect point that may still take one, and the next turn at each decision
|
|
2216
|
+
* of a concurrent run. Runs are deterministic, so forcing a prefix of
|
|
2217
|
+
* choices reproduces the run up to there; the enumerator walks the tree of
|
|
2218
|
+
* choice sequences depth first, one run per leaf, without saving state
|
|
2219
|
+
* (each run starts from the scenario's reset).
|
|
2220
|
+
*
|
|
2221
|
+
* Reduction, when on, uses sleep sets (Godefroid, Partial-Order Methods for
|
|
2222
|
+
* the Verification of Concurrent Systems, 1996): two turns of different
|
|
2223
|
+
* invocations whose effects have different targets commute, so after one
|
|
2224
|
+
* order of them has been explored the other is not. Starting an event is
|
|
2225
|
+
* dependent on everything. A run whose every option is asleep repeats an
|
|
2226
|
+
* explored order; it still runs (the choices are forced up to it) but is not
|
|
2227
|
+
* counted as a schedule and nothing below it is explored.
|
|
2228
|
+
*/
|
|
2229
|
+
/** Whether two turns commute: different invocations, effects on different targets. */
|
|
2230
|
+
function independent(a, b) {
|
|
2231
|
+
return a.invocation !== void 0 && b.invocation !== void 0 && a.invocation !== b.invocation && a.target !== void 0 && b.target !== void 0 && a.target !== b.target;
|
|
2232
|
+
}
|
|
2233
|
+
const asleep = /* @__PURE__ */ new Map();
|
|
2234
|
+
var Enumerator = class {
|
|
2235
|
+
stack = [];
|
|
2236
|
+
depth = 0;
|
|
2237
|
+
/** The depth of the first node in the run just made whose every option was asleep, or null. */
|
|
2238
|
+
blockedAt = null;
|
|
2239
|
+
mismatchReason = null;
|
|
2240
|
+
reduction;
|
|
2241
|
+
constructor(options) {
|
|
2242
|
+
this.reduction = options.reduction;
|
|
2243
|
+
}
|
|
2244
|
+
/** Whether the run just made repeats an explored order (every option at some point was asleep). */
|
|
2245
|
+
get blocked() {
|
|
2246
|
+
return this.blockedAt !== null;
|
|
2247
|
+
}
|
|
2248
|
+
/** Set when a run made different choices than the same prefix did before: not deterministic. */
|
|
2249
|
+
get mismatch() {
|
|
2250
|
+
return this.mismatchReason;
|
|
2251
|
+
}
|
|
2252
|
+
/**
|
|
2253
|
+
* The chooser for the next run: the explored prefix, then the first option
|
|
2254
|
+
* not asleep. Enumerated runs pick their choices and share one seed for
|
|
2255
|
+
* the virtual globals; their turns are recorded, since they do not follow it.
|
|
2256
|
+
*/
|
|
2257
|
+
next() {
|
|
2258
|
+
this.depth = 0;
|
|
2259
|
+
this.blockedAt = null;
|
|
2260
|
+
return {
|
|
2261
|
+
seed: 0,
|
|
2262
|
+
recordsTurns: true,
|
|
2263
|
+
choose: (kind, options) => this.choose(kind, options)
|
|
2264
|
+
};
|
|
2265
|
+
}
|
|
2266
|
+
choose(kind, options) {
|
|
2267
|
+
const i = this.depth++;
|
|
2268
|
+
const known = this.stack[i];
|
|
2269
|
+
if (known) {
|
|
2270
|
+
if (!(known.kind === kind && known.options.length === options.length && known.options.every((o, j) => o.label === options[j]?.label)) && this.mismatchReason === null) this.mismatchReason = `choice ${i} differed between runs with the same earlier choices (${known.options.map((o) => o.label).join(", ")} then ${options.map((o) => o.label).join(", ")})`;
|
|
2271
|
+
return known.picked < options.length ? known.picked : 0;
|
|
2272
|
+
}
|
|
2273
|
+
if (this.blockedAt !== null) return 0;
|
|
2274
|
+
const sleep = this.sleepAt(i);
|
|
2275
|
+
let picked = kind === "turn" ? options.findIndex((o) => !sleep.has(o.label)) : 0;
|
|
2276
|
+
if (picked < 0) {
|
|
2277
|
+
this.blockedAt = i;
|
|
2278
|
+
picked = 0;
|
|
2279
|
+
}
|
|
2280
|
+
this.stack.push({
|
|
2281
|
+
kind,
|
|
2282
|
+
options,
|
|
2283
|
+
picked,
|
|
2284
|
+
done: [],
|
|
2285
|
+
sleep
|
|
2286
|
+
});
|
|
2287
|
+
return picked;
|
|
2288
|
+
}
|
|
2289
|
+
/** The sleep set of a new node at depth i, from its parent's. */
|
|
2290
|
+
sleepAt(i) {
|
|
2291
|
+
const parent = this.stack[i - 1];
|
|
2292
|
+
if (!this.reduction || !parent) return asleep;
|
|
2293
|
+
if (parent.kind === "fault") return parent.sleep;
|
|
2294
|
+
const taken = parent.options[parent.picked];
|
|
2295
|
+
if (!taken) return asleep;
|
|
2296
|
+
const sleep = /* @__PURE__ */ new Map();
|
|
2297
|
+
const candidates = [...parent.sleep.values(), ...parent.done.map((j) => parent.options[j])];
|
|
2298
|
+
for (const c of candidates) if (c && independent(c, taken)) sleep.set(c.label, c);
|
|
2299
|
+
return sleep;
|
|
2300
|
+
}
|
|
2301
|
+
/** Move to the next schedule after a run. False once every schedule has been explored. */
|
|
2302
|
+
advance() {
|
|
2303
|
+
this.stack.length = Math.min(this.stack.length, this.depth, (this.blockedAt ?? Infinity) + 1);
|
|
2304
|
+
while (this.stack.length > 0) {
|
|
2305
|
+
const node = this.stack[this.stack.length - 1];
|
|
2306
|
+
if (!node.done.includes(node.picked)) node.done.push(node.picked);
|
|
2307
|
+
const next = node.options.findIndex((o, j) => !node.done.includes(j) && (node.kind === "fault" || !node.sleep.has(o.label)));
|
|
2308
|
+
if (next >= 0) {
|
|
2309
|
+
node.picked = next;
|
|
2310
|
+
return true;
|
|
2311
|
+
}
|
|
2312
|
+
this.stack.pop();
|
|
2313
|
+
}
|
|
2314
|
+
return false;
|
|
2315
|
+
}
|
|
2316
|
+
};
|
|
2317
|
+
/**
|
|
2318
|
+
* The exhaustive half of `explore`: the chooser for each run, what a run
|
|
2319
|
+
* counts for, and starting the enumeration again with the reduction off
|
|
2320
|
+
* once a run shows its turns may not commute.
|
|
2321
|
+
*/
|
|
2322
|
+
var ExhaustiveDriver = class {
|
|
2323
|
+
reduction;
|
|
2324
|
+
enumerator;
|
|
2325
|
+
maxFaultsPerRun;
|
|
2326
|
+
schedules = 0;
|
|
2327
|
+
more = true;
|
|
2328
|
+
restart = false;
|
|
2329
|
+
constructor(reduction, maxFaultsPerRun) {
|
|
2330
|
+
this.reduction = reduction;
|
|
2331
|
+
this.maxFaultsPerRun = maxFaultsPerRun;
|
|
2332
|
+
this.enumerator = new Enumerator({ reduction });
|
|
2333
|
+
}
|
|
2334
|
+
/** Whether schedules are left to run. */
|
|
2335
|
+
get hasMore() {
|
|
2336
|
+
return this.more;
|
|
2337
|
+
}
|
|
2338
|
+
/** See `Enumerator.mismatch`. */
|
|
2339
|
+
get mismatch() {
|
|
2340
|
+
return this.enumerator.mismatch;
|
|
2341
|
+
}
|
|
2342
|
+
/** The chooser for the next run, under the run's fault bound. */
|
|
2343
|
+
next() {
|
|
2344
|
+
return limitFaults(this.enumerator.next(), this.maxFaultsPerRun);
|
|
2345
|
+
}
|
|
2346
|
+
/**
|
|
2347
|
+
* Account for the run just made. False when it only repeated an order the
|
|
2348
|
+
* reduction had covered: it is not a new schedule and its checks repeat
|
|
2349
|
+
* others'. A run that shows its turns may not commute counts and is
|
|
2350
|
+
* checked, and `checked` then starts again over every order.
|
|
2351
|
+
*/
|
|
2352
|
+
ran(turnsMayNotCommute) {
|
|
2353
|
+
this.restart = this.reduction && turnsMayNotCommute();
|
|
2354
|
+
if (!this.restart) {
|
|
2355
|
+
this.more = this.enumerator.advance();
|
|
2356
|
+
if (this.enumerator.blocked) return false;
|
|
2357
|
+
}
|
|
2358
|
+
this.schedules++;
|
|
2359
|
+
return true;
|
|
2360
|
+
}
|
|
2361
|
+
/** The run's checks passed: if it turned the reduction off, every order from the start. */
|
|
2362
|
+
checked() {
|
|
2363
|
+
if (!this.restart) return;
|
|
2364
|
+
this.reduction = false;
|
|
2365
|
+
this.enumerator = new Enumerator({ reduction: false });
|
|
2366
|
+
this.schedules = 0;
|
|
2367
|
+
}
|
|
2368
|
+
/** What the verdict reports (see `BoundsReached.exhaustive`). */
|
|
2369
|
+
get reached() {
|
|
2370
|
+
return {
|
|
2371
|
+
complete: !this.more,
|
|
2372
|
+
schedules: this.schedules,
|
|
2373
|
+
reduction: this.reduction
|
|
2374
|
+
};
|
|
2375
|
+
}
|
|
2376
|
+
};
|
|
2167
2377
|
// packages/engine/src/shrink.ts
|
|
2168
2378
|
/**
|
|
2169
2379
|
* Shrinking, the loop: try the pure candidates in order, replay each, keep
|
|
@@ -2298,14 +2508,15 @@ async function deliverConcurrently(spec, platform, run) {
|
|
|
2298
2508
|
};
|
|
2299
2509
|
d.started.promise.then((result) => {
|
|
2300
2510
|
d.outcome = { result };
|
|
2301
|
-
run.
|
|
2511
|
+
run.rested();
|
|
2302
2512
|
}, (error) => {
|
|
2303
2513
|
d.outcome = { error };
|
|
2304
|
-
run.
|
|
2514
|
+
run.rested();
|
|
2305
2515
|
});
|
|
2306
2516
|
active.push(d);
|
|
2307
|
-
} else if (turn === "none" && next >= 0 && !due && active.length < spec.bounds.maxConcurrentInvocations && (run.nextTimerDue() ?? Number.POSITIVE_INFINITY) > (pending[next]?.at ?? 0))
|
|
2308
|
-
|
|
2517
|
+
} else if (turn === "none" && next >= 0 && !due && active.length < spec.bounds.maxConcurrentInvocations && (run.nextTimerDue() ?? Number.POSITIVE_INFINITY) > (pending[next]?.at ?? 0)) {
|
|
2518
|
+
if (!await run.advanceTo(pending[next]?.at ?? 0)) continue;
|
|
2519
|
+
} else if (turn === "none" && !run.fireTimer()) {
|
|
2309
2520
|
const stuck = active.flatMap((d) => d.started.invocation() ?? []);
|
|
2310
2521
|
if (run.abandon(stuck) === 0) throw new Error(`the ${platform.name} platform's delivery made no progress and cannot be abandoned`);
|
|
2311
2522
|
}
|
|
@@ -2333,10 +2544,8 @@ async function runOnce(spec, platform, run) {
|
|
|
2333
2544
|
/** Re-run a recorded schedule exactly and return the whole run (log and support status). */
|
|
2334
2545
|
async function replayRun(spec, platform, schedule) {
|
|
2335
2546
|
const run = new Run({
|
|
2336
|
-
mode: "replay",
|
|
2337
|
-
schedule,
|
|
2338
2547
|
bounds: spec.bounds,
|
|
2339
|
-
|
|
2548
|
+
chooser: replayChooser(schedule)
|
|
2340
2549
|
});
|
|
2341
2550
|
await runOnce(spec, platform, run);
|
|
2342
2551
|
return run;
|
|
@@ -2400,7 +2609,7 @@ async function explore(scenario, platform, options) {
|
|
|
2400
2609
|
/** Eligible points of a run without faults, and the most any run has had: seeded fault positions. */
|
|
2401
2610
|
let baseline = 0;
|
|
2402
2611
|
let longest = 0;
|
|
2403
|
-
const exhaustive = options.exhaustive ? new ExhaustiveDriver(typeof options.exhaustive === "object" ? options.exhaustive.reduction ?? true : true) : null;
|
|
2612
|
+
const exhaustive = options.exhaustive ? new ExhaustiveDriver(typeof options.exhaustive === "object" ? options.exhaustive.reduction ?? true : true, spec.bounds.maxFaultsPerRun) : null;
|
|
2404
2613
|
const doneNow = () => ({
|
|
2405
2614
|
...done(),
|
|
2406
2615
|
...exhaustive ? { exhaustive: exhaustive.reached } : {}
|
|
@@ -2411,14 +2620,12 @@ async function explore(scenario, platform, options) {
|
|
|
2411
2620
|
let faultPlan = [];
|
|
2412
2621
|
if (!exhaustive) [faultPlan, master] = planFaults(master, baseline, longest, spec.bounds.maxFaultsPerRun, faultProbability);
|
|
2413
2622
|
const run = new Run({
|
|
2414
|
-
mode: "explore",
|
|
2415
|
-
schedule: {
|
|
2416
|
-
seed: exhaustive ? 0 : runSeed,
|
|
2417
|
-
faults: []
|
|
2418
|
-
},
|
|
2419
2623
|
bounds: spec.bounds,
|
|
2420
|
-
|
|
2421
|
-
|
|
2624
|
+
chooser: exhaustive ? exhaustive.next() : seededChooser(runSeed, {
|
|
2625
|
+
faultPlan,
|
|
2626
|
+
faultProbability,
|
|
2627
|
+
maxFaultsPerRun: spec.bounds.maxFaultsPerRun
|
|
2628
|
+
})
|
|
2422
2629
|
});
|
|
2423
2630
|
const log = await runOnce(spec, platform, run);
|
|
2424
2631
|
reached.runs++;
|
|
@@ -2523,16 +2730,14 @@ var DifferentialStuck = class extends Error {
|
|
|
2523
2730
|
*/
|
|
2524
2731
|
async function proxiedSide(spec, platform, attempt) {
|
|
2525
2732
|
const run = new Run({
|
|
2526
|
-
mode: "replay",
|
|
2527
|
-
schedule: {
|
|
2528
|
-
seed: 0,
|
|
2529
|
-
faults: []
|
|
2530
|
-
},
|
|
2531
2733
|
bounds: {
|
|
2532
2734
|
...spec.bounds,
|
|
2533
2735
|
maxConcurrentInvocations: 1
|
|
2534
2736
|
},
|
|
2535
|
-
|
|
2737
|
+
chooser: replayChooser({
|
|
2738
|
+
seed: 0,
|
|
2739
|
+
faults: []
|
|
2740
|
+
})
|
|
2536
2741
|
});
|
|
2537
2742
|
const attempts = [];
|
|
2538
2743
|
const { finish, cleanup } = platform;
|
|
@@ -2650,6 +2855,6 @@ function observeCore(namespace, functions) {
|
|
|
2650
2855
|
}
|
|
2651
2856
|
};
|
|
2652
2857
|
}
|
|
2653
|
-
export {
|
|
2858
|
+
export { writeFaults as A, toJson as C, checkInvariants as D, checkInvariant as E, getPath as F, canonicalJson as I, nextInt as M, nextU32 as N, decisionFaults as O, seedPrng as P, patchProperty as S, validateScenario as T, withoutNetwork as _, explore as a, settleOn as b, runInvocation as c, findResponse as d, installScriptedFetch as f, toResponse as g, replyOf as h, proxiedSide as i, nextFloat as j, readFaults as k, CrashSignal as l, parseBody as m, DifferentialStuck as n, replay as o, isRedirect as p, compareSides as r, restrictSpec as s, observeCore as t, InjectedEffectError as u, patchGlobals as v, defaultBounds as w, virtualEpoch as x, realTick as y };
|
|
2654
2859
|
|
|
2655
|
-
//# sourceMappingURL=src-
|
|
2860
|
+
//# sourceMappingURL=src-DGh7w877.mjs.map
|