eutaxy 0.4.0 → 0.5.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.
@@ -44,6 +44,13 @@ interface Schedule {
44
44
  /** The per-run seed the decisions were drawn from. */
45
45
  readonly seed: number;
46
46
  readonly faults: readonly FaultDecision[];
47
+ /**
48
+ * The turn picked at each scheduling decision with more than one option,
49
+ * in order, as an index into the options (parked invocations by start
50
+ * order, then starting the next event). Absent: turns follow the seed.
51
+ * Exhaustive exploration records them, since it picks rather than draws.
52
+ */
53
+ readonly turns?: readonly number[];
47
54
  }
48
55
  /** Picks effect records by target, op, kind and payload fields. */
49
56
  interface EffectSelector {
@@ -124,7 +131,47 @@ interface Implies {
124
131
  readonly state: StateQuery;
125
132
  readonly column: string;
126
133
  }
127
- type Invariant = AtMostOncePerKey | AtLeastOnce | EveryRow | Implies;
134
+ /**
135
+ * No two rows the query returns share the value at `path`, a dot path into
136
+ * the row (a column name for flat rows). Rows where it is absent or null are
137
+ * skipped. Catches a resource handed out twice, e.g. "no project holds two
138
+ * slots".
139
+ */
140
+ interface Unique {
141
+ readonly kind: "unique";
142
+ readonly name: string;
143
+ readonly query: StateQuery;
144
+ readonly path: string;
145
+ }
146
+ /**
147
+ * The shell follows the core. Calls to a pure core function are recorded as
148
+ * decisions (`Core:<function>` results, payload `{ args, result }`). Every
149
+ * selected effect must come after a decision of `decision` in its own
150
+ * invocation; the latest such decision is the one it carries out. With
151
+ * `follows`, the effect's payload agrees with that decision at each pair of
152
+ * paths. With `state`, the decision rests on the last `read` its invocation
153
+ * made before it (none is a violation), and no other invocation's `write`
154
+ * (to the same `key`, when given) commits between that read and the effect:
155
+ * otherwise the effect carried out a decision made on a stale read.
156
+ */
157
+ interface Refines {
158
+ readonly kind: "refines";
159
+ readonly name: string;
160
+ /** The core function, as recorded. */
161
+ readonly decision: string;
162
+ readonly effect: EffectSelector;
163
+ readonly follows?: readonly {
164
+ readonly effect: string;
165
+ readonly decision: string;
166
+ }[];
167
+ readonly state?: {
168
+ readonly read: EffectSelector;
169
+ readonly write: EffectSelector;
170
+ /** Dot path into the read's and the writes' payloads naming the state they touch. */
171
+ readonly key?: string;
172
+ };
173
+ }
174
+ type Invariant = AtMostOncePerKey | AtLeastOnce | EveryRow | Implies | Unique | Refines;
128
175
  interface Violation {
129
176
  readonly invariant: string;
130
177
  readonly message: string;
@@ -198,6 +245,12 @@ interface ScenarioSpec {
198
245
  readonly externals: readonly ExternalDecl[];
199
246
  readonly invariants: readonly Invariant[];
200
247
  readonly bounds: Bounds;
248
+ /**
249
+ * Modules of pure core functions with Lemma specs, relative to the
250
+ * scenario. Calls to their annotated functions are recorded as decisions
251
+ * during exploration, and each property is checked on the inputs seen.
252
+ */
253
+ readonly specs?: readonly string[];
201
254
  }
202
255
  /** Every reason a spec is not usable; empty when it is. */
203
256
  declare function validateScenario(spec: ScenarioSpec): readonly string[];
@@ -207,6 +260,18 @@ interface EventRef {
207
260
  /** 1 for the first delivery, 2 for the first redelivery, and so on. */
208
261
  readonly attempt: number;
209
262
  readonly data: JsonValue;
263
+ /**
264
+ * Virtual time (ms since the epoch) before which the event is not
265
+ * delivered, e.g. a resend after the caller's retry delay. Absent: as soon
266
+ * as possible. The engine advances the virtual clock to it once nothing
267
+ * else can move.
268
+ */
269
+ readonly at?: number;
270
+ /**
271
+ * What produced the event when it is not the scenario's drive, e.g. a
272
+ * Durable Object alarm, so the platform knows how to deliver it.
273
+ */
274
+ readonly source?: string;
210
275
  }
211
276
  /** What a proxy tells the engine about an effect it is about to perform. */
212
277
  interface EffectPoint {
@@ -216,6 +281,29 @@ interface EffectPoint {
216
281
  readonly args: JsonValue;
217
282
  /** Which faults make sense here; the engine only injects from this list. */
218
283
  readonly allowed: readonly FaultKind[];
284
+ /**
285
+ * Performing this effect runs user code that may make effects of its own
286
+ * (a Durable Object call). Those are part of this effect's turn even when
287
+ * the runtime does not carry async context into that code.
288
+ */
289
+ readonly hostsEffects?: boolean;
290
+ }
291
+ interface EffectOptions {
292
+ /**
293
+ * Called when the effect is abandoned while its `perform` is still
294
+ * running, because its invocation crashed inside it or its I/O hung: the
295
+ * place to reset whatever the perform left busy (a Durable Object). For a
296
+ * crash inside, it is called synchronously where the crash happens, in the
297
+ * async context of the code the perform runs.
298
+ */
299
+ readonly onAbandon?: () => void;
300
+ /**
301
+ * Whether an effect the hosted code makes may wait for its turn now. False
302
+ * while the hosted code holds every other event out (a Durable Object
303
+ * inside blockConcurrencyWhile): nothing else could enter it then, and it
304
+ * could not notice its release, so the effect runs at once.
305
+ */
306
+ readonly mayPark?: () => boolean;
219
307
  }
220
308
  /** One invocation of the Worker, as the engine tracks it. */
221
309
  interface Invocation {
@@ -226,13 +314,34 @@ interface Invocation {
226
314
  }
227
315
  /** What the engine offers a platform during one run. */
228
316
  interface RunHooks {
229
- startInvocation(id: string): Invocation;
317
+ /**
318
+ * Start tracking an invocation; it becomes the running one. With
319
+ * `bookkeeping`, it only records the platform's own actions (a dead
320
+ * letter, a caller giving up) and never becomes the running one, so it
321
+ * cannot take over the effects of the handler it was started during.
322
+ */
323
+ startInvocation(id: string, options?: {
324
+ readonly bookkeeping?: boolean;
325
+ }): Invocation;
230
326
  /** Perform an asynchronous effect under fault injection and record it. */
231
- effect<T>(point: EffectPoint, perform: () => Promise<T>, summarize: (value: T) => JsonValue): Promise<T>;
327
+ effect<T>(point: EffectPoint, perform: () => Promise<T>, summarize: (value: T) => JsonValue, options?: EffectOptions): Promise<T>;
232
328
  /** Perform a synchronous effect under fault injection and record it. */
233
329
  effectSync<T>(point: EffectPoint, perform: () => T, summarize: (value: T) => JsonValue): T;
234
330
  /** Declare that the run touched something Eutaxy cannot control. */
235
331
  unsupported(reason: string): void;
332
+ /**
333
+ * The invocation whose code is running now. Proxies that cannot tell which
334
+ * invocation called them attribute their effects to it; with concurrent
335
+ * invocations only one runs at a time, so this is always the caller.
336
+ */
337
+ running(): string;
338
+ /**
339
+ * Queue an event now, before the current delivery finishes, e.g. a resend
340
+ * the caller makes as soon as it gives up while the handler's background
341
+ * work still runs. Equivalent to returning it in `followUps`, except for
342
+ * when it can start.
343
+ */
344
+ enqueue(event: EventRef): void;
236
345
  /** Record a state snapshot (not an effect point; never faulted). */
237
346
  snapshot(invocation: string, target: string, payload: JsonValue): void;
238
347
  /**
@@ -252,6 +361,13 @@ interface Platform {
252
361
  readonly name: string;
253
362
  /** What a verdict rests on that this platform decides, one line each. */
254
363
  readonly assumptions: readonly string[];
364
+ /**
365
+ * True when `deliver` may be called again before an earlier delivery has
366
+ * finished, which `maxConcurrentInvocations` above 1 needs. Such a
367
+ * platform attributes effects per delivery or through `RunHooks.running`,
368
+ * never through state shared between deliveries.
369
+ */
370
+ readonly concurrent?: boolean;
255
371
  /** Establish the scenario's initial state. Called before every run. */
256
372
  reset(spec: ScenarioSpec): Promise<void>;
257
373
  /** The events the scenario's drive produces, in order. */
@@ -265,5 +381,5 @@ interface Platform {
265
381
  /** Called when a run ends for any reason, after `finish` or after a failure: undo any per-run patching. */
266
382
  cleanup?(spec: ScenarioSpec): Promise<void>;
267
383
  }
268
- export { Schedule as C, JsonValue as E, FaultKind as S, EffectRecord as T, StateQuery as _, PlatformData as a, checkInvariants as b, WorkerRef as c, AtMostOncePerKey as d, EffectSelector as f, RowCondition as g, Invariant as h, ExternalDecl as i, validateScenario as l, Implies as m, Platform as n, ScenarioSpec as o, EveryRow as p, Bounds as r, ScriptedResponse as s, EventRef as t, AtLeastOnce as u, Violation as v, EffectLog as w, FaultDecision as x, checkInvariant as y };
269
- //# sourceMappingURL=platform-TwATAkL3.d.mts.map
384
+ export { FaultDecision as C, EffectRecord as D, EffectLog as E, JsonValue as O, checkInvariants as S, Schedule as T, RowCondition as _, PlatformData as a, Violation as b, WorkerRef as c, AtMostOncePerKey as d, EffectSelector as f, Refines as g, Invariant as h, ExternalDecl as i, validateScenario as l, Implies as m, Platform as n, ScenarioSpec as o, EveryRow as p, Bounds as r, ScriptedResponse as s, EventRef as t, AtLeastOnce as u, StateQuery as v, FaultKind as w, checkInvariant as x, Unique as y };
385
+ //# sourceMappingURL=platform-eVgCMbX0.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-eVgCMbX0.d.mts","names":[],"sources":["../../core/src/canonical-json.ts","../../core/src/effect-log.ts","../../core/src/faults.ts","../../core/src/invariants.ts","../../core/src/scenario.ts","../../core/src/platform.ts"],"mappings":";;;;;KAMY,wDAKC;YACG,cAAc;;;KCDlB;UAEK;;WAEN;WACA,MAAM;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;UAGH;WACN,kBAAkB;;;;;;;KChBjB;UAUK;;WAEN;;WAEA;WACA,OAAO;;WAEP;WACA;;UAGM;;WAEN;WACA,iBAAiB;;;;;;;WAOjB;;;UCjCM;WACN;WACA;WACA,OAAO;;WAEP;cAAoB,eAAe;;;WAEnC;cAAsB;;;;UAIhB;WACN;WACA;WACA,QAAQ;;WAER;;;UAIM;WACN;WACA;WACA,QAAQ;WACR;WACA,mBAAmB;;WAEnB;aAAwB;;;;KAqBvB;WACG;WAAyB;WAA2B,OAAO;;WAC3D;WAAyB;WAA0C;;WACnE;WAAyB;WAAmB,gBAAgB;;WAC5D;WAAyB;;;UAGvB;;WAEN;WACA;WACA,iBAAiB;;;UAIX;WACN;WACA;WACA,OAAO;WACP,gBAAgB;;;;;;;UAQV;WACN;WACA;WACA,MAAM;;WAEN;WACA,OAAO;WACP;;;;;;;;UASM;WACN;WACA;WACA,OAAO;WACP;;;;;;;;;;;;;UAcM;WACN;WACA;;WAEA;WACA,QAAQ;WACR;aAA8B;aAAyB;;WACvD;aACE,MAAM;aACN,OAAO;;aAEP;;;KASD,YAAY,mBAAmB,cAAc,WAAW,UAAU,SAAS;UA2DtE;WACN;WACA;;WAEA;;WAEA;;iBA4EK,eAAe,KAAK,WAAW,KAAK,YAAY;iBA2MhD,gBACd,KAAK,WACL,qBAAqB,uBACX;;UC3dK;WACN;YACC,cAAc;;;UAIT;WACN;WACA;;;UAIM;;WAEN;;WAEA;WACA;WACA;cAAsB;;;WAEtB,OAAO;;;;;;;UAQD;WACN;;WAEA;WACA;;;;;;aAME;;;WAGF,qBAAqB;;;UAIf;WACN;WACA;WACA;WACA;;UAGM;WACN;WACA;;WAEA;WACA,QAAQ;;WAER,OAAO;;WAEP,gBAAgB;WAChB,oBAAoB;WACpB,qBAAqB;WACrB,QAAQ;;;;;;WAMR;;;iBAeK,iBAAiB,MAAM;;UCpFtB;WACN;;WAEA;WACA,MAAM;;;;;;;WAON;;;;;WAKA;;;UAIM;WACN;WACA;WACA;WACA,MAAM;;WAEN,kBAAkB;;;;;;WAMlB;;UAGM;;;;;;;;WAQN;;;;;;;WAOA;;;UAIM;WACN;;WAEA,SAAS;EAClB;;;UAIe;;;;;;;EAOf,gBAAgB,YAAY;aAAqB;MAA0B;;EAE3E,OAAO,GACL,OAAO,aACP,eAAe,QAAQ,IACvB,YAAY,OAAO,MAAM,WACzB,UAAU,gBACT,QAAQ;;EAEX,WAAW,GAAG,OAAO,aAAa,eAAe,GAAG,YAAY,OAAO,MAAM,YAAY;;EAEzF,YAAY;;;;;;EAMZ;;;;;;;EAOA,QAAQ,OAAO;;EAEf,SAAS,oBAAoB,gBAAgB,SAAS;;;;;;;EAOtD,OAAO,GAAG,SAAS,QAAQ,IAAI,qBAAqB,QAAQ;;UAG7C;WACN;;WAEA,oBAAoB;;UAGd;WACN;;WAEA;;;;;;;WAOA;;EAET,MAAM,MAAM,eAAe;;EAE3B,cAAc,MAAM,wBAAwB;;EAE5C,QAAQ,OAAO,UAAU,OAAO,UAAU,MAAM,eAAe,QAAQ;;EAEvE,eAAe,MAAM,cAAc,6BAA6B;;EAEhE,QAAQ,MAAM,cAAc,OAAO,WAAW;;EAE9C,SAAS,MAAM,eAAe"}
@@ -1,8 +1,8 @@
1
1
  import { i as canonicalJson } from "./src-s6uYyC0B.mjs";
2
- import { i as emitRegressionTest, n as renderText } from "./src-BBXd0WEp.mjs";
2
+ import { a as emitRegressionTest, n as renderSpecs, o as predicateSource, r as renderText, s as extractSpecs } from "./src-CgfGiH25.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { spawn } from "node:child_process";
5
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
6
6
  import { basename, dirname, join, relative, resolve } from "node:path";
7
7
  // packages/cli/src/args.ts
8
8
  function parseArgs(argv, booleans = []) {
@@ -42,13 +42,15 @@ function parseArgs(argv, booleans = []) {
42
42
  /** Key under which the generated test stores its result in the Vitest task meta, read back from the JSON reporter. */
43
43
  const metaKey = "eutaxy";
44
44
  function checkTestSource(g) {
45
- const maxRuns = g.maxRuns === void 0 ? "" : `, maxRuns: ${g.maxRuns}`;
45
+ const maxRuns = (g.maxRuns === void 0 ? "" : `, maxRuns: ${g.maxRuns}`) + (g.exhaustive ? ", exhaustive: true" : "");
46
46
  return `// Generated by eutaxy check; deleted after the run.
47
- import { renderJson } from "eutaxy";
47
+ import { checkSpecModule, observeCore, renderJson } from "eutaxy";
48
48
  import { check, createCloudflarePlatform, type QueueHandler } from "eutaxy/cloudflare";
49
49
  import { env } from "cloudflare:workers";
50
+ import * as cloudflareTest from "cloudflare:test";
50
51
  import { test } from "vitest";
51
52
  import scenario from ${JSON.stringify(g.scenarioImport)};
53
+ import { specLoaders } from "./specs.ts";
52
54
 
53
55
  const sqlFiles = import.meta.glob("../**/*.sql", { query: "?raw", import: "default", eager: true }) as Record<string, string>;
54
56
  const modules = import.meta.glob(["../**/*.ts", "!../**/*.test.ts", "!../**/*.sim.ts", "!../**/node_modules/**", "!../**/.eutaxy/**"]) as Record<string, () => Promise<{ default: QueueHandler }>>;
@@ -68,9 +70,48 @@ test("eutaxy check", async ({ task }) => {
68
70
  const load = modules[key(scenario.worker.entry)];
69
71
  if (!load) throw new Error(\`worker entry \${scenario.worker.entry} not found next to the scenario\`);
70
72
  const handler = (await load()).default;
71
- const platform = createCloudflarePlatform({ env, handler, schemas });
72
- const verdict = await check(scenario, platform, { seed: ${JSON.stringify(g.seed)}${maxRuns} });
73
- task.meta[${JSON.stringify(metaKey)}] = { report: JSON.parse(renderJson(verdict)), worker: scenario.worker, setup: scenario.setup };
73
+ const platform = createCloudflarePlatform({ env, handler, schemas, durableObjects: cloudflareTest });
74
+ // The modules the scenario's specs name: their annotated functions, and the core functions
75
+ // refines invariants name, are observed while it runs.
76
+ const decisions = scenario.invariants.flatMap((i) => (i.kind === "refines" ? [i.decision] : []));
77
+ const specErrors: { module: string; line: number; message: string }[] = [];
78
+ const selected = [];
79
+ for (const path of scenario.specs ?? []) {
80
+ const specKey = \`./\${path.replace(/^(\\.\\/)+/, "")}\`;
81
+ const loadSpec = modules[key(path)];
82
+ if (!loadSpec) {
83
+ specErrors.push({ module: path, line: 0, message: "no such module next to the scenario" });
84
+ continue;
85
+ }
86
+ const namespace = await loadSpec();
87
+ const entry = specLoaders[specKey] ? await specLoaders[specKey]() : undefined;
88
+ const specs = entry?.specs ?? { functions: [], exports: [], errors: [] };
89
+ for (const e of specs.errors) specErrors.push({ module: path, ...e });
90
+ const names = [...new Set([...specs.functions.map((f) => f.name), ...decisions.filter((d) => typeof (namespace as Record<string, unknown>)[d] === "function")])];
91
+ selected.push({ path, key: specKey, namespace, specs, predicates: entry ? entry.predicates(namespace) : {}, names });
92
+ }
93
+ // Decisions are logged by function name: one name in two modules would make them ambiguous.
94
+ const observedIn = new Map<string, string>();
95
+ for (const m of selected)
96
+ for (const n of m.names) {
97
+ const other = observedIn.get(n);
98
+ if (other !== undefined) specErrors.push({ module: m.path, line: 0, message: \`\${n} is observed in both \${other} and \${m.path}; decisions of one name must come from one module\` });
99
+ else observedIn.set(n, m.path);
100
+ }
101
+ if (specErrors.length > 0) {
102
+ task.meta[${JSON.stringify(metaKey)}] = { report: null, specErrors, worker: scenario.worker, setup: scenario.setup };
103
+ return;
104
+ }
105
+ const observers = selected.map((m) => observeCore(m.namespace, m.names));
106
+ let verdict;
107
+ try {
108
+ verdict = await check(scenario, platform, { seed: ${JSON.stringify(g.seed)}${maxRuns} });
109
+ } finally {
110
+ for (const o of observers) o.restore();
111
+ }
112
+ const specs = selected.flatMap((m, i) => checkSpecModule(m.key, m.specs, m.predicates, observers[i]));
113
+ const observed = selected.map((m) => ({ module: m.path, functions: m.names }));
114
+ task.meta[${JSON.stringify(metaKey)}] = { report: JSON.parse(renderJson(verdict, specs)), worker: scenario.worker, setup: scenario.setup, observed };
74
115
  });
75
116
  `;
76
117
  }
@@ -97,19 +138,124 @@ function cloudflareRegressionTest(verdict, options) {
97
138
  const imports = [
98
139
  "import { createCloudflarePlatform } from \"eutaxy/cloudflare\";",
99
140
  "import { env } from \"cloudflare:workers\";",
141
+ ...options.durableObjects ? ["import * as cloudflareTest from \"cloudflare:test\";"] : [],
100
142
  `import scenario from ${JSON.stringify(options.scenarioPath)};`,
101
143
  ...bindings.map((b) => `import schema_${b} from ${JSON.stringify(`${options.schemaPaths[b]}?raw`)};`),
102
- `import handler from ${JSON.stringify(options.workerPath)};`
144
+ `import handler from ${JSON.stringify(options.workerPath)};`,
145
+ ...(options.specModules ?? []).map((m, i) => `import * as core_${i} from ${JSON.stringify(m.path)};`)
103
146
  ];
104
147
  const schemas = `{ ${bindings.map((b) => `${b}: schema_${b}`).join(", ")} }`;
105
148
  const retries = options.maxRetries === void 0 ? "" : `, maxRetries: ${options.maxRetries}`;
149
+ const objects = options.durableObjects ? ", durableObjects: cloudflareTest" : "";
106
150
  return emitRegressionTest(verdict, {
107
151
  imports,
108
- platform: `createCloudflarePlatform({ env, handler, schemas: ${schemas}${retries} })`,
152
+ platform: `createCloudflarePlatform({ env, handler, schemas: ${schemas}${retries}${objects} })`,
109
153
  scenario: "scenario",
110
154
  ...options.expect ? { expect: options.expect } : {},
111
- ...options.engineModule ? { engineModule: options.engineModule } : {}
155
+ ...options.engineModule ? { engineModule: options.engineModule } : {},
156
+ ...options.specModules && options.specModules.length > 0 ? { observe: options.specModules.map((m, i) => ({
157
+ namespace: `core_${i}`,
158
+ functions: m.functions
159
+ })) } : {}
160
+ });
161
+ }
162
+ // packages/cli/src/specs.ts
163
+ /**
164
+ * Spec modules for `eutaxy check`: every TypeScript module next to the
165
+ * scenario with Lemma annotations, and the generated module that holds
166
+ * their predicates as compiled code (workerd runs no `eval`). Which of them
167
+ * a run checks is the scenario's `specs`, read where the scenario is loaded,
168
+ * inside the generated test.
169
+ */
170
+ const skipDirs = /* @__PURE__ */ new Set([
171
+ "node_modules",
172
+ ".eutaxy",
173
+ "dist",
174
+ ".git"
175
+ ]);
176
+ /** Normalize a module path from a scenario's `specs` to a key. */
177
+ function specKey(path) {
178
+ return `./${path.split("\\").join("/").replace(/^(\.\/)+/, "")}`;
179
+ }
180
+ /** Annotated modules under `dir`, tests and scenarios excepted. */
181
+ function findSpecModules(dir) {
182
+ const out = [];
183
+ const walk = (at) => {
184
+ for (const entry of readdirSync(at, { withFileTypes: true })) {
185
+ const path = join(at, entry.name);
186
+ if (entry.isDirectory()) {
187
+ if (!skipDirs.has(entry.name)) walk(path);
188
+ continue;
189
+ }
190
+ const name = entry.name;
191
+ if (!name.endsWith(".ts") || name.endsWith(".d.ts") || name.endsWith(".test.ts") || name.endsWith(".sim.ts")) continue;
192
+ const source = readFileSync(path, "utf8");
193
+ if (!/@(ensures|total|throws)\b/.test(source)) continue;
194
+ const specs = extractSpecs(source);
195
+ if (specs.functions.length === 0 && specs.errors.length === 0) continue;
196
+ out.push({
197
+ key: specKey(relative(dir, path)),
198
+ path,
199
+ specs
200
+ });
201
+ }
202
+ };
203
+ walk(dir);
204
+ return out.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
205
+ }
206
+ /** The generated module's own names; each predicate takes them as parameters, so nothing in a property shadows them. */
207
+ const helpers = {
208
+ bool: "__eutaxyBool",
209
+ same: "__eutaxySame",
210
+ scope: "__eutaxyNamespace",
211
+ unresolved: "__eutaxyUnresolved"
212
+ };
213
+ /**
214
+ * The generated spec files: `specs.ts`, which maps each annotated module's
215
+ * key to a loader, and one file per module with its extracted specs and a
216
+ * function from its namespace to its predicates. A module's file loads only
217
+ * when a scenario names the module, so an annotation elsewhere that does not
218
+ * compile cannot stop a check. Each predicate binds its free names from the
219
+ * namespace (else the globals) when it is built, which happens before
220
+ * anything is observed, so checking a property never counts as a call the
221
+ * simulator made.
222
+ */
223
+ function specFiles(modules) {
224
+ const header = "// Generated by eutaxy check; deleted after the run.";
225
+ const index = [
226
+ header,
227
+ "export const specLoaders: Record<string, () => Promise<{ specs: any; predicates: (ns: any) => any }>> = {",
228
+ ...modules.map((m, i) => ` ${JSON.stringify(m.key)}: () => import("./specs/m${i}.ts"),`),
229
+ "};"
230
+ ];
231
+ const files = modules.map((m, i) => {
232
+ const lines = [
233
+ header,
234
+ `import { lemmaBool as ${helpers.bool}, lemmaUnresolved as ${helpers.unresolved} } from "eutaxy";`,
235
+ `const ${helpers.same} = Object.is;`,
236
+ "",
237
+ `export const specs = ${JSON.stringify(m.specs)};`,
238
+ "",
239
+ `export const predicates = (${helpers.scope}: any) => ({`
240
+ ];
241
+ for (const fn of m.specs.functions) {
242
+ lines.push(` [${JSON.stringify(fn.name)}]: {`);
243
+ for (const p of fn.ensures) {
244
+ const source = predicateSource(p.property, helpers).split("\n").join("\n ");
245
+ lines.push(` [${JSON.stringify(p.name)}]: ${source},`);
246
+ }
247
+ lines.push(" },");
248
+ }
249
+ lines.push("});");
250
+ return {
251
+ name: `specs/m${i}.ts`,
252
+ source: `${lines.join("\n")}\n`
253
+ };
112
254
  });
255
+ return [{
256
+ name: "specs.ts",
257
+ source: `${index.join("\n")}\n`
258
+ }, ...files];
113
259
  }
114
260
  // packages/cli/src/check.ts
115
261
  /**
@@ -207,8 +353,13 @@ async function runCheck(o) {
207
353
  writeFileSync(testPath, checkTestSource({
208
354
  seed: o.seed ?? name,
209
355
  ...o.maxRuns === void 0 ? {} : { maxRuns: o.maxRuns },
356
+ ...o.exhaustive ? { exhaustive: true } : {},
210
357
  scenarioImport: `../${basename(scenarioPath)}`
211
358
  }));
359
+ for (const f of specFiles(findSpecModules(dir))) {
360
+ mkdirSync(dirname(join(workDir, f.name)), { recursive: true });
361
+ writeFileSync(join(workDir, f.name), f.source);
362
+ }
212
363
  const reportPath = join(workDir, "vitest-report.json");
213
364
  rmSync(reportPath, { force: true });
214
365
  writeFileSync(configPath, vitestConfigSource(wrangler, testPath, reportPath));
@@ -218,9 +369,15 @@ async function runCheck(o) {
218
369
  o.stderr(`eutaxy check could not read a verdict from Vitest (exit ${code}):\n${output}\n`);
219
370
  return exitCodes.error;
220
371
  }
221
- const verdict = transport.report.verdict;
372
+ if (transport.specErrors && transport.specErrors.length > 0) {
373
+ for (const e of transport.specErrors) o.stderr(`${e.module}${e.line > 0 ? `:${e.line}` : ""}: ${e.message}\n`);
374
+ return exitCodes.error;
375
+ }
376
+ const report = transport.report;
377
+ const verdict = report.verdict;
378
+ const specs = report.specs ?? [];
222
379
  if (o.json) o.stdout(`${canonicalJson(transport.report)}\n`);
223
- else o.stdout(`${renderText(verdict)}\n`);
380
+ else o.stdout(`${renderText(verdict)}\n${specs.length > 0 ? `\n${renderSpecs(specs)}\n` : ""}`);
224
381
  if (verdict.kind === "VIOLATED" && !o.noRegression) {
225
382
  const outPath = o.out ? resolve(o.cwd, o.out) : join(dir, `${name}.regression.test.ts`);
226
383
  const outDir = dirname(outPath);
@@ -230,12 +387,18 @@ async function runCheck(o) {
230
387
  scenarioPath: toPosix(relative(outDir, scenarioPath)),
231
388
  workerPath: toPosix(relative(outDir, resolve(dir, transport.worker.entry))),
232
389
  schemaPaths,
233
- ...o.expectViolation ? { expect: "violates" } : {}
390
+ ...transport.setup.some((s) => s.kind === "durable_object") ? { durableObjects: true } : {},
391
+ ...o.expectViolation ? { expect: "violates" } : {},
392
+ ...(transport.observed ?? []).length > 0 ? { specModules: (transport.observed ?? []).map((m) => ({
393
+ path: toPosix(relative(outDir, resolve(dir, m.module))),
394
+ functions: m.functions
395
+ })) } : {}
234
396
  });
235
397
  mkdirSync(outDir, { recursive: true });
236
398
  writeFileSync(outPath, source);
237
399
  if (!o.json) o.stdout(`\nRegression test written to ${relative(o.cwd, outPath) || outPath}\n`);
238
400
  }
401
+ if (verdict.kind !== "VIOLATED" && specs.some((v) => v.kind === "REFUTED")) return exitCodes.VIOLATED;
239
402
  return exitCodes[verdict.kind];
240
403
  } finally {
241
404
  if (!o.keep) rmSync(workDir, {
@@ -254,13 +417,14 @@ Options:
254
417
  --wrangler <path> wrangler config (default: wrangler.jsonc/json/toml beside the scenario)
255
418
  --seed <seed> exploration seed (default: the scenario file name)
256
419
  --max-runs <n> cap on exploration runs in addition to the scenario's time budget
420
+ --exhaustive run every schedule within the bounds once (with partial-order reduction)
257
421
  --json print the versioned JSON report instead of text
258
422
  --out <path> where to write the regression test on a violation
259
423
  --no-regression do not write a regression test
260
424
  --expect-violation write a regression test that asserts the violation (for corpora)
261
425
  --keep keep the generated .eutaxy/ files
262
426
 
263
- Exit codes: 0 BOUNDED, 1 VIOLATED, 2 UNSUPPORTED, 3 error.
427
+ Exit codes: 0 BOUNDED, 1 VIOLATED or a REFUTED spec, 2 UNSUPPORTED, 3 error.
264
428
  `;
265
429
  async function main(argv, io) {
266
430
  const { positionals, flags } = parseArgs(argv, [
@@ -268,7 +432,8 @@ async function main(argv, io) {
268
432
  "no-regression",
269
433
  "expect-violation",
270
434
  "keep",
271
- "help"
435
+ "help",
436
+ "exhaustive"
272
437
  ]);
273
438
  const command = positionals[0];
274
439
  if (!command || command === "help" || flags["help"] === true) {
@@ -297,6 +462,7 @@ async function main(argv, io) {
297
462
  ...str("wrangler") ? { wrangler: str("wrangler") } : {},
298
463
  ...str("seed") ? { seed: str("seed") } : {},
299
464
  ...maxRuns === void 0 ? {} : { maxRuns },
465
+ exhaustive: flags["exhaustive"] === true,
300
466
  json: flags["json"] === true,
301
467
  ...str("out") ? { out: str("out") } : {},
302
468
  noRegression: flags["no-regression"] === true,
@@ -308,4 +474,4 @@ async function main(argv, io) {
308
474
  }
309
475
  export { cloudflareRegressionTest as n, main as t };
310
476
 
311
- //# sourceMappingURL=src-BGdIBGkN.mjs.map
477
+ //# sourceMappingURL=src-BD3jkjgG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-BD3jkjgG.mjs","names":[],"sources":["../../cli/src/args.ts","../../cli/src/generate.ts","../../cli/src/regression.ts","../../cli/src/specs.ts","../../cli/src/check.ts","../../cli/src/main.ts"],"sourcesContent":["/** A small argument parser: positionals, `--flag value`, `--flag=value` and boolean `--flag`. */\n\nexport interface ParsedArgs {\n readonly positionals: readonly string[];\n readonly flags: Readonly<Record<string, string | true>>;\n}\n\nexport function parseArgs(argv: readonly string[], booleans: readonly string[] = []): ParsedArgs {\n const positionals: string[] = [];\n const flags: Record<string, string | true> = {};\n for (let i = 0; i < argv.length; i++) {\n const a = argv[i] as string;\n if (!a.startsWith(\"--\")) {\n positionals.push(a);\n continue;\n }\n const eq = a.indexOf(\"=\");\n if (eq !== -1) {\n flags[a.slice(2, eq)] = a.slice(eq + 1);\n continue;\n }\n const name = a.slice(2);\n const next = argv[i + 1];\n if (booleans.includes(name) || next === undefined || next.startsWith(\"--\")) {\n flags[name] = true;\n } else {\n flags[name] = next;\n i++;\n }\n }\n return { positionals, flags };\n}\n","/**\n * The files `eutaxy check` writes into `<scenario dir>/.eutaxy/` before\n * running Vitest: a test that performs the check inside workerd and prints\n * the verdict on one marked line, and a Vitest config with the Cloudflare\n * plugin pointed at the scenario's wrangler config.\n */\n\n/** Key under which the generated test stores its result in the Vitest task meta, read back from the JSON reporter. */\nexport const metaKey = \"eutaxy\";\n\nexport interface GeneratedCheck {\n readonly seed: string;\n readonly maxRuns?: number;\n /** Exhaustive exploration instead of seeded. */\n readonly exhaustive?: boolean;\n /** Import specifier of the scenario from the generated test (e.g. \"../scenario.sim.ts\"). */\n readonly scenarioImport: string;\n}\n\n/** What the generated test stores in its task meta. */\nexport interface CheckTransport {\n readonly report: unknown;\n /** Set instead of a report when a module the scenario's `specs` names has no usable annotations. */\n readonly specErrors?: readonly {\n readonly module: string;\n readonly line: number;\n readonly message: string;\n }[];\n readonly worker: { readonly entry: string; readonly config: string };\n readonly setup: readonly { readonly kind: string; readonly [key: string]: unknown }[];\n /** The core modules observed (as the scenario's specs name them) and the functions on each. */\n readonly observed?: readonly { readonly module: string; readonly functions: readonly string[] }[];\n}\n\nexport function checkTestSource(g: GeneratedCheck): string {\n const maxRuns =\n (g.maxRuns === undefined ? \"\" : `, maxRuns: ${g.maxRuns}`) +\n (g.exhaustive ? \", exhaustive: true\" : \"\");\n return `// Generated by eutaxy check; deleted after the run.\nimport { checkSpecModule, observeCore, renderJson } from \"eutaxy\";\nimport { check, createCloudflarePlatform, type QueueHandler } from \"eutaxy/cloudflare\";\nimport { env } from \"cloudflare:workers\";\nimport * as cloudflareTest from \"cloudflare:test\";\nimport { test } from \"vitest\";\nimport scenario from ${JSON.stringify(g.scenarioImport)};\nimport { specLoaders } from \"./specs.ts\";\n\nconst sqlFiles = import.meta.glob(\"../**/*.sql\", { query: \"?raw\", import: \"default\", eager: true }) as Record<string, string>;\nconst modules = import.meta.glob([\"../**/*.ts\", \"!../**/*.test.ts\", \"!../**/*.sim.ts\", \"!../**/node_modules/**\", \"!../**/.eutaxy/**\"]) as Record<string, () => Promise<{ default: QueueHandler }>>;\n\nfunction key(path: string): string {\n return \\`../\\${path.replace(/^\\\\.\\\\//, \"\")}\\`;\n}\n\ntest(\"eutaxy check\", async ({ task }) => {\n const schemas: Record<string, string> = {};\n for (const step of scenario.setup) {\n if (step.kind !== \"d1\") continue;\n const sql = sqlFiles[key(String(step.schemaFile))];\n if (sql === undefined) throw new Error(\\`schema file \\${String(step.schemaFile)} not found next to the scenario\\`);\n schemas[String(step.binding)] = sql;\n }\n const load = modules[key(scenario.worker.entry)];\n if (!load) throw new Error(\\`worker entry \\${scenario.worker.entry} not found next to the scenario\\`);\n const handler = (await load()).default;\n const platform = createCloudflarePlatform({ env, handler, schemas, durableObjects: cloudflareTest });\n // The modules the scenario's specs name: their annotated functions, and the core functions\n // refines invariants name, are observed while it runs.\n const decisions = scenario.invariants.flatMap((i) => (i.kind === \"refines\" ? [i.decision] : []));\n const specErrors: { module: string; line: number; message: string }[] = [];\n const selected = [];\n for (const path of scenario.specs ?? []) {\n const specKey = \\`./\\${path.replace(/^(\\\\.\\\\/)+/, \"\")}\\`;\n const loadSpec = modules[key(path)];\n if (!loadSpec) {\n specErrors.push({ module: path, line: 0, message: \"no such module next to the scenario\" });\n continue;\n }\n const namespace = await loadSpec();\n const entry = specLoaders[specKey] ? await specLoaders[specKey]() : undefined;\n const specs = entry?.specs ?? { functions: [], exports: [], errors: [] };\n for (const e of specs.errors) specErrors.push({ module: path, ...e });\n const names = [...new Set([...specs.functions.map((f) => f.name), ...decisions.filter((d) => typeof (namespace as Record<string, unknown>)[d] === \"function\")])];\n selected.push({ path, key: specKey, namespace, specs, predicates: entry ? entry.predicates(namespace) : {}, names });\n }\n // Decisions are logged by function name: one name in two modules would make them ambiguous.\n const observedIn = new Map<string, string>();\n for (const m of selected)\n for (const n of m.names) {\n const other = observedIn.get(n);\n if (other !== undefined) specErrors.push({ module: m.path, line: 0, message: \\`\\${n} is observed in both \\${other} and \\${m.path}; decisions of one name must come from one module\\` });\n else observedIn.set(n, m.path);\n }\n if (specErrors.length > 0) {\n task.meta[${JSON.stringify(metaKey)}] = { report: null, specErrors, worker: scenario.worker, setup: scenario.setup };\n return;\n }\n const observers = selected.map((m) => observeCore(m.namespace, m.names));\n let verdict;\n try {\n verdict = await check(scenario, platform, { seed: ${JSON.stringify(g.seed)}${maxRuns} });\n } finally {\n for (const o of observers) o.restore();\n }\n const specs = selected.flatMap((m, i) => checkSpecModule(m.key, m.specs, m.predicates, observers[i]));\n const observed = selected.map((m) => ({ module: m.path, functions: m.names }));\n task.meta[${JSON.stringify(metaKey)}] = { report: JSON.parse(renderJson(verdict, specs)), worker: scenario.worker, setup: scenario.setup, observed };\n});\n`;\n}\n\nexport function vitestConfigSource(\n wranglerConfigPath: string,\n testPath: string,\n outputFile: string,\n): string {\n return `// Generated by eutaxy check; deleted after the run.\nimport { cloudflareTest } from \"@cloudflare/vitest-plugin\";\nimport { defineConfig } from \"vitest/config\";\n\nexport default defineConfig({\n plugins: [cloudflareTest({ wrangler: { configPath: ${JSON.stringify(wranglerConfigPath)} } })],\n test: {\n include: [${JSON.stringify(testPath)}],\n testTimeout: 600_000,\n reporters: [\"json\"],\n outputFile: ${JSON.stringify(outputFile)},\n },\n});\n`;\n}\n","import type { Violated } from \"@eutaxy/core\";\nimport { emitRegressionTest } from \"@eutaxy/report\";\n\nexport interface CloudflareRegressionOptions {\n /** Import path of the scenario module, relative to the emitted file. */\n readonly scenarioPath: string;\n /** Import path of the Worker module. */\n readonly workerPath: string;\n /** D1 binding name to schema file path, imported with `?raw`. */\n readonly schemaPaths: Readonly<Record<string, string>>;\n /** The platform's retry limit, when the scenario was checked with a non-default one. */\n readonly maxRetries?: number;\n /** The scenario sets up Durable Objects: pass the Cloudflare test helpers to the platform. */\n readonly durableObjects?: boolean;\n readonly expect?: \"holds\" | \"violates\";\n readonly engineModule?: string;\n /** Core modules to observe during the replay (import path, functions), for `refines`. */\n readonly specModules?: readonly {\n readonly path: string;\n readonly functions: readonly string[];\n }[];\n}\n\n/** A Vitest regression test for a Cloudflare scenario, to run under the Cloudflare Vitest plugin. */\nexport function cloudflareRegressionTest(\n verdict: Violated,\n options: CloudflareRegressionOptions,\n): string {\n const bindings = Object.keys(options.schemaPaths).sort();\n const imports = [\n 'import { createCloudflarePlatform } from \"eutaxy/cloudflare\";',\n 'import { env } from \"cloudflare:workers\";',\n ...(options.durableObjects ? ['import * as cloudflareTest from \"cloudflare:test\";'] : []),\n `import scenario from ${JSON.stringify(options.scenarioPath)};`,\n ...bindings.map(\n (b) => `import schema_${b} from ${JSON.stringify(`${options.schemaPaths[b]}?raw`)};`,\n ),\n `import handler from ${JSON.stringify(options.workerPath)};`,\n ...(options.specModules ?? []).map(\n (m, i) => `import * as core_${i} from ${JSON.stringify(m.path)};`,\n ),\n ];\n const schemas = `{ ${bindings.map((b) => `${b}: schema_${b}`).join(\", \")} }`;\n const retries = options.maxRetries === undefined ? \"\" : `, maxRetries: ${options.maxRetries}`;\n const objects = options.durableObjects ? \", durableObjects: cloudflareTest\" : \"\";\n return emitRegressionTest(verdict, {\n imports,\n platform: `createCloudflarePlatform({ env, handler, schemas: ${schemas}${retries}${objects} })`,\n scenario: \"scenario\",\n ...(options.expect ? { expect: options.expect } : {}),\n ...(options.engineModule ? { engineModule: options.engineModule } : {}),\n ...(options.specModules && options.specModules.length > 0\n ? {\n observe: options.specModules.map((m, i) => ({\n namespace: `core_${i}`,\n functions: m.functions,\n })),\n }\n : {}),\n });\n}\n","/**\n * Spec modules for `eutaxy check`: every TypeScript module next to the\n * scenario with Lemma annotations, and the generated module that holds\n * their predicates as compiled code (workerd runs no `eval`). Which of them\n * a run checks is the scenario's `specs`, read where the scenario is loaded,\n * inside the generated test.\n */\n\nimport { readdirSync, readFileSync } from \"node:fs\";\nimport { join, relative } from \"node:path\";\nimport { extractSpecs, type ModuleSpecs, predicateSource } from \"@eutaxy/spec\";\n\nexport interface SpecModule {\n /** The path relative to the scenario's directory, as a scenario names it: \"./domain.ts\". */\n readonly key: string;\n readonly path: string;\n readonly specs: ModuleSpecs;\n}\n\nconst skipDirs = new Set([\"node_modules\", \".eutaxy\", \"dist\", \".git\"]);\n\n/** Normalize a module path from a scenario's `specs` to a key. */\nexport function specKey(path: string): string {\n const posix = path\n .split(\"\\\\\")\n .join(\"/\")\n .replace(/^(\\.\\/)+/, \"\");\n return `./${posix}`;\n}\n\n/** Annotated modules under `dir`, tests and scenarios excepted. */\nexport function findSpecModules(dir: string): SpecModule[] {\n const out: SpecModule[] = [];\n const walk = (at: string): void => {\n for (const entry of readdirSync(at, { withFileTypes: true })) {\n const path = join(at, entry.name);\n if (entry.isDirectory()) {\n if (!skipDirs.has(entry.name)) walk(path);\n continue;\n }\n const name = entry.name;\n if (\n !name.endsWith(\".ts\") ||\n name.endsWith(\".d.ts\") ||\n name.endsWith(\".test.ts\") ||\n name.endsWith(\".sim.ts\")\n )\n continue;\n const source = readFileSync(path, \"utf8\");\n if (!/@(ensures|total|throws)\\b/.test(source)) continue;\n const specs = extractSpecs(source);\n if (specs.functions.length === 0 && specs.errors.length === 0) continue;\n out.push({ key: specKey(relative(dir, path)), path, specs });\n }\n };\n walk(dir);\n return out.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));\n}\n\n/** The generated module's own names; each predicate takes them as parameters, so nothing in a property shadows them. */\nconst helpers = {\n bool: \"__eutaxyBool\",\n same: \"__eutaxySame\",\n scope: \"__eutaxyNamespace\",\n unresolved: \"__eutaxyUnresolved\",\n};\n\n/** A file `eutaxy check` writes into `.eutaxy/`, by its path there. */\nexport interface GeneratedFile {\n readonly name: string;\n readonly source: string;\n}\n\n/**\n * The generated spec files: `specs.ts`, which maps each annotated module's\n * key to a loader, and one file per module with its extracted specs and a\n * function from its namespace to its predicates. A module's file loads only\n * when a scenario names the module, so an annotation elsewhere that does not\n * compile cannot stop a check. Each predicate binds its free names from the\n * namespace (else the globals) when it is built, which happens before\n * anything is observed, so checking a property never counts as a call the\n * simulator made.\n */\nexport function specFiles(modules: readonly SpecModule[]): GeneratedFile[] {\n const header = \"// Generated by eutaxy check; deleted after the run.\";\n const index = [\n header,\n \"export const specLoaders: Record<string, () => Promise<{ specs: any; predicates: (ns: any) => any }>> = {\",\n ...modules.map((m, i) => ` ${JSON.stringify(m.key)}: () => import(\"./specs/m${i}.ts\"),`),\n \"};\",\n ];\n const files = modules.map((m, i) => {\n const lines = [\n header,\n `import { lemmaBool as ${helpers.bool}, lemmaUnresolved as ${helpers.unresolved} } from \"eutaxy\";`,\n `const ${helpers.same} = Object.is;`,\n \"\",\n `export const specs = ${JSON.stringify(m.specs)};`,\n \"\",\n `export const predicates = (${helpers.scope}: any) => ({`,\n ];\n for (const fn of m.specs.functions) {\n // Computed keys: a name like __proto__ stays an ordinary entry.\n lines.push(` [${JSON.stringify(fn.name)}]: {`);\n for (const p of fn.ensures) {\n const source = predicateSource(p.property, helpers).split(\"\\n\").join(\"\\n \");\n lines.push(` [${JSON.stringify(p.name)}]: ${source},`);\n }\n lines.push(\" },\");\n }\n lines.push(\"});\");\n return { name: `specs/m${i}.ts`, source: `${lines.join(\"\\n\")}\\n` };\n });\n return [{ name: \"specs.ts\", source: `${index.join(\"\\n\")}\\n` }, ...files];\n}\n","/**\n * `eutaxy check <scenario.sim.ts>`: run a scenario inside workerd through\n * the user's Vitest and the Cloudflare plugin, print the verdict as text or\n * JSON, and on a violation write a regression test next to the scenario.\n */\n\nimport { spawn } from \"node:child_process\";\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { basename, dirname, join, relative, resolve } from \"node:path\";\nimport {\n canonicalJson,\n type JsonValue,\n type ScenarioVerdict,\n type SpecVerdict,\n type Violated,\n} from \"@eutaxy/core\";\nimport { renderSpecs, renderText } from \"@eutaxy/report\";\nimport { type CheckTransport, checkTestSource, metaKey, vitestConfigSource } from \"./generate.ts\";\nimport { cloudflareRegressionTest } from \"./regression.ts\";\nimport { findSpecModules, specFiles } from \"./specs.ts\";\n\nexport interface CheckOptions {\n readonly scenario: string;\n readonly cwd: string;\n readonly wrangler?: string;\n readonly seed?: string;\n readonly maxRuns?: number;\n /** Run every schedule within the bounds once instead of drawing them from the seed. */\n readonly exhaustive?: boolean;\n readonly json: boolean;\n /** Where to write the regression test on a violation; default `<name>.regression.test.ts` beside the scenario. */\n readonly out?: string;\n readonly noRegression: boolean;\n /** Emit a regression test that asserts the violation (for corpora) rather than one that expects it fixed. */\n readonly expectViolation: boolean;\n /** Keep the generated `.eutaxy/` files for inspection. */\n readonly keep: boolean;\n readonly stdout: (text: string) => void;\n readonly stderr: (text: string) => void;\n}\n\nexport const exitCodes = { BOUNDED: 0, VIOLATED: 1, UNSUPPORTED: 2, error: 3 } as const;\n\nfunction findWrangler(dir: string, explicit: string | undefined, cwd: string): string | null {\n if (explicit) return resolve(cwd, explicit);\n for (const name of [\"wrangler.jsonc\", \"wrangler.json\", \"wrangler.toml\"]) {\n const p = join(dir, name);\n if (existsSync(p)) return p;\n }\n return null;\n}\n\nfunction vitestBin(from: string): string {\n const req = createRequire(join(from, \"package.json\"));\n return join(dirname(req.resolve(\"vitest/package.json\")), \"vitest.mjs\");\n}\n\nfunction runVitest(\n bin: string,\n configPath: string,\n cwd: string,\n): Promise<{ code: number; output: string }> {\n return new Promise((resolveRun) => {\n const child = spawn(process.execPath, [bin, \"run\", \"--config\", configPath], {\n cwd,\n env: { ...process.env, CI: \"1\", FORCE_COLOR: \"0\" },\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n let output = \"\";\n child.stdout.on(\"data\", (d: Buffer) => {\n output += d.toString();\n });\n child.stderr.on(\"data\", (d: Buffer) => {\n output += d.toString();\n });\n child.on(\"close\", (code) => resolveRun({ code: code ?? 1, output }));\n });\n}\n\n/** The transport the generated test left in its task meta, via Vitest's JSON reporter. */\nfunction readTransport(reportPath: string): CheckTransport | null {\n if (!existsSync(reportPath)) return null;\n const report = JSON.parse(readFileSync(reportPath, \"utf8\")) as {\n testResults?: { assertionResults?: { meta?: Record<string, unknown> }[] }[];\n };\n for (const file of report.testResults ?? []) {\n for (const t of file.assertionResults ?? []) {\n const m = t.meta?.[metaKey];\n if (m) return m as CheckTransport;\n }\n }\n return null;\n}\n\nfunction toPosix(p: string): string {\n const s = p.split(\"\\\\\").join(\"/\");\n return s.startsWith(\".\") ? s : `./${s}`;\n}\n\nexport async function runCheck(o: CheckOptions): Promise<number> {\n const scenarioPath = resolve(o.cwd, o.scenario);\n if (!existsSync(scenarioPath)) {\n o.stderr(`scenario not found: ${scenarioPath}\\n`);\n return exitCodes.error;\n }\n const dir = dirname(scenarioPath);\n const name = basename(scenarioPath)\n .replace(/\\.sim\\.ts$/, \"\")\n .replace(/\\.ts$/, \"\");\n const wrangler = findWrangler(dir, o.wrangler, o.cwd);\n if (!wrangler || !existsSync(wrangler)) {\n o.stderr(`no wrangler config found next to the scenario; pass --wrangler <path>\\n`);\n return exitCodes.error;\n }\n const workDir = join(dir, \".eutaxy\");\n const testPath = join(workDir, `${name}.check.test.ts`);\n const configPath = join(workDir, \"vitest.config.mts\");\n mkdirSync(workDir, { recursive: true });\n try {\n writeFileSync(\n testPath,\n checkTestSource({\n seed: o.seed ?? name,\n ...(o.maxRuns === undefined ? {} : { maxRuns: o.maxRuns }),\n ...(o.exhaustive ? { exhaustive: true } : {}),\n scenarioImport: `../${basename(scenarioPath)}`,\n }),\n );\n for (const f of specFiles(findSpecModules(dir))) {\n mkdirSync(dirname(join(workDir, f.name)), { recursive: true });\n writeFileSync(join(workDir, f.name), f.source);\n }\n const reportPath = join(workDir, \"vitest-report.json\");\n rmSync(reportPath, { force: true }); // never read a report left by an earlier --keep run\n writeFileSync(configPath, vitestConfigSource(wrangler, testPath, reportPath));\n const { code, output } = await runVitest(vitestBin(dir), configPath, dir);\n const transport = code === 0 ? readTransport(reportPath) : null;\n if (!transport) {\n o.stderr(`eutaxy check could not read a verdict from Vitest (exit ${code}):\\n${output}\\n`);\n return exitCodes.error;\n }\n if (transport.specErrors && transport.specErrors.length > 0) {\n for (const e of transport.specErrors)\n o.stderr(`${e.module}${e.line > 0 ? `:${e.line}` : \"\"}: ${e.message}\\n`);\n return exitCodes.error;\n }\n const report = transport.report as { verdict: ScenarioVerdict; specs?: readonly SpecVerdict[] };\n const verdict = report.verdict;\n const specs = report.specs ?? [];\n if (o.json) o.stdout(`${canonicalJson(transport.report as JsonValue)}\\n`);\n else o.stdout(`${renderText(verdict)}\\n${specs.length > 0 ? `\\n${renderSpecs(specs)}\\n` : \"\"}`);\n\n if (verdict.kind === \"VIOLATED\" && !o.noRegression) {\n const outPath = o.out ? resolve(o.cwd, o.out) : join(dir, `${name}.regression.test.ts`);\n const outDir = dirname(outPath);\n const schemaPaths: Record<string, string> = {};\n for (const step of transport.setup) {\n if (step.kind === \"d1\") {\n schemaPaths[String(step[\"binding\"])] = toPosix(\n relative(outDir, resolve(dir, String(step[\"schemaFile\"]))),\n );\n }\n }\n const source = cloudflareRegressionTest(verdict as Violated, {\n scenarioPath: toPosix(relative(outDir, scenarioPath)),\n workerPath: toPosix(relative(outDir, resolve(dir, transport.worker.entry))),\n schemaPaths,\n ...(transport.setup.some((s) => s.kind === \"durable_object\")\n ? { durableObjects: true }\n : {}),\n ...(o.expectViolation ? { expect: \"violates\" as const } : {}),\n ...((transport.observed ?? []).length > 0\n ? {\n specModules: (transport.observed ?? []).map((m) => ({\n path: toPosix(relative(outDir, resolve(dir, m.module))),\n functions: m.functions,\n })),\n }\n : {}),\n });\n mkdirSync(outDir, { recursive: true });\n writeFileSync(outPath, source);\n if (!o.json)\n o.stdout(`\\nRegression test written to ${relative(o.cwd, outPath) || outPath}\\n`);\n }\n // A refuted spec fails the check like a violation does.\n if (verdict.kind !== \"VIOLATED\" && specs.some((v) => v.kind === \"REFUTED\"))\n return exitCodes.VIOLATED;\n return exitCodes[verdict.kind];\n } finally {\n if (!o.keep) rmSync(workDir, { recursive: true, force: true });\n }\n}\n","import { parseArgs } from \"./args.ts\";\nimport { exitCodes, runCheck } from \"./check.ts\";\n\nconst usage = `eutaxy — deterministic simulation checks for Cloudflare Workers\n\nUsage:\n eutaxy check <scenario.sim.ts> [options]\n\nOptions:\n --wrangler <path> wrangler config (default: wrangler.jsonc/json/toml beside the scenario)\n --seed <seed> exploration seed (default: the scenario file name)\n --max-runs <n> cap on exploration runs in addition to the scenario's time budget\n --exhaustive run every schedule within the bounds once (with partial-order reduction)\n --json print the versioned JSON report instead of text\n --out <path> where to write the regression test on a violation\n --no-regression do not write a regression test\n --expect-violation write a regression test that asserts the violation (for corpora)\n --keep keep the generated .eutaxy/ files\n\nExit codes: 0 BOUNDED, 1 VIOLATED or a REFUTED spec, 2 UNSUPPORTED, 3 error.\n`;\n\nexport interface Io {\n readonly cwd: string;\n readonly stdout: (text: string) => void;\n readonly stderr: (text: string) => void;\n}\n\nexport async function main(argv: readonly string[], io: Io): Promise<number> {\n const { positionals, flags } = parseArgs(argv, [\n \"json\",\n \"no-regression\",\n \"expect-violation\",\n \"keep\",\n \"help\",\n \"exhaustive\",\n ]);\n const command = positionals[0];\n if (!command || command === \"help\" || flags[\"help\"] === true) {\n io.stdout(usage);\n return command ? exitCodes.BOUNDED : exitCodes.error;\n }\n if (command !== \"check\") {\n io.stderr(`unknown command ${command}\\n\\n${usage}`);\n return exitCodes.error;\n }\n const scenario = positionals[1];\n if (!scenario) {\n io.stderr(`check needs a scenario file\\n\\n${usage}`);\n return exitCodes.error;\n }\n const str = (k: string): string | undefined =>\n typeof flags[k] === \"string\" ? (flags[k] as string) : undefined;\n const maxRunsText = str(\"max-runs\");\n const maxRuns = maxRunsText === undefined ? undefined : Number(maxRunsText);\n if (maxRuns !== undefined && !(Number.isInteger(maxRuns) && maxRuns > 0)) {\n io.stderr(`--max-runs must be a positive integer, got ${JSON.stringify(maxRunsText)}\\n`);\n return exitCodes.error;\n }\n return runCheck({\n scenario,\n cwd: io.cwd,\n ...(str(\"wrangler\") ? { wrangler: str(\"wrangler\") as string } : {}),\n ...(str(\"seed\") ? { seed: str(\"seed\") as string } : {}),\n ...(maxRuns === undefined ? {} : { maxRuns }),\n exhaustive: flags[\"exhaustive\"] === true,\n json: flags[\"json\"] === true,\n ...(str(\"out\") ? { out: str(\"out\") as string } : {}),\n noRegression: flags[\"no-regression\"] === true,\n expectViolation: flags[\"expect-violation\"] === true,\n keep: flags[\"keep\"] === true,\n stdout: io.stdout,\n stderr: io.stderr,\n });\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,UAAU,MAAyB,WAA8B,CAAC,GAAe;CAC/F,MAAM,cAAwB,CAAC;CAC/B,MAAM,QAAuC,CAAC;CAC9C,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,Q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