eutaxy 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +10 -6
  2. package/dist/aws.d.mts +28 -2
  3. package/dist/aws.d.mts.map +1 -1
  4. package/dist/aws.mjs +13 -2
  5. package/dist/aws.mjs.map +1 -1
  6. package/dist/bin.mjs +1 -1
  7. package/dist/{cli-BppjMaqL.mjs → cli-CzGCMudc.mjs} +637 -55
  8. package/dist/cli-CzGCMudc.mjs.map +1 -0
  9. package/dist/cli.d.mts.map +1 -1
  10. package/dist/cli.mjs +1 -1
  11. package/dist/cloudflare.d.mts +79 -8
  12. package/dist/cloudflare.d.mts.map +1 -1
  13. package/dist/cloudflare.mjs +2 -2
  14. package/dist/{combinators-Bsd9HKtw.d.mts → combinators-BecOKcmi.d.mts} +7 -1
  15. package/dist/combinators-BecOKcmi.d.mts.map +1 -0
  16. package/dist/{combinators-CVjxodAJ.mjs → combinators-CLfsPfhT.mjs} +6 -1
  17. package/dist/combinators-CLfsPfhT.mjs.map +1 -0
  18. package/dist/{delivery-invariants-_T9ZMwOJ.mjs → delivery-invariants-BCtvzAfW.mjs} +7 -2
  19. package/dist/delivery-invariants-BCtvzAfW.mjs.map +1 -0
  20. package/dist/delivery-invariants-DzMy3iPs.d.mts +10 -0
  21. package/dist/delivery-invariants-DzMy3iPs.d.mts.map +1 -0
  22. package/dist/{explore-B7aR_5Hy.d.mts → explore-B52m-wmk.d.mts} +13 -2
  23. package/dist/explore-B52m-wmk.d.mts.map +1 -0
  24. package/dist/index.d.mts +25 -3
  25. package/dist/index.d.mts.map +1 -1
  26. package/dist/index.mjs +2 -2
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/{platform-CCz48WF9.d.mts → platform-Ba1Kvdza.d.mts} +18 -1
  29. package/dist/platform-Ba1Kvdza.d.mts.map +1 -0
  30. package/dist/provers-DS44OeEm.mjs.map +1 -1
  31. package/dist/spec.d.mts +1 -1
  32. package/dist/spec.mjs +1 -1
  33. package/dist/{src-ClXnIi6O.mjs → src-nwQA9Xwr.mjs} +9 -3
  34. package/dist/src-nwQA9Xwr.mjs.map +1 -0
  35. package/dist/{src-DPCF2XGv.mjs → src-ud5wEfnx.mjs} +9 -1
  36. package/dist/src-ud5wEfnx.mjs.map +1 -0
  37. package/dist/{workerd-DVJ8eCLI.mjs → workerd-Be43_PZo.mjs} +160 -39
  38. package/dist/workerd-Be43_PZo.mjs.map +1 -0
  39. package/package.json +1 -1
  40. package/dist/cli-BppjMaqL.mjs.map +0 -1
  41. package/dist/combinators-Bsd9HKtw.d.mts.map +0 -1
  42. package/dist/combinators-CVjxodAJ.mjs.map +0 -1
  43. package/dist/delivery-invariants-DZOBkCMR.d.mts +0 -5
  44. package/dist/delivery-invariants-DZOBkCMR.d.mts.map +0 -1
  45. package/dist/delivery-invariants-_T9ZMwOJ.mjs.map +0 -1
  46. package/dist/explore-B7aR_5Hy.d.mts.map +0 -1
  47. package/dist/platform-CCz48WF9.d.mts.map +0 -1
  48. package/dist/src-ClXnIi6O.mjs.map +0 -1
  49. package/dist/src-DPCF2XGv.mjs.map +0 -1
  50. package/dist/workerd-DVJ8eCLI.mjs.map +0 -1
@@ -1,6 +1,6 @@
1
- import { A as readFaults, E as validateScenario, I as getPath, L as canonicalJson, S as virtualEpoch, T as defaultBounds, _ as toResponse, a as explore, b as realTick, c as hostInvocation, d as InjectedEffectError, f as findResponse, g as replyOf, h as parseBody, i as proxiedSide, j as writeFaults, k as decisionFaults, l as runInvocation, m as isRedirect, n as DifferentialStuck, p as installScriptedFetch, r as compareSides, t as observeCore, u as CrashSignal, v as withoutNetwork, w as toJson, x as settleOn, y as patchGlobals } from "./src-DPCF2XGv.mjs";
2
- import { a as redelivery, i as invocationOf, n as atLeastOncePerMessage$1 } from "./delivery-invariants-_T9ZMwOJ.mjs";
3
- import { c as checkSpecModule, s as emitRegressionTest, t as renderJson, y as describeVerdict } from "./src-ClXnIi6O.mjs";
1
+ import { A as readFaults, E as validateScenario, I as getPath, L as canonicalJson, S as virtualEpoch, T as defaultBounds, _ as toResponse, a as explore, b as realTick, c as hostInvocation, d as InjectedEffectError, f as findResponse, g as replyOf, h as parseBody, i as proxiedSide, j as writeFaults, k as decisionFaults, l as runInvocation, m as isRedirect, n as DifferentialStuck, p as installScriptedFetch, r as compareSides, t as observeCore, u as CrashSignal, v as withoutNetwork, w as toJson, x as settleOn, y as patchGlobals } from "./src-ud5wEfnx.mjs";
2
+ import { a as redelivery, i as invocationOf, n as atLeastOncePerMessage$1 } from "./delivery-invariants-BCtvzAfW.mjs";
3
+ import { c as checkSpecModule, s as emitRegressionTest, t as renderJson, y as describeVerdict } from "./src-nwQA9Xwr.mjs";
4
4
  // packages/cli/src/regression.ts
5
5
  /**
6
6
  * Identifiers for binding names: a qualified name (`orders/DB`) becomes
@@ -25,9 +25,26 @@ const key = (binding) => /^[A-Za-z_$][\w$]*$/.test(binding) ? binding : JSON.str
25
25
  function cloudflareRegressionTest(verdict, options) {
26
26
  const bindings = Object.keys(options.schemaPaths).sort();
27
27
  const callees = Object.keys(options.callees ?? {}).sort();
28
- const schemaIds = identifiers(bindings);
28
+ /**
29
+ * Each binding's files, in setup order, each with an identifier of its own: the binding's name for the
30
+ * first, a count after it for the later ones, made unique across all files as `identifiers` does.
31
+ */
32
+ const taken = /* @__PURE__ */ new Set();
33
+ const files = bindings.flatMap((b) => {
34
+ const paths = options.schemaPaths[b] ?? [];
35
+ return (typeof paths === "string" ? [paths] : paths).map((path, i) => {
36
+ const base = (i === 0 ? b : `${b}_${i + 1}`).replace(/[^A-Za-z0-9_$]/g, "_");
37
+ let id = base;
38
+ for (let n = 2; taken.has(id); n++) id = `${base}_${n}`;
39
+ taken.add(id);
40
+ return {
41
+ binding: b,
42
+ path,
43
+ id
44
+ };
45
+ });
46
+ });
29
47
  const calleeIds = identifiers(callees);
30
- const ident = (binding) => schemaIds.get(binding) ?? calleeIds.get(binding) ?? binding;
31
48
  const withExports = options.exports === true || options.workflows === true;
32
49
  const imports = [
33
50
  ...callees.length === 0 || (options.calleeBindings ?? []).length === 0 ? [] : [`// Needs the callees' bindings in this test's isolate under their qualified names: ${(options.calleeBindings ?? []).join(", ")}.`, "// Declare them in the wrangler config, or run this test under the config eutaxy check --keep leaves in .eutaxy/."],
@@ -35,12 +52,16 @@ function cloudflareRegressionTest(verdict, options) {
35
52
  "import { env } from \"cloudflare:workers\";",
36
53
  ...options.durableObjects ? ["import * as cloudflareTest from \"cloudflare:test\";"] : [],
37
54
  `import scenario from ${JSON.stringify(options.scenarioPath)};`,
38
- ...bindings.map((b) => `import schema_${ident(b)} from ${JSON.stringify(`${options.schemaPaths[b]}?raw`)};`),
55
+ ...files.map((f) => `import schema_${f.id} from ${JSON.stringify(`${f.path}?raw`)};`),
39
56
  ...callees.map((b) => `import * as callee_${calleeIds.get(b)} from ${JSON.stringify(options.callees?.[b]?.path)};`),
40
57
  withExports ? `import * as worker from ${JSON.stringify(options.workerPath)};` : `import handler from ${JSON.stringify(options.workerPath)};`,
41
58
  ...(options.specModules ?? []).map((m, i) => `import * as core_${i} from ${JSON.stringify(m.path)};`)
42
59
  ];
43
- const schemas = `{ ${bindings.map((b) => `${key(b)}: schema_${ident(b)}`).join(", ")} }`;
60
+ const schemaOf = (b) => {
61
+ const own = files.filter((f) => f.binding === b).map((f) => `schema_${f.id}`);
62
+ return own.length === 1 ? own[0] : `[${own.join(", ")}].join("\\n;\\n")`;
63
+ };
64
+ const schemas = `{ ${bindings.map((b) => `${key(b)}: ${schemaOf(b)}`).join(", ")} }`;
44
65
  const calleeOption = callees.length === 0 ? "" : `, callees: { ${callees.map((b) => `${key(b)}: { name: ${JSON.stringify(options.callees?.[b]?.name)}, exports: callee_${calleeIds.get(b)}${options.callees?.[b]?.entrypoint === void 0 ? "" : `, entrypoint: ${JSON.stringify(options.callees?.[b]?.entrypoint)}`}${options.callees?.[b]?.props === void 0 ? "" : `, props: ${JSON.stringify(options.callees?.[b]?.props)}`} }`).join(", ")} }`;
45
66
  const retries = options.maxRetries === void 0 ? "" : `, maxRetries: ${options.maxRetries}`;
46
67
  const aliases = options.aliases === void 0 || Object.keys(options.aliases).length === 0 ? "" : `, aliases: ${JSON.stringify(options.aliases)}`;
@@ -92,7 +113,7 @@ async function drainBackground(hooks, inv, invocation, target, background) {
92
113
  allowed: CUT_OFF
93
114
  }, () => null, () => null);
94
115
  await Promise.race([hooks.settle(Promise.all(background), invocation), inv.crashed]);
95
- return false;
116
+ return inv.isCrashed();
96
117
  } catch (err) {
97
118
  if (!(err instanceof CrashSignal)) throw err;
98
119
  return true;
@@ -824,6 +845,25 @@ function constructEntrypoint(cls, base, ctx, env) {
824
845
  Object.setPrototypeOf(direct, original);
825
846
  }
826
847
  }
848
+ /**
849
+ * The handler object a `WorkerEntrypoint` class stands for when it is the Worker's default export: each
850
+ * of `fetch`, `queue` and `scheduled` the class defines constructs it anew with the invocation's env and
851
+ * ctx, as workerd does per event, and calls the method with the event alone (its env and ctx are on the
852
+ * instance) (developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/rpc/).
853
+ */
854
+ function entrypointHandler(cls) {
855
+ const proto = typeof cls === "function" ? cls.prototype : void 0;
856
+ const out = {};
857
+ for (const name of [
858
+ "fetch",
859
+ "queue",
860
+ "scheduled"
861
+ ]) if (typeof proto?.[name] === "function") out[name] = (event, env, ctx) => {
862
+ const instance = constructEntrypoint(cls, "WorkerEntrypoint", ctx, env);
863
+ return instance[name].call(instance, event);
864
+ };
865
+ return out;
866
+ }
827
867
  // packages/cloudflare/src/caller.ts
828
868
  /**
829
869
  * The caller of an inbound request or RPC call. Cloudflare retries neither,
@@ -1038,6 +1078,10 @@ function cronTicks(expression, from, count) {
1038
1078
  * Cloudflare shapes (queues, D1 bindings) and the effect conventions the
1039
1079
  * proxies follow.
1040
1080
  */
1081
+ /**
1082
+ * Drive the Worker's `fetch()` handler with these requests, each resent as `options` say. A request's
1083
+ * method defaults to POST with a body and GET without; its id to `req-<n>`, by position.
1084
+ */
1041
1085
  function http(requests, options = {}) {
1042
1086
  return {
1043
1087
  kind: "http",
@@ -1054,6 +1098,10 @@ function http(requests, options = {}) {
1054
1098
  ...options.deadlineMs === void 0 ? {} : { deadlineMs: options.deadlineMs }
1055
1099
  };
1056
1100
  }
1101
+ /**
1102
+ * Drive the Worker over these WebSocket connections: each opened through its `fetch()` and handed to a
1103
+ * Durable Object, its messages delivered in order to the object's `webSocketMessage` handler.
1104
+ */
1057
1105
  function websocket(connections) {
1058
1106
  return {
1059
1107
  kind: "websocket",
@@ -1071,6 +1119,7 @@ function websocket(connections) {
1071
1119
  })
1072
1120
  };
1073
1121
  }
1122
+ /** Drive a `WorkerEntrypoint` of the Worker with these method calls; a call's id defaults to `call-<n>`. */
1074
1123
  function rpc(calls, options = {}) {
1075
1124
  return {
1076
1125
  kind: "rpc",
@@ -1089,6 +1138,10 @@ function rpc(calls, options = {}) {
1089
1138
  function rpcTarget(drive, method) {
1090
1139
  return `Rpc:${drive.entrypoint === void 0 ? method : `${drive.entrypoint}.${method}`}`;
1091
1140
  }
1141
+ /**
1142
+ * Drive the Worker's `scheduled()` handler with the ticks of a Cron Trigger expression, in Cloudflare's
1143
+ * dialect: one tick by default, re-run 0 times by default.
1144
+ */
1092
1145
  function cron(expression, options = {}) {
1093
1146
  const count = options.ticks ?? 1;
1094
1147
  return {
@@ -1188,6 +1241,11 @@ function restrictDrive(drive, keepIds) {
1188
1241
  };
1189
1242
  }
1190
1243
  }
1244
+ /**
1245
+ * A Durable Object namespace the scenario uses: cleared before each run, the named objects seeded with
1246
+ * key-value entries (and with `sql`, a SQLite-backed object's tables and rows), and its storage snapshotted
1247
+ * after the run. `alarmsPerObject` caps an object's alarm firings per run (default 3).
1248
+ */
1191
1249
  function durableObject(binding, objects = {}, options = {}) {
1192
1250
  return {
1193
1251
  kind: "durable_object",
@@ -1197,6 +1255,7 @@ function durableObject(binding, objects = {}, options = {}) {
1197
1255
  ...options.sql === void 0 ? {} : { sql: options.sql }
1198
1256
  };
1199
1257
  }
1258
+ /** An R2 bucket the scenario uses: emptied before each run, then seeded with these objects by key. */
1200
1259
  function r2Bucket(binding, objects = {}) {
1201
1260
  return {
1202
1261
  kind: "r2",
@@ -1248,6 +1307,10 @@ function references(name, query, path, inQuery, column) {
1248
1307
  column
1249
1308
  };
1250
1309
  }
1310
+ /**
1311
+ * A Workflow binding and the class its instances run, an export of the Worker module; `name` is the
1312
+ * Workflow's name in the wrangler config, which instances read as `event.workflowName`.
1313
+ */
1251
1314
  function workflow(binding, className, options = {}) {
1252
1315
  return {
1253
1316
  kind: "workflow",
@@ -1256,6 +1319,10 @@ function workflow(binding, className, options = {}) {
1256
1319
  ...options.name === void 0 ? {} : { name: options.name }
1257
1320
  };
1258
1321
  }
1322
+ /**
1323
+ * Script the Worker behind a service binding: its RPC methods answer from `methods` and its `fetch()` from
1324
+ * `fetch`, and the real binding is never called. See `ServiceSetup`.
1325
+ */
1259
1326
  function service(binding, options = {}) {
1260
1327
  return {
1261
1328
  kind: "service",
@@ -1264,6 +1331,10 @@ function service(binding, options = {}) {
1264
1331
  ...options.fetch === void 0 ? {} : { fetch: [...options.fetch] }
1265
1332
  };
1266
1333
  }
1334
+ /**
1335
+ * Run the Worker behind a service binding for real, named by its module and its wrangler config, relative
1336
+ * to the scenario; `entrypoint` names the export the binding reaches. See `CalleeSetup`.
1337
+ */
1267
1338
  function callee(binding, worker) {
1268
1339
  return {
1269
1340
  kind: "callee",
@@ -1351,6 +1422,7 @@ function durableObjectTable(binding, object, table, where) {
1351
1422
  table: name
1352
1423
  };
1353
1424
  }
1425
+ /** Drive the Worker's `queue()` handler with these messages from the named queue; an id defaults to `msg-<n>`. */
1354
1426
  function queue(name, messages) {
1355
1427
  return {
1356
1428
  kind: "queue",
@@ -1361,6 +1433,10 @@ function queue(name, messages) {
1361
1433
  }))
1362
1434
  };
1363
1435
  }
1436
+ /**
1437
+ * A D1 binding the scenario uses: its tables dropped before each run and the schema file applied, relative
1438
+ * to the scenario. Several steps on one binding apply their files in order, a migration per file.
1439
+ */
1364
1440
  function d1Schema(binding, schemaFile) {
1365
1441
  return {
1366
1442
  kind: "d1",
@@ -2362,6 +2438,7 @@ function splitSql(sql) {
2362
2438
  if (c === "/" && next === "*") {
2363
2439
  const end = sql.indexOf("*/", i + 2);
2364
2440
  i = end === -1 ? sql.length : end + 2;
2441
+ cur += " ";
2365
2442
  continue;
2366
2443
  }
2367
2444
  if (c === "'" || c === "\"" || c === "`" || c === "[") {
@@ -2412,7 +2489,28 @@ function splitSql(sql) {
2412
2489
  /** Drop every user table and re-apply the schema, using the real binding (not an effect). */
2413
2490
  async function resetD1(real, schema) {
2414
2491
  const tables = await real.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '\\_cf\\_%' ESCAPE '\\'").all();
2415
- for (const { name } of tables.results) await real.prepare(`DROP TABLE IF EXISTS "${name.replace(/"/g, "\"\"")}"`).run();
2492
+ const quote = (n) => `"${n.replace(/"/g, "\"\"")}"`;
2493
+ const triggers = await real.prepare("SELECT name FROM sqlite_master WHERE type = 'trigger'").all();
2494
+ for (const { name } of triggers.results) await real.prepare(`DROP TRIGGER IF EXISTS ${quote(name)}`).run();
2495
+ const parents = /* @__PURE__ */ new Map();
2496
+ for (const { name } of tables.results) {
2497
+ const keys = await real.prepare(`PRAGMA foreign_key_list(${quote(name)})`).all();
2498
+ parents.set(name, new Set(keys.results.map((k) => k.table).filter((t) => t !== name)));
2499
+ }
2500
+ const left = new Set(parents.keys());
2501
+ for (;;) {
2502
+ const leaves = [...left].filter((t) => ![...left].some((o) => parents.get(o)?.has(t)));
2503
+ if (leaves.length === 0) break;
2504
+ for (const t of leaves) {
2505
+ await real.prepare(`DROP TABLE IF EXISTS ${quote(t)}`).run();
2506
+ left.delete(t);
2507
+ }
2508
+ }
2509
+ if (left.size > 0) {
2510
+ const cycle = [...left];
2511
+ await real.batch([real.prepare("PRAGMA defer_foreign_keys = on"), ...cycle.map((t) => real.prepare(`DELETE FROM ${quote(t)}`))]);
2512
+ await real.batch([real.prepare("PRAGMA defer_foreign_keys = on"), ...cycle.map((t) => real.prepare(`DROP TABLE IF EXISTS ${quote(t)}`))]);
2513
+ }
2416
2514
  for (const statement of splitSql(schema)) await real.prepare(statement).run();
2417
2515
  }
2418
2516
  /** Every user table's rows, sorted canonically, read through the real binding (not an effect). */
@@ -2892,13 +2990,12 @@ function validEventType(type) {
2892
2990
  if (typeof type === "string" && type.length <= 100 && /^[a-zA-Z0-9_][a-zA-Z0-9-_]*$/.test(type)) return type;
2893
2991
  throw new Error(`(workflow.invalid_event_type) event type must be up to 100 letters, digits, - or _, got ${JSON.stringify(type)}`);
2894
2992
  }
2895
- /** Thrown through `run()` to suspend an instance waiting for an event; never meant to be caught. */
2896
- var Suspension = class {
2897
- gen;
2898
- constructor(gen) {
2899
- this.gen = gen;
2900
- }
2901
- };
2993
+ /**
2994
+ * A promise that never settles: what a step call gives once its instance hibernated. The engine stops a
2995
+ * waiting instance's code where it is, so nothing after the wait runs, caught or not, until a wake re-runs
2996
+ * `run()` from the start.
2997
+ */
2998
+ const hibernated = () => new Promise(() => {});
2902
2999
  /**
2903
3000
  * Whether a run event wakes the instance: not a wake at all, the restart of a
2904
3001
  * run a wake began (its first delivery resumed the instance), or the wake of
@@ -3039,7 +3136,7 @@ async function deliverWorkflow(event, hooks, d) {
3039
3136
  b,
3040
3137
  c
3041
3138
  ];
3042
- if (suspending !== void 0) continuedAfterSuspension("step.do");
3139
+ if (suspending !== void 0) return alongsideWait("step.do");
3043
3140
  if (options?.rollback !== void 0) {
3044
3141
  hooks.unsupported(`Workflow ${d.binding}: rollback handlers are not modelled`);
3045
3142
  throw new Error("eutaxy: rollback handlers are not modelled");
@@ -3204,7 +3301,7 @@ async function deliverWorkflow(event, hooks, d) {
3204
3301
  await sleepStep(k, name, Math.max(0, at - Date.now()), at);
3205
3302
  },
3206
3303
  waitForEvent: async (name, options = {}) => {
3207
- if (suspending !== void 0) continuedAfterSuspension("step.waitForEvent");
3304
+ if (suspending !== void 0) return alongsideWait("step.waitForEvent");
3208
3305
  const type = validEventType(options.type);
3209
3306
  const timeoutMs = durationMs(options.timeout ?? "24 hours");
3210
3307
  if (!(timeoutMs >= 1e3 && timeoutMs <= 31536e6)) {
@@ -3278,18 +3375,24 @@ async function deliverWorkflow(event, hooks, d) {
3278
3375
  gen,
3279
3376
  deadline
3280
3377
  };
3281
- throw new Suspension(gen);
3378
+ hibernate();
3379
+ return hibernated();
3282
3380
  }
3283
3381
  };
3284
- /** Set once a wait suspended this run: anything the code does after it caught the suspension is not modelled. */
3382
+ /** Set once a wait hibernated this run; the run then ends with the wait, wherever its code was. */
3285
3383
  let suspending;
3286
- const continuedAfterSuspension = (what) => {
3287
- const reason = `Workflow ${d.binding}: ${what} after step.waitForEvent suspended the instance; the code caught the suspension (catch only the wait's WorkflowTimeoutError)`;
3288
- hooks.unsupported(reason);
3289
- throw new Error(`eutaxy: ${reason}`);
3384
+ /**
3385
+ * A step call once a wait hibernated the run. Code after the wait never runs (its promise never
3386
+ * settles), so the call comes from code running in parallel with the wait (`Promise.all` of a wait and
3387
+ * a step), which the engine would run while the wait is pending: not modelled, so reported, and the
3388
+ * call never settles, as the hibernated run's other calls.
3389
+ */
3390
+ const alongsideWait = (what) => {
3391
+ hooks.unsupported(`Workflow ${d.binding}: ${what} started alongside step.waitForEvent; steps running in parallel with a wait are not modelled`);
3392
+ return hibernated();
3290
3393
  };
3291
3394
  async function sleepStep(k, name, ms, until) {
3292
- if (suspending !== void 0) continuedAfterSuspension("step.sleep");
3395
+ if (suspending !== void 0) return alongsideWait("step.sleep");
3293
3396
  if (instance.persisted.has(k)) return;
3294
3397
  const pending = instance.deadlines.get(k);
3295
3398
  if (pending !== void 0) {
@@ -3319,6 +3422,10 @@ async function deliverWorkflow(event, hooks, d) {
3319
3422
  value: null
3320
3423
  });
3321
3424
  }
3425
+ let hibernate = () => {};
3426
+ const hibernation = new Promise((resolve) => {
3427
+ hibernate = () => resolve(void 0);
3428
+ });
3322
3429
  const ran = await runInvocation(hooks, inv, () => {
3323
3430
  const flow = constructWorkflow(d.cls, executionContext(background), d.env);
3324
3431
  const workflowEvent = {
@@ -3333,7 +3440,7 @@ async function deliverWorkflow(event, hooks, d) {
3333
3440
  hooks.unsupported(`Workflow ${d.binding}: event.workflowName needs the Workflow's name, workflow(binding, className, { name })`);
3334
3441
  }
3335
3442
  });
3336
- return flow.run(workflowEvent, step);
3443
+ return Promise.race([flow.run(workflowEvent, step), hibernation]);
3337
3444
  });
3338
3445
  const serialised = (value) => {
3339
3446
  try {
@@ -3350,13 +3457,10 @@ async function deliverWorkflow(event, hooks, d) {
3350
3457
  }
3351
3458
  };
3352
3459
  let result = ran.status === "completed" ? serialised(ran.value) : ran;
3353
- if (suspending !== void 0) {
3354
- if (!(ran.status === "errored" && ran.error instanceof Suspension) && ran.status !== "crashed") hooks.unsupported(`Workflow ${d.binding}: run() ${ran.status === "completed" ? "returned" : "threw"} after step.waitForEvent suspended the instance; the code caught the suspension (catch only the wait's WorkflowTimeoutError)`);
3355
- if (ran.status !== "crashed") result = {
3356
- status: "completed",
3357
- value: void 0
3358
- };
3359
- }
3460
+ if (suspending !== void 0 && ran.status !== "crashed") result = {
3461
+ status: "completed",
3462
+ value: void 0
3463
+ };
3360
3464
  let status = result.status;
3361
3465
  if (suspending !== void 0 && result.status === "completed") {
3362
3466
  instance.status = "waiting";
@@ -3685,7 +3789,7 @@ function calleeBinding(deps) {
3685
3789
  if (!p) {
3686
3790
  const module = deps.callees?.[name];
3687
3791
  if (!module) {
3688
- ctx.hooks.unsupported(`callee ${name}: the platform was not given its module; pass createCloudflarePlatform({ ..., callees: { ${name}: { name, exports } } }) (eutaxy check does not load callees yet)`);
3792
+ ctx.hooks.unsupported(`callee ${name}: the platform was not given its module; pass createCloudflarePlatform({ ..., callees: { ${name}: { name, exports } } }), as eutaxy check does from the callee() step`);
3689
3793
  return proxyService(name, ctx, {
3690
3794
  kind: "service",
3691
3795
  binding: name,
@@ -3760,9 +3864,16 @@ function serviceBinding() {
3760
3864
  */
3761
3865
  function ownedSetups(setup, bindings) {
3762
3866
  const out = [];
3867
+ const databases = /* @__PURE__ */ new Set();
3763
3868
  for (const step of setup) {
3764
3869
  const binding = bindings.find((b) => b.kind === step.kind);
3765
- if (binding) out.push([binding, step]);
3870
+ if (!binding) continue;
3871
+ if (step.kind === "d1") {
3872
+ const name = String(step["binding"]);
3873
+ if (databases.has(name)) continue;
3874
+ databases.add(name);
3875
+ }
3876
+ out.push([binding, step]);
3766
3877
  }
3767
3878
  return out;
3768
3879
  }
@@ -4553,6 +4664,11 @@ const assumptions = [
4553
4664
  "cron triggers: each tick of the drive's expression is one invocation of scheduled(), with scheduledTime the tick's virtual time (UTC, the expression's matches from the virtual epoch on, in Cloudflare's dialect where weekdays run 1 = Sunday to 7 = Saturday; L, W and # are not modelled) and cron the expression (developers.cloudflare.com/workers/runtime-apis/handlers/scheduled/, /workers/configuration/cron-triggers/); Cloudflare documents noRetry() but no retry count, so the drive declares how many times a tick whose handler failed is re-run, and none after noRetry()",
4554
4665
  "inbound RPC: one invocation per call attempt, the entrypoint constructed anew for each with a fresh ExecutionContext (developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/rpc/); the return value is the response effect, and an exception reaches the caller as a new error with its name and message (developers.cloudflare.com/workers/runtime-apis/rpc/error-handling/); Cloudflare does not retry a call, so the drive's caller resends a call that threw or got no answer as the http drive's caller does; a result that is not plain data (a stub, a function, a stream) makes the run UNSUPPORTED"
4555
4666
  ];
4667
+ /**
4668
+ * The Cloudflare platform for `check`, run inside workerd under the Cloudflare Vitest plugin: the scenario's
4669
+ * drive delivered to the Worker's handlers, its bindings proxied so every call is an effect that faults can
4670
+ * hit, and the setup's resources reset before each run and snapshotted after it.
4671
+ */
4556
4672
  function createCloudflarePlatform(options) {
4557
4673
  const env = options.env;
4558
4674
  const aliases = options.aliases ?? {};
@@ -4629,7 +4745,7 @@ function createCloudflarePlatform(options) {
4629
4745
  }
4630
4746
  });
4631
4747
  const worker = {
4632
- handler: typeof options.handler === "function" ? {} : options.handler,
4748
+ handler: typeof options.handler === "function" ? entrypointHandler(options.handler) : options.handler,
4633
4749
  env: proxiedEnv
4634
4750
  };
4635
4751
  return {
@@ -5064,7 +5180,10 @@ function globKey(path) {
5064
5180
  * meta, which the CLI reads back. It imports nothing that needs Node, so
5065
5181
  * the Cloudflare Vitest plugin can load it.
5066
5182
  */
5067
- /** Each D1 binding's schema, read from the `.sql` files next to the scenario. */
5183
+ /**
5184
+ * Each D1 binding's schema, read from the `.sql` files next to the scenario. Several `d1Schema` steps
5185
+ * on one binding (a migration per file) are joined in setup order, each file its own statements.
5186
+ */
5068
5187
  function schemasFor(scenario, sqlFiles) {
5069
5188
  const schemas = {};
5070
5189
  for (const step of scenario.setup) {
@@ -5072,7 +5191,9 @@ function schemasFor(scenario, sqlFiles) {
5072
5191
  const file = String(step["schemaFile"]);
5073
5192
  const sql = sqlFiles[globKey(file)];
5074
5193
  if (sql === void 0) throw new Error(`schema file ${file} not found next to the scenario`);
5075
- schemas[String(step["binding"])] = sql;
5194
+ const binding = String(step["binding"]);
5195
+ const earlier = schemas[binding];
5196
+ schemas[binding] = earlier === void 0 ? sql : `${earlier}\n;\n${sql}`;
5076
5197
  }
5077
5198
  return schemas;
5078
5199
  }
@@ -5197,4 +5318,4 @@ async function checkInWorkerd(input) {
5197
5318
  }
5198
5319
  export { r2Bucket as A, webSocketReceived as B, external as C, implies as D, httpResponse as E, rpc as F, cloudflareRegressionTest as G, workflow as H, rpcResponse as I, service as L, r2Rows as M, references as N, queue as O, refines as P, serviceCall as R, everyRow as S, http as T, workflowRows as U, websocket as V, workflowStep as W, d1Write as _, createCloudflarePlatform as a, durableObjectRows as b, expectHolds as c, callee as d, cron as f, d1Schema as g, d1Rows as h, runDifferential as i, r2Op as j, queueAck as k, calleeEnv as l, d1Read as m, globKey as n, snapshotD1 as o, d1Param as p, specKey as r, check as s, checkInWorkerd as t, atLeastOncePerMessage as u, defineScenario as v, fetchCall as w, durableObjectTable as x, durableObject as y, unique as z };
5199
5320
 
5200
- //# sourceMappingURL=workerd-DVJ8eCLI.mjs.map
5321
+ //# sourceMappingURL=workerd-Be43_PZo.mjs.map