eutaxy 0.13.0 → 0.14.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.
@@ -1,14 +1,14 @@
1
- import { I as canonicalJson } from "./src-DGh7w877.mjs";
2
- import { _ as render, a as renderText, c as checkSpecModule, d as shrinkRefutation, g as endpointNumber, h as endpointBigInt, i as renderSpecs, m as conforms, n as renderSpecReport, p as evaluate, r as renderSpecReportJson, v as describeType } from "./src-5pKRvj02.mjs";
1
+ import { L as canonicalJson } from "./src-DPCF2XGv.mjs";
2
+ import { _ as render, a as renderText, c as checkSpecModule, d as shrinkRefutation, g as endpointNumber, h as endpointBigInt, i as renderSpecs, m as conforms, n as renderSpecReport, p as evaluate, r as renderSpecReportJson, v as describeType } from "./src-ClXnIi6O.mjs";
3
3
  import { n as isSpec } from "./combinators-CVjxodAJ.mjs";
4
4
  import { t as aggregate } from "./provers-DS44OeEm.mjs";
5
- import { H as cloudflareRegressionTest, n as specKey } from "./workerd-BMJ-GKx8.mjs";
5
+ import { G as cloudflareRegressionTest, n as globKey, r as specKey } from "./workerd-DVJ8eCLI.mjs";
6
6
  import { createRequire, registerHooks } from "node:module";
7
7
  import { Readable } from "node:stream";
8
8
  import { createHash, randomBytes } from "node:crypto";
9
9
  import { chmodSync, closeSync, copyFileSync, createReadStream, existsSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, renameSync, rmSync, symlinkSync, writeFileSync, writeSync } from "node:fs";
10
10
  import { homedir, tmpdir } from "node:os";
11
- import { basename, dirname, join, relative, resolve, sep } from "node:path";
11
+ import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
12
12
  import { createZstdDecompress, inflateRawSync } from "node:zlib";
13
13
  import { fork, spawn } from "node:child_process";
14
14
  import { InternalSymbolName, ModifierFlags, NodeFlags, SyntaxKind, forEachLeadingCommentRange, forEachTrailingCommentRange } from "typescript/ast";
@@ -3594,7 +3594,7 @@ function readSpecs(input) {
3594
3594
  * no names of these shapes, so a function called `decide` or a parameter
3595
3595
  * called `max` stays what the author meant.
3596
3596
  */
3597
- const ident$1 = {
3597
+ const ident$2 = {
3598
3598
  fn: (name) => quote(`f_${name}`),
3599
3599
  record: (name) => quote(`R_${name}`),
3600
3600
  variable: (name) => quote(`v_${name}`),
@@ -3611,7 +3611,7 @@ function leanType(t) {
3611
3611
  case "int": return "Int";
3612
3612
  case "bool": return "Bool";
3613
3613
  case "string": return "String";
3614
- case "record": return ident$1.record(t.name);
3614
+ case "record": return ident$2.record(t.name);
3615
3615
  case "list": return `(List ${leanType(t.element)})`;
3616
3616
  case "nothing": return fail$1("the element type of an empty array, which nothing gives");
3617
3617
  case "nullable":
@@ -3621,8 +3621,8 @@ function leanType(t) {
3621
3621
  }
3622
3622
  function emitRecord(r) {
3623
3623
  return [
3624
- `structure ${ident$1.record(r.name)} where`,
3625
- ...r.fields.map((f) => ` ${ident$1.field(f.name)} : ${leanType(f.type)}`),
3624
+ `structure ${ident$2.record(r.name)} where`,
3625
+ ...r.fields.map((f) => ` ${ident$2.field(f.name)} : ${leanType(f.type)}`),
3626
3626
  " deriving Repr, DecidableEq"
3627
3627
  ].join("\n");
3628
3628
  }
@@ -3675,7 +3675,7 @@ function term$1(e, scope, env) {
3675
3675
  case "string": return leanString(e.value);
3676
3676
  case "var":
3677
3677
  if (env.cons?.list === e.name) return `(${env.cons.head} :: ${env.cons.tail})`;
3678
- return ident$1.variable(e.name);
3678
+ return ident$2.variable(e.name);
3679
3679
  case "null":
3680
3680
  case "narrow": return fail$1("null, which the Lean engine does not take yet");
3681
3681
  case "narrowTag": return fail$1("a union, which the Lean engine does not take yet");
@@ -3714,21 +3714,21 @@ function term$1(e, scope, env) {
3714
3714
  }
3715
3715
  break;
3716
3716
  case "cond": return `(if ${t(e.test)} = true then ${t(e.ifTrue)} else ${t(e.ifFalse)})`;
3717
- case "call": return `(${ident$1.fn(e.callee)}${e.args.map((a) => ` ${t(a)}`).join("")})`;
3717
+ case "call": return `(${ident$2.fn(e.callee)}${e.args.map((a) => ` ${t(a)}`).join("")})`;
3718
3718
  case "field":
3719
3719
  if (typeOf(e.object, scope, env.ctx, fail$1).kind === "list") return `(Int.ofNat (List.length ${t(e.object)}))`;
3720
- return `${t(e.object)}.${ident$1.field(e.field)}`;
3720
+ return `${t(e.object)}.${ident$2.field(e.field)}`;
3721
3721
  case "record": {
3722
3722
  const type = typeOf(e, scope, env.ctx, fail$1);
3723
- const name = type.kind === "record" ? ident$1.record(type.name) : fail$1("a record literal of no record type");
3724
- return `({ ${e.fields.map((f) => `${ident$1.field(f.name)} := ${t(f.value)}`).join(", ")} } : ${name})`;
3723
+ const name = type.kind === "record" ? ident$2.record(type.name) : fail$1("a record literal of no record type");
3724
+ return `({ ${e.fields.map((f) => `${ident$2.field(f.name)} := ${t(f.value)}`).join(", ")} } : ${name})`;
3725
3725
  }
3726
3726
  case "let": {
3727
3727
  const inner = new Map(scope);
3728
3728
  const bound = e.type ?? typeOf(e.value, scope, env.ctx, fail$1);
3729
3729
  inner.set(e.name, bound);
3730
3730
  const annotated = e.type ? ` : ${leanType(e.type)}` : "";
3731
- return `(let ${ident$1.variable(e.name)}${annotated} := ${t(e.value)}; ${term$1(e.body, inner, env)})`;
3731
+ return `(let ${ident$2.variable(e.name)}${annotated} := ${t(e.value)}; ${term$1(e.body, inner, env)})`;
3732
3732
  }
3733
3733
  case "list":
3734
3734
  if (e.items.length === 0 && !e.rest) return "[]";
@@ -3748,7 +3748,7 @@ function term$1(e, scope, env) {
3748
3748
  if (e.index !== void 0) inner.set(e.index, { kind: "int" });
3749
3749
  const body = term$1(e.body, inner, env);
3750
3750
  const nat = e.index === void 0 ? "" : quote(`nv_${e.index}`);
3751
- const fn = e.index === void 0 ? `(fun ${ident$1.variable(e.item)} => ${body})` : `(fun (${ident$1.variable(e.item)}, ${nat}) => let ${ident$1.variable(e.index)} := Int.ofNat ${nat}; ${body})`;
3751
+ const fn = e.index === void 0 ? `(fun ${ident$2.variable(e.item)} => ${body})` : `(fun (${ident$2.variable(e.item)}, ${nat}) => let ${ident$2.variable(e.index)} := Int.ofNat ${nat}; ${body})`;
3752
3752
  const list = e.index === void 0 ? t(e.list) : `(List.zipIdx ${t(e.list)})`;
3753
3753
  if (e.op === "map") return `(List.map ${fn} ${list})`;
3754
3754
  if (e.op === "flatMap") return `(List.flatMap ${fn} ${list})`;
@@ -3760,15 +3760,15 @@ function term$1(e, scope, env) {
3760
3760
  const inner = new Map(scope);
3761
3761
  inner.set(e.acc, typeOf(e, scope, env.ctx, fail$1));
3762
3762
  inner.set(e.item, listType.element);
3763
- return `(List.foldl (fun ${ident$1.variable(e.acc)} ${ident$1.variable(e.item)} => ${term$1(e.body, inner, env)}) ${t(e.init)} ${t(e.list)})`;
3763
+ return `(List.foldl (fun ${ident$2.variable(e.acc)} ${ident$2.variable(e.item)} => ${term$1(e.body, inner, env)}) ${t(e.init)} ${t(e.list)})`;
3764
3764
  }
3765
3765
  }
3766
3766
  }
3767
3767
  function emitFunction$1(f, module) {
3768
3768
  const e = env$1(module);
3769
3769
  const scope = new Map(f.params.map((p) => [p.name, p.type]));
3770
- const params = f.params.map((p) => `(${ident$1.variable(p.name)} : ${leanType(p.type)})`).join(" ");
3771
- const head = `def ${ident$1.fn(f.name)} ${params} : ${leanType(f.returns)} :=`;
3770
+ const params = f.params.map((p) => `(${ident$2.variable(p.name)} : ${leanType(p.type)})`).join(" ");
3771
+ const head = `def ${ident$2.fn(f.name)} ${params} : ${leanType(f.returns)} :=`;
3772
3772
  if (f.structural === void 0 || f.body.kind !== "cond") return `${head}\n ${term$1(f.body, scope, e)}`;
3773
3773
  const list = f.params[f.structural].name;
3774
3774
  const cons = {
@@ -3778,7 +3778,7 @@ function emitFunction$1(f, module) {
3778
3778
  };
3779
3779
  return [
3780
3780
  head,
3781
- ` match ${ident$1.variable(list)} with`,
3781
+ ` match ${ident$2.variable(list)} with`,
3782
3782
  ` | [] => ${term$1(f.body.ifTrue, scope, e)}`,
3783
3783
  ` | ${cons.head} :: ${cons.tail} => ${term$1(f.body.ifFalse, scope, {
3784
3784
  ...e,
@@ -3861,7 +3861,7 @@ function stated(property, module) {
3861
3861
  if (property.kind !== "forall" || !property.ensures) fail$1("not a forall property");
3862
3862
  const e = env$1(module);
3863
3863
  const types = property.binders.map((b) => binderType$1(b.name, b.type, module));
3864
- const binders = property.binders.map((b, i) => `(${ident$1.variable(b.name)} : ${leanType(types[i])})`).join(" ");
3864
+ const binders = property.binders.map((b, i) => `(${ident$2.variable(b.name)} : ${leanType(types[i])})`).join(" ");
3865
3865
  const hyps = property.when ? [`(${arrowTerm$1(property.when, "when", property, types, e)} = true)`] : [];
3866
3866
  const claim = `(${arrowTerm$1(property.ensures, "ensures", property, types, e)} = true)`;
3867
3867
  const body = [...hyps, claim].join(" →\n ");
@@ -3881,10 +3881,10 @@ function stated(property, module) {
3881
3881
  * the statement.
3882
3882
  */
3883
3883
  function tactics(module, property, hypotheses) {
3884
- const defs = module.functions.map((f) => ident$1.fn(f.name)).join(", ");
3885
- const names = property.binders.map((b) => ident$1.variable(b.name));
3884
+ const defs = module.functions.map((f) => ident$2.fn(f.name)).join(", ");
3885
+ const names = property.binders.map((b) => ident$2.variable(b.name));
3886
3886
  const hyps = Array.from({ length: hypotheses }, (_, i) => `h${i}_`);
3887
- const bools = property.binders.filter((b) => b.type.kind === "boolean" || b.type.kind === "literal" && typeof b.type.value === "boolean").map((b) => ident$1.variable(b.name));
3887
+ const bools = property.binders.filter((b) => b.type.kind === "boolean" || b.type.kind === "literal" && typeof b.type.value === "boolean").map((b) => ident$2.variable(b.name));
3888
3888
  const introduced = [...names, ...hyps];
3889
3889
  return [
3890
3890
  ...introduced.length > 0 ? [` intro ${introduced.join(" ")}`] : [],
@@ -4523,7 +4523,7 @@ function renderGoals(input) {
4523
4523
  `${specHashMarker}${input.specSha256}`
4524
4524
  ];
4525
4525
  const described = input.goals.map((g) => [
4526
- commentLine(`-- goal: ${g.property}, a property of ${ident$1.fn(g.function)}`),
4526
+ commentLine(`-- goal: ${g.property}, a property of ${ident$2.fn(g.function)}`),
4527
4527
  commentLine(`-- Lean said: ${g.reason}`),
4528
4528
  "-- statement:",
4529
4529
  comment(g.statement.replace(/^/gm, " "))
@@ -4855,7 +4855,7 @@ function symbol(name) {
4855
4855
  return /^[A-Za-z~!@$%^&*_+=<>.?/-][A-Za-z0-9~!@$%^&*_+=<>.?/-]*$/.test(escaped) ? escaped : `|${escaped}|`;
4856
4856
  }
4857
4857
  /** TypeScript names as SMT symbols that cannot clash with each other or with the theories' names. */
4858
- const ident = {
4858
+ const ident$1 = {
4859
4859
  fn: (name) => symbol(`f_${name}`),
4860
4860
  /** The datatype of a record, or of a union. */
4861
4861
  record: (name) => symbol(`R_${name}`),
@@ -4879,8 +4879,8 @@ function sortName(t, module) {
4879
4879
  case "bool": return "Bool";
4880
4880
  case "string": return "Str";
4881
4881
  case "record":
4882
- case "union": return ident.record(t.name);
4883
- case "nullable": return ident.option(sortName(t.inner, module));
4882
+ case "union": return ident$1.record(t.name);
4883
+ case "nullable": return ident$1.option(sortName(t.inner, module));
4884
4884
  case "null": return fail("null has no sort of its own");
4885
4885
  }
4886
4886
  }
@@ -4898,7 +4898,7 @@ function sort(t, module) {
4898
4898
  }
4899
4899
  /** A constructor applied: a bare symbol when there are no arguments. */
4900
4900
  function construct(name, values) {
4901
- return values.length === 0 ? ident.constructor(name) : `(${ident.constructor(name)} ${values.join(" ")})`;
4901
+ return values.length === 0 ? ident$1.constructor(name) : `(${ident$1.constructor(name)} ${values.join(" ")})`;
4902
4902
  }
4903
4903
  /** A double as a floating-point literal. */
4904
4904
  function numberTerm(n) {
@@ -4958,7 +4958,7 @@ function sameAs(a, b, t, env) {
4958
4958
  case "string": return `(= ${a} ${b})`;
4959
4959
  case "nullable": {
4960
4960
  const base = sortName(t.inner, env.module);
4961
- return `(ite (and (${tester(ident.some(base))} ${a}) (${tester(ident.some(base))} ${b})) ${sameAs(`(${ident.val(base)} ${a})`, `(${ident.val(base)} ${b})`, t.inner, env)} (and (${tester(ident.none(base))} ${a}) (${tester(ident.none(base))} ${b})))`;
4961
+ return `(ite (and (${tester(ident$1.some(base))} ${a}) (${tester(ident$1.some(base))} ${b})) ${sameAs(`(${ident$1.val(base)} ${a})`, `(${ident$1.val(base)} ${b})`, t.inner, env)} (and (${tester(ident$1.none(base))} ${a}) (${tester(ident$1.none(base))} ${b})))`;
4962
4962
  }
4963
4963
  case "record":
4964
4964
  case "union":
@@ -4972,16 +4972,16 @@ function sameAs(a, b, t, env) {
4972
4972
  * union. Anything else is already of the sort wanted.
4973
4973
  */
4974
4974
  function lift(inner, actual, want, module) {
4975
- if (want.kind === "union" && actual.kind === "record") return `(${ident.inject(want.name, actual.name)} ${inner})`;
4975
+ if (want.kind === "union" && actual.kind === "record") return `(${ident$1.inject(want.name, actual.name)} ${inner})`;
4976
4976
  if (want.kind !== "nullable") return inner;
4977
4977
  if (actual.kind === "null") return inner;
4978
4978
  if (actual.kind === "nullable") {
4979
4979
  if (want.inner.kind !== "union" || actual.inner.kind !== "record") return inner;
4980
4980
  const from = sortName(actual.inner, module);
4981
4981
  const to = sortName(want.inner, module);
4982
- return `(ite (${tester(ident.none(from))} ${inner}) ${ident.none(to)} (${ident.some(to)} ${lift(`(${ident.val(from)} ${inner})`, actual.inner, want.inner, module)}))`;
4982
+ return `(ite (${tester(ident$1.none(from))} ${inner}) ${ident$1.none(to)} (${ident$1.some(to)} ${lift(`(${ident$1.val(from)} ${inner})`, actual.inner, want.inner, module)}))`;
4983
4983
  }
4984
- return `(${ident.some(sortName(want.inner, module))} ${lift(inner, actual, want.inner, module)})`;
4984
+ return `(${ident$1.some(sortName(want.inner, module))} ${lift(inner, actual, want.inner, module)})`;
4985
4985
  }
4986
4986
  /**
4987
4987
  * A term of the expression's type, or of `expected` where one is given:
@@ -5018,15 +5018,15 @@ function term(e, scope, env, expected) {
5018
5018
  case "string": return stringTerm(e.value);
5019
5019
  case "null":
5020
5020
  if (expected?.kind !== "nullable") fail("null where no nullable type is expected");
5021
- return ident.none(sortName(expected.inner, env.module));
5022
- case "var": return ident.variable(e.name);
5021
+ return ident$1.none(sortName(expected.inner, env.module));
5022
+ case "var": return ident$1.variable(e.name);
5023
5023
  case "narrow": {
5024
5024
  const nt = scope.get(e.name);
5025
5025
  if (nt?.kind !== "nullable") fail(`${e.name} is narrowed but is not a nullable`);
5026
5026
  const base = sortName(nt.inner, env.module);
5027
5027
  const inner = new Map(scope);
5028
5028
  inner.set(e.name, nt.inner);
5029
- return `(let ((${ident.variable(e.name)} (${ident.val(base)} ${ident.variable(e.name)}))) ${narrowed(e.body, inner)})`;
5029
+ return `(let ((${ident$1.variable(e.name)} (${ident$1.val(base)} ${ident$1.variable(e.name)}))) ${narrowed(e.body, inner)})`;
5030
5030
  }
5031
5031
  case "narrowTag": {
5032
5032
  const nt = scope.get(e.name);
@@ -5036,8 +5036,8 @@ function term(e, scope, env, expected) {
5036
5036
  kind: "record",
5037
5037
  name: e.member
5038
5038
  });
5039
- const v = ident.variable(e.name);
5040
- return `(let ((${v} (${ident.project(nt.name, e.member)} ${v}))) ${narrowed(e.body, inner)})`;
5039
+ const v = ident$1.variable(e.name);
5040
+ return `(let ((${v} (${ident$1.project(nt.name, e.member)} ${v}))) ${narrowed(e.body, inner)})`;
5041
5041
  }
5042
5042
  case "neg": return `(fp.neg ${t(e.operand)})`;
5043
5043
  case "not": return `(not ${t(e.operand)})`;
@@ -5062,13 +5062,13 @@ function term(e, scope, env, expected) {
5062
5062
  const side = lt.kind === "null" ? e.right : e.left;
5063
5063
  const st = lt.kind === "null" ? rt : lt;
5064
5064
  if (st.kind !== "nullable") fail("a comparison with null of something that is not nullable");
5065
- eq = `(${tester(ident.none(sortName(st.inner, env.module)))} ${t(side)})`;
5065
+ eq = `(${tester(ident$1.none(sortName(st.inner, env.module)))} ${t(side)})`;
5066
5066
  } else if (lt.kind === "nullable" && rt.kind !== "nullable") {
5067
5067
  const base = sortName(lt.inner, env.module);
5068
- eq = `(and (${tester(ident.some(base))} ${t(e.left)}) ${sameAs(`(${ident.val(base)} ${t(e.left)})`, t(e.right), lt.inner, env)})`;
5068
+ eq = `(and (${tester(ident$1.some(base))} ${t(e.left)}) ${sameAs(`(${ident$1.val(base)} ${t(e.left)})`, t(e.right), lt.inner, env)})`;
5069
5069
  } else if (rt.kind === "nullable" && lt.kind !== "nullable") {
5070
5070
  const base = sortName(rt.inner, env.module);
5071
- eq = `(and (${tester(ident.some(base))} ${t(e.right)}) ${sameAs(t(e.left), `(${ident.val(base)} ${t(e.right)})`, rt.inner, env)})`;
5071
+ eq = `(and (${tester(ident$1.some(base))} ${t(e.right)}) ${sameAs(t(e.left), `(${ident$1.val(base)} ${t(e.right)})`, rt.inner, env)})`;
5072
5072
  } else eq = sameAs(t(e.left), t(e.right), lt, env);
5073
5073
  return e.op === "===" ? eq : `(not ${eq})`;
5074
5074
  }
@@ -5084,17 +5084,17 @@ function term(e, scope, env, expected) {
5084
5084
  case "call": {
5085
5085
  const sig = env.ctx.signatures.get(e.callee) ?? fail(`no signature for ${e.callee}`);
5086
5086
  const args = e.args.map((a, i) => coerce(a, sig.params[i].type));
5087
- return args.length === 0 ? ident.fn(e.callee) : `(${ident.fn(e.callee)} ${args.join(" ")})`;
5087
+ return args.length === 0 ? ident$1.fn(e.callee) : `(${ident$1.fn(e.callee)} ${args.join(" ")})`;
5088
5088
  }
5089
5089
  case "field": {
5090
5090
  const o = typed(e.object);
5091
5091
  const obj = t(e.object);
5092
5092
  if (o.kind === "union") return membersOf(o.name, env).reduceRight((rest, m) => {
5093
- const read = `(${ident.field(m.name, e.field)} (${ident.project(o.name, m.name)} ${obj}))`;
5094
- return rest === void 0 ? read : `(ite (${tester(ident.inject(o.name, m.name))} ${obj}) ${read} ${rest})`;
5093
+ const read = `(${ident$1.field(m.name, e.field)} (${ident$1.project(o.name, m.name)} ${obj}))`;
5094
+ return rest === void 0 ? read : `(ite (${tester(ident$1.inject(o.name, m.name))} ${obj}) ${read} ${rest})`;
5095
5095
  }, void 0);
5096
5096
  if (o.kind !== "record") fail(`field ${e.field} read from a ${o.kind}`);
5097
- return `(${ident.field(o.name, e.field)} ${obj})`;
5097
+ return `(${ident$1.field(o.name, e.field)} ${obj})`;
5098
5098
  }
5099
5099
  case "record": {
5100
5100
  const type = typed(e);
@@ -5110,20 +5110,20 @@ function term(e, scope, env, expected) {
5110
5110
  const bound = e.type ?? typed(e.value);
5111
5111
  inner.set(e.name, bound);
5112
5112
  const value = e.type ? coerce(e.value, e.type) : t(e.value);
5113
- return `(let ((${ident.variable(e.name)} ${value})) ${narrowed(e.body, inner)})`;
5113
+ return `(let ((${ident$1.variable(e.name)} ${value})) ${narrowed(e.body, inner)})`;
5114
5114
  }
5115
5115
  }
5116
5116
  }
5117
5117
  function emitFunction(f, module) {
5118
5118
  const e = env(module);
5119
5119
  const scope = new Map(f.params.map((p) => [p.name, p.type]));
5120
- const params = f.params.map((p) => `(${ident.variable(p.name)} ${sort(p.type, module)})`).join(" ");
5120
+ const params = f.params.map((p) => `(${ident$1.variable(p.name)} ${sort(p.type, module)})`).join(" ");
5121
5121
  const body = (() => {
5122
5122
  const b = f.body;
5123
5123
  if (b.kind === "cond" || b.kind === "let" || b.kind === "narrow" || b.kind === "narrowTag" || b.kind === "null") return term(b, scope, e, f.returns);
5124
5124
  return lift(term(b, scope, e, f.returns), typeOf(b, scope, e.ctx, fail), f.returns, module);
5125
5125
  })();
5126
- return `(define-fun ${ident.fn(f.name)} (${params}) ${sort(f.returns, module)}\n ${body})`;
5126
+ return `(define-fun ${ident$1.fn(f.name)} (${params}) ${sort(f.returns, module)}\n ${body})`;
5127
5127
  }
5128
5128
  /**
5129
5129
  * An option sort over every sort the module could mention: the primitives,
@@ -5160,16 +5160,16 @@ function emitDatatypes(module) {
5160
5160
  const unions = module.unions;
5161
5161
  const options = optionSorts(module);
5162
5162
  const names = [
5163
- ...plain.map((r) => ident.record(r.name)),
5164
- ...unions.map((u) => ident.record(u.name)),
5165
- ...[...options.keys()].map((base) => ident.option(base))
5163
+ ...plain.map((r) => ident$1.record(r.name)),
5164
+ ...unions.map((u) => ident$1.record(u.name)),
5165
+ ...[...options.keys()].map((base) => ident$1.option(base))
5166
5166
  ];
5167
5167
  if (names.length === 0) return "";
5168
- const constructorOf = (r) => `(${ident.constructor(r.name)}${r.fields.map((f) => ` (${ident.field(r.name, f.name)} ${sort(f.type, module)})`).join("")})`;
5168
+ const constructorOf = (r) => `(${ident$1.constructor(r.name)}${r.fields.map((f) => ` (${ident$1.field(r.name, f.name)} ${sort(f.type, module)})`).join("")})`;
5169
5169
  const bodies = [
5170
5170
  ...plain.map((r) => `(${constructorOf(r)})`),
5171
- ...unions.map((u) => `(${u.members.map((m) => `(${ident.inject(u.name, m.record)} (${ident.project(u.name, m.record)} ${ident.record(m.record)}))`).join(" ")})`),
5172
- ...[...options].map(([base, inner]) => `((${ident.none(base)}) (${ident.some(base)} (${ident.val(base)} ${sort(inner, module)})))`)
5171
+ ...unions.map((u) => `(${u.members.map((m) => `(${ident$1.inject(u.name, m.record)} (${ident$1.project(u.name, m.record)} ${ident$1.record(m.record)}))`).join(" ")})`),
5172
+ ...[...options].map(([base, inner]) => `((${ident$1.none(base)}) (${ident$1.some(base)} (${ident$1.val(base)} ${sort(inner, module)})))`)
5173
5173
  ];
5174
5174
  return `(declare-datatypes (${names.map((n) => `(${n} 0)`).join(" ")}) (${bodies.join(" ")}))`;
5175
5175
  }
@@ -5300,15 +5300,15 @@ function wellFormed(target, t, module) {
5300
5300
  case "null": return;
5301
5301
  case "nullable": {
5302
5302
  const base = sortName(t.inner, module);
5303
- const inner = wellFormed(`(${ident.val(base)} ${target})`, t.inner, module);
5304
- return inner === void 0 ? void 0 : `(or (${tester(ident.none(base))} ${target}) ${inner})`;
5303
+ const inner = wellFormed(`(${ident$1.val(base)} ${target})`, t.inner, module);
5304
+ return inner === void 0 ? void 0 : `(or (${tester(ident$1.none(base))} ${target}) ${inner})`;
5305
5305
  }
5306
5306
  case "record": {
5307
5307
  const rec = module.records.find((r) => r.name === t.name);
5308
5308
  if (!rec) return void 0;
5309
5309
  const parts = [];
5310
5310
  for (const f of rec.fields) {
5311
- const read = `(${ident.field(rec.name, f.name)} ${target})`;
5311
+ const read = `(${ident$1.field(rec.name, f.name)} ${target})`;
5312
5312
  if (f.literal !== void 0) parts.push(typeof f.literal === "string" ? `(= ${read} ${stringTerm(f.literal)})` : `(= ${read} ${f.literal ? "true" : "false"})`);
5313
5313
  const inner = wellFormed(read, f.type, module);
5314
5314
  if (inner !== void 0) parts.push(inner);
@@ -5319,8 +5319,8 @@ function wellFormed(target, t, module) {
5319
5319
  const u = module.unions.find((x) => x.name === t.name);
5320
5320
  if (!u) return void 0;
5321
5321
  return `(or ${u.members.map((m) => {
5322
- const is = `(${tester(ident.inject(u.name, m.record))} ${target})`;
5323
- const inner = wellFormed(`(${ident.project(u.name, m.record)} ${target})`, {
5322
+ const is = `(${tester(ident$1.inject(u.name, m.record))} ${target})`;
5323
+ const inner = wellFormed(`(${ident$1.project(u.name, m.record)} ${target})`, {
5324
5324
  kind: "record",
5325
5325
  name: m.record
5326
5326
  }, module);
@@ -5351,8 +5351,8 @@ function domainConstraint(symbolName, t, subset, module) {
5351
5351
  };
5352
5352
  if (subset.kind === "nullable") {
5353
5353
  const base = sortName(subset.inner, module);
5354
- const some = `(and (${tester(ident.some(base))} ${symbolName}) ${over(`(${ident.val(base)} ${symbolName})`)})`;
5355
- return withNull ? `(or (${tester(ident.none(base))} ${symbolName}) ${some})` : some;
5354
+ const some = `(and (${tester(ident$1.some(base))} ${symbolName}) ${over(`(${ident$1.val(base)} ${symbolName})`)})`;
5355
+ return withNull ? `(or (${tester(ident$1.none(base))} ${symbolName}) ${some})` : some;
5356
5356
  }
5357
5357
  return over(symbolName);
5358
5358
  }
@@ -5401,7 +5401,7 @@ function propertyScript(property, module) {
5401
5401
  const types = property.binders.map((b) => binderType(b.name, b.type, module));
5402
5402
  const binders = property.binders.map((b, i) => ({
5403
5403
  name: b.name,
5404
- symbol: ident.variable(b.name),
5404
+ symbol: ident$1.variable(b.name),
5405
5405
  type: types[i]
5406
5406
  }));
5407
5407
  return {
@@ -5516,15 +5516,15 @@ function decode(x, t, module) {
5516
5516
  case "string": return decodeString(x);
5517
5517
  case "nullable": {
5518
5518
  const base = sortName(t.inner, module);
5519
- if (x === ident.none(base)) return null;
5520
- if (Array.isArray(x) && x[0] === ident.some(base) && x.length === 2) return decode(x[1], t.inner, module);
5519
+ if (x === ident$1.none(base)) return null;
5520
+ if (Array.isArray(x) && x[0] === ident$1.some(base) && x.length === 2) return decode(x[1], t.inner, module);
5521
5521
  throw new UnreadableModel(`not a ${describeSubset(t)}: ${show(x)}`);
5522
5522
  }
5523
5523
  case "union": {
5524
5524
  const u = module.unions.find((y) => y.name === t.name);
5525
5525
  if (!u) throw new UnreadableModel(`no union ${t.name}`);
5526
5526
  const head = Array.isArray(x) ? x[0] : x;
5527
- const member = u.members.find((m) => ident.inject(u.name, m.record) === head);
5527
+ const member = u.members.find((m) => ident$1.inject(u.name, m.record) === head);
5528
5528
  if (!member || !Array.isArray(x) || x.length !== 2) throw new UnreadableModel(`not a ${t.name}: ${show(x)}`);
5529
5529
  return decode(x[1], {
5530
5530
  kind: "record",
@@ -5534,8 +5534,8 @@ function decode(x, t, module) {
5534
5534
  case "record": {
5535
5535
  const rec = module.records.find((r) => r.name === t.name);
5536
5536
  if (!rec) throw new UnreadableModel(`no record ${t.name}`);
5537
- if (rec.fields.length === 0 && x === ident.constructor(t.name)) return {};
5538
- if (!Array.isArray(x) || x[0] !== ident.constructor(t.name) || x.length !== rec.fields.length + 1) throw new UnreadableModel(`not a ${t.name}: ${show(x)}`);
5537
+ if (rec.fields.length === 0 && x === ident$1.constructor(t.name)) return {};
5538
+ if (!Array.isArray(x) || x[0] !== ident$1.constructor(t.name) || x.length !== rec.fields.length + 1) throw new UnreadableModel(`not a ${t.name}: ${show(x)}`);
5539
5539
  const out = {};
5540
5540
  rec.fields.forEach((f, i) => {
5541
5541
  out[f.name] = decode(x[i + 1], f.type, module);
@@ -5976,12 +5976,536 @@ const smtProver = {
5976
5976
  },
5977
5977
  prove: (input) => proveModule(input)
5978
5978
  };
5979
+ // packages/cli/src/resolve.ts
5980
+ /**
5981
+ * Relative imports from a `.ts` file that Node cannot resolve are tried as
5982
+ * TypeScript resolves them, so `./domain.js` and `./domain` find `domain.ts`
5983
+ * (or `domain/index.ts`), as `tsc` and Vite would. Used where the command
5984
+ * imports a user's module in Node: `eutaxy report` for spec modules, `eutaxy
5985
+ * check` for a scenario that names callees.
5986
+ */
5987
+ let registered = false;
5988
+ /** Register the hook once per process. */
5989
+ function resolveAsTypeScript() {
5990
+ if (registered) return;
5991
+ registered = true;
5992
+ registerHooks({ resolve(specifier, context, nextResolve) {
5993
+ try {
5994
+ return nextResolve(specifier, context);
5995
+ } catch (err) {
5996
+ if (!(specifier.startsWith("./") || specifier.startsWith("../")) || !context.parentURL?.endsWith(".ts")) throw err;
5997
+ const stem = specifier.endsWith(".js") ? specifier.slice(0, -3) : specifier;
5998
+ for (const candidate of [`${stem}.ts`, `${stem}/index.ts`]) try {
5999
+ return nextResolve(candidate, context);
6000
+ } catch {}
6001
+ throw err;
6002
+ }
6003
+ } });
6004
+ }
6005
+ // packages/cli/src/callees.ts
6006
+ /**
6007
+ * The callees a scenario names (`callee()` steps), read on the Node side for
6008
+ * `eutaxy check`. Each callee's wrangler config gives its Worker's name and
6009
+ * its bindings; the command adds them to the test's isolate under qualified
6010
+ * names (`<name>/<binding>`): the main module it generates re-exports the
6011
+ * caller's exports as they are and the callees' Durable Object and Workflow
6012
+ * classes under qualified aliases, and the Vitest config's miniflare options
6013
+ * add the callees' resources. Probed inside workerd (2026-11): the plugin
6014
+ * takes a `main` beside the caller's `wrangler.configPath`, miniflare options
6015
+ * add to and override the wrangler config's bindings, and wrangler, miniflare
6016
+ * and workerd accept a slash in a binding name.
6017
+ */
6018
+ /** The `callee` steps of a setup, as the scenario wrote them. */
6019
+ function calleeSteps(setup) {
6020
+ return setup.filter((s) => s.kind === "callee").map((s) => ({
6021
+ binding: String(s["binding"]),
6022
+ entry: String(s["entry"]),
6023
+ config: String(s["config"]),
6024
+ ...s["entrypoint"] === void 0 ? {} : { entrypoint: String(s["entrypoint"]) }
6025
+ }));
6026
+ }
6027
+ /**
6028
+ * Whether the scenario's source names a callee at all: the command imports
6029
+ * the scenario module in Node only then, since reading its steps needs it.
6030
+ */
6031
+ function mentionsCallee(scenarioSource) {
6032
+ return /\bcallee\s*\(/.test(scenarioSource);
6033
+ }
6034
+ /** The argument that makes a process started on this module load one scenario and report it. */
6035
+ const scenarioFlag = "--eutaxy-load-scenario";
6036
+ /** Inside the child: import the scenario and keep what the command reads. */
6037
+ async function loadHere(scenarioPath) {
6038
+ resolveAsTypeScript();
6039
+ const spec = (await import(pathToFileURL(scenarioPath).href)).default;
6040
+ if (!spec || !Array.isArray(spec.setup) || typeof spec.worker?.entry !== "string") throw new Error("the scenario module's default export is not a scenario");
6041
+ return {
6042
+ setup: spec.setup,
6043
+ worker: spec.worker
6044
+ };
6045
+ }
6046
+ const send$1 = process.send?.bind(process);
6047
+ if (process.argv[2] === scenarioFlag && send$1) {
6048
+ process.once("disconnect", () => process.exit(0));
6049
+ process.once("message", async (scenarioPath) => {
6050
+ let output;
6051
+ try {
6052
+ output = {
6053
+ kind: "eutaxy-scenario",
6054
+ scenario: await loadHere(scenarioPath)
6055
+ };
6056
+ } catch (err) {
6057
+ output = {
6058
+ kind: "eutaxy-scenario-error",
6059
+ message: String(err)
6060
+ };
6061
+ }
6062
+ send$1(output, () => process.exit(0));
6063
+ });
6064
+ }
6065
+ /** How long a scenario module may take to load before the command gives up on it. */
6066
+ const loadBudgetMs = 6e4;
6067
+ /**
6068
+ * Import the scenario module in Node and return its setup and Worker, in a
6069
+ * child process started on this module (as `eutaxy report` loads modules):
6070
+ * a long-lived process (the MCP server) would otherwise get Node's cached
6071
+ * module after the scenario or what it imports changed. Relative imports
6072
+ * are resolved as TypeScript resolves them (`./setup.js` and `./setup` find
6073
+ * `setup.ts`). Rejects with what the import threw.
6074
+ */
6075
+ function loadScenario(scenarioPath) {
6076
+ return new Promise((resolveLoad, reject) => {
6077
+ const child = fork(fileURLToPath(import.meta.url), [scenarioFlag], {
6078
+ stdio: [
6079
+ "ignore",
6080
+ "ignore",
6081
+ "pipe",
6082
+ "ipc"
6083
+ ],
6084
+ serialization: "advanced"
6085
+ });
6086
+ let errors = "";
6087
+ child.stderr?.on("data", (d) => {
6088
+ errors += d.toString();
6089
+ });
6090
+ let settled = false;
6091
+ const settle = (outcome) => {
6092
+ if (settled) return;
6093
+ settled = true;
6094
+ clearTimeout(timer);
6095
+ outcome();
6096
+ };
6097
+ const timer = setTimeout(() => {
6098
+ child.kill("SIGKILL");
6099
+ settle(() => reject(/* @__PURE__ */ new Error(`the scenario module did not load within ${loadBudgetMs} ms`)));
6100
+ }, loadBudgetMs);
6101
+ child.on("message", (output) => {
6102
+ settle(() => {
6103
+ if (output.kind === "eutaxy-scenario") resolveLoad(output.scenario);
6104
+ else reject(new Error(output.message));
6105
+ });
6106
+ });
6107
+ child.once("error", (err) => settle(() => reject(err)));
6108
+ child.once("close", (code, signal) => settle(() => reject(/* @__PURE__ */ new Error(`the scenario module's process ended (${signal ?? `exit ${code}`}) before reporting${errors ? `:\n${errors}` : ""}`))));
6109
+ child.send(scenarioPath);
6110
+ });
6111
+ }
6112
+ /** The qualified names the callees' bindings get in the isolate, for a regression test's note. */
6113
+ function isolateBindings(callees) {
6114
+ const names = [];
6115
+ for (const c of callees) {
6116
+ for (const d of c.d1) names.push(qualified(c.name, d.binding));
6117
+ for (const b of c.r2) names.push(qualified(c.name, b.binding));
6118
+ for (const k of c.kv) names.push(qualified(c.name, k.binding));
6119
+ for (const o of c.durableObjects) if (o.scriptName === void 0) names.push(qualified(c.name, o.binding));
6120
+ for (const w of c.workflows) names.push(qualified(c.name, w.binding));
6121
+ for (const s of c.services) names.push(qualified(c.name, s));
6122
+ for (const q of c.queues) names.push(qualified(c.name, q.binding));
6123
+ for (const v of Object.keys(c.vars)) names.push(qualified(c.name, v));
6124
+ }
6125
+ return names;
6126
+ }
6127
+ /**
6128
+ * JSON with comments and trailing commas, as wrangler.jsonc allows: comments
6129
+ * are removed outside strings, a comma before `}` or `]` dropped, and the
6130
+ * rest is JSON.
6131
+ */
6132
+ function parseJsonc(text) {
6133
+ let out = "";
6134
+ let i = 0;
6135
+ /** The index of the next character that is neither whitespace nor inside a comment, from `from`. */
6136
+ const nextToken = (from) => {
6137
+ let k = from;
6138
+ for (;;) {
6139
+ while (k < text.length && /\s/.test(text[k])) k++;
6140
+ if (text[k] === "/" && text[k + 1] === "/") while (k < text.length && text[k] !== "\n") k++;
6141
+ else if (text[k] === "/" && text[k + 1] === "*") {
6142
+ const end = text.indexOf("*/", k + 2);
6143
+ k = end < 0 ? text.length : end + 2;
6144
+ } else return k;
6145
+ }
6146
+ };
6147
+ while (i < text.length) {
6148
+ const c = text[i];
6149
+ if (c === "\"") {
6150
+ let j = i + 1;
6151
+ while (j < text.length && text[j] !== "\"") j += text[j] === "\\" ? 2 : 1;
6152
+ out += text.slice(i, j + 1);
6153
+ i = j + 1;
6154
+ } else if (c === "/" && text[i + 1] === "/") while (i < text.length && text[i] !== "\n") i++;
6155
+ else if (c === "/" && text[i + 1] === "*") {
6156
+ const end = text.indexOf("*/", i + 2);
6157
+ i = end < 0 ? text.length : end + 2;
6158
+ } else if (c === ",") {
6159
+ const next = text[nextToken(i + 1)];
6160
+ if (next !== "}" && next !== "]") out += c;
6161
+ i++;
6162
+ } else {
6163
+ out += c;
6164
+ i++;
6165
+ }
6166
+ }
6167
+ return JSON.parse(out);
6168
+ }
6169
+ /** Read a wrangler config as an object; only JSON and JSONC are read here. */
6170
+ function readWranglerConfig(path) {
6171
+ const ext = extname(path);
6172
+ if (ext !== ".json" && ext !== ".jsonc") throw new Error(`${basename(path)}: eutaxy check reads a callee's wrangler config as JSON or JSONC; a TOML config is not read`);
6173
+ const parsed = parseJsonc(readFileSync(path, "utf8"));
6174
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`${basename(path)}: not a wrangler config object`);
6175
+ return parsed;
6176
+ }
6177
+ const list = (v) => Array.isArray(v) ? v.filter((x) => typeof x === "object" && x) : [];
6178
+ const str$1 = (v, fallback = "") => typeof v === "string" ? v : fallback;
6179
+ /** The keys of a wrangler config whose bindings the command carries into the isolate. */
6180
+ const carried = /* @__PURE__ */ new Set([
6181
+ "name",
6182
+ "main",
6183
+ "compatibility_date",
6184
+ "compatibility_flags",
6185
+ "d1_databases",
6186
+ "r2_buckets",
6187
+ "kv_namespaces",
6188
+ "durable_objects",
6189
+ "migrations",
6190
+ "workflows",
6191
+ "services",
6192
+ "queues",
6193
+ "vars",
6194
+ "$schema",
6195
+ "observability",
6196
+ "triggers",
6197
+ "routes",
6198
+ "route",
6199
+ "workers_dev",
6200
+ "account_id",
6201
+ "placement",
6202
+ "limits",
6203
+ "upload_source_maps",
6204
+ "minify",
6205
+ "keep_vars",
6206
+ "preview_urls"
6207
+ ]);
6208
+ /** Read a callee's wrangler config into what the isolate needs; `scenarioDir` resolves the step's paths. */
6209
+ function readCalleeConfig(step, scenarioDir) {
6210
+ const path = resolve(scenarioDir, step.config);
6211
+ const config = readWranglerConfig(path);
6212
+ const name = str$1(config["name"]);
6213
+ if (!name) throw new Error(`${basename(path)}: the callee's wrangler config has no name, which qualifies its bindings`);
6214
+ const notAdded = [];
6215
+ const sqlite = /* @__PURE__ */ new Set();
6216
+ const strings = (v) => Array.isArray(v) ? v.filter((x) => typeof x === "string") : [];
6217
+ for (const m of list(config["migrations"])) {
6218
+ for (const c of strings(m["new_sqlite_classes"])) sqlite.add(c);
6219
+ for (const r of list(m["renamed_classes"])) {
6220
+ const from = str$1(r["from"]);
6221
+ if (sqlite.delete(from)) sqlite.add(str$1(r["to"]));
6222
+ }
6223
+ for (const c of strings(m["deleted_classes"])) sqlite.delete(c);
6224
+ }
6225
+ const durableObjects = [];
6226
+ const dos = config["durable_objects"];
6227
+ for (const b of list(dos?.bindings)) {
6228
+ const className = str$1(b["class_name"]);
6229
+ const scriptName = b["script_name"] === void 0 ? void 0 : str$1(b["script_name"]);
6230
+ durableObjects.push({
6231
+ binding: str$1(b["name"]),
6232
+ className,
6233
+ sqlite: sqlite.has(className),
6234
+ ...scriptName === void 0 ? {} : { scriptName }
6235
+ });
6236
+ }
6237
+ const queues = config["queues"];
6238
+ for (const key of Object.keys(config)) if (!carried.has(key)) notAdded.push(key);
6239
+ const vars = {};
6240
+ const rawVars = config["vars"];
6241
+ if (typeof rawVars === "object" && rawVars !== null) for (const [k, v] of Object.entries(rawVars)) vars[k] = v;
6242
+ return {
6243
+ binding: step.binding,
6244
+ name,
6245
+ entry: resolve(scenarioDir, step.entry),
6246
+ d1: list(config["d1_databases"]).map((d) => ({
6247
+ binding: str$1(d["binding"]),
6248
+ id: str$1(d["database_id"], str$1(d["database_name"], str$1(d["binding"])))
6249
+ })),
6250
+ r2: list(config["r2_buckets"]).map((b) => ({
6251
+ binding: str$1(b["binding"]),
6252
+ bucket: str$1(b["bucket_name"], str$1(b["binding"]))
6253
+ })),
6254
+ kv: list(config["kv_namespaces"]).map((k) => ({
6255
+ binding: str$1(k["binding"]),
6256
+ id: str$1(k["id"], str$1(k["binding"]))
6257
+ })),
6258
+ durableObjects,
6259
+ workflows: list(config["workflows"]).map((w) => ({
6260
+ binding: str$1(w["binding"]),
6261
+ className: str$1(w["class_name"]),
6262
+ name: str$1(w["name"], str$1(w["binding"]))
6263
+ })),
6264
+ services: list(config["services"]).map((s) => str$1(s["binding"])),
6265
+ queues: list(queues?.producers).map((p) => ({
6266
+ binding: str$1(p["binding"]),
6267
+ queue: str$1(p["queue"])
6268
+ })),
6269
+ vars,
6270
+ sqliteClasses: [...sqlite],
6271
+ notAdded
6272
+ };
6273
+ }
6274
+ /** A Worker's name as an identifier prefix (`my-worker` → `my_worker`, `1st` → `_1st`). */
6275
+ const ident = (s) => {
6276
+ const safe = s.replace(/[^A-Za-z0-9_$]/g, "_");
6277
+ return /^[A-Za-z_$]/.test(safe) ? safe : `_${safe}`;
6278
+ };
6279
+ /** The export name a callee's class gets in the generated main module. */
6280
+ function classAlias(worker, className) {
6281
+ return `${ident(worker)}__${className}`;
6282
+ }
6283
+ /** The qualified name of a callee's binding. */
6284
+ function qualified(worker, binding) {
6285
+ return `${worker}/${binding}`;
6286
+ }
6287
+ function toPosix$1(p) {
6288
+ const s = p.split("\\").join("/");
6289
+ return s.startsWith(".") ? s : `./${s}`;
6290
+ }
6291
+ /**
6292
+ * The main module the plugin runs: the caller's exports as they are, and
6293
+ * each callee's Durable Object and Workflow classes under qualified aliases,
6294
+ * so the miniflare options can bind them. workerd constructs those classes
6295
+ * with the main Worker's env, so each alias is a subclass handing its parent
6296
+ * the callee's view of it (`calleeEnv`), under which `this.env.DB` is the
6297
+ * callee's `<name>/DB`.
6298
+ */
6299
+ function mainModuleSource(workDir, callerEntry, callees, isolate = noIsolate) {
6300
+ const caller = toPosix$1(relative(workDir, callerEntry));
6301
+ const lines = [
6302
+ "// Generated by eutaxy check; deleted after the run.",
6303
+ `export * from ${JSON.stringify(caller)};`,
6304
+ `export { default } from ${JSON.stringify(caller)};`
6305
+ ];
6306
+ const adapters = [];
6307
+ const emitted = /* @__PURE__ */ new Set();
6308
+ callees.forEach((c, i) => {
6309
+ const classes = [
6310
+ ...c.durableObjects.filter((d) => d.scriptName === void 0).map((d) => d.className),
6311
+ ...c.workflows.map((w) => w.className),
6312
+ ...isolate.extraClasses[c.name] ?? []
6313
+ ];
6314
+ const unique = [...new Set(classes)].filter((n) => n && !emitted.has(classAlias(c.name, n)));
6315
+ if (unique.length === 0) return;
6316
+ lines.push(`import { ${unique.map((n) => `${n} as callee${i}_${n}`).join(", ")} } from ${JSON.stringify(toPosix$1(relative(workDir, c.entry)))};`);
6317
+ const own = Object.fromEntries(Object.entries(isolate.aliases).filter(([k]) => k.startsWith(`${c.name}/`)));
6318
+ const view = `calleeEnv(${JSON.stringify(c.name)}, env${Object.keys(own).length === 0 ? "" : `, ${JSON.stringify(own)}`})`;
6319
+ for (const n of unique) {
6320
+ emitted.add(classAlias(c.name, n));
6321
+ adapters.push(`export class ${classAlias(c.name, n)} extends callee${i}_${n} {`, ` constructor(ctx: unknown, env: object) {`, ` super(ctx as never, ${view} as never);`, ` }`, `}`);
6322
+ }
6323
+ });
6324
+ if (adapters.length > 0) lines.splice(1, 0, "import { calleeEnv } from \"eutaxy/cloudflare\";");
6325
+ return `${[...lines, ...adapters].join("\n")}\n`;
6326
+ }
6327
+ /** The name the generated config gives the function answering a service binding nobody calls. */
6328
+ const neverCalled = "neverCalled";
6329
+ /**
6330
+ * The miniflare options adding the callees' resources under qualified names,
6331
+ * as source (an object literal) for the generated Vitest config. Service
6332
+ * bindings, the caller's to its callees and the callees' own, are answered
6333
+ * by a function of the config's (`neverCalled`): the Worker the caller's
6334
+ * config names is not in the isolate, a worker name given through these
6335
+ * options must be one the plugin knows, and the binding is never called
6336
+ * anyway (the scenario names a callee for it or scripts it); its value is a
6337
+ * Fetcher all the same, which is what the platform recognises.
6338
+ */
6339
+ function miniflareOptionsSource(callees, isolate = noIsolate) {
6340
+ const d1 = {};
6341
+ const r2 = {};
6342
+ const kv = {};
6343
+ const dos = {};
6344
+ const workflows = {};
6345
+ const services = {};
6346
+ const queues = {};
6347
+ const vars = {};
6348
+ const aliased = (name) => name in isolate.aliases;
6349
+ Object.assign(dos, isolate.redirected);
6350
+ for (const c of callees) {
6351
+ for (const d of c.d1) if (!aliased(qualified(c.name, d.binding))) d1[qualified(c.name, d.binding)] = d.id;
6352
+ for (const b of c.r2) if (!aliased(qualified(c.name, b.binding))) r2[qualified(c.name, b.binding)] = b.bucket;
6353
+ for (const k of c.kv) if (!aliased(qualified(c.name, k.binding))) kv[qualified(c.name, k.binding)] = k.id;
6354
+ for (const o of c.durableObjects) {
6355
+ if (o.scriptName !== void 0 || aliased(qualified(c.name, o.binding))) continue;
6356
+ dos[qualified(c.name, o.binding)] = {
6357
+ className: classAlias(c.name, o.className),
6358
+ ...o.sqlite ? { useSQLite: true } : {}
6359
+ };
6360
+ }
6361
+ for (const w of c.workflows) workflows[qualified(c.name, w.binding)] = {
6362
+ name: w.name,
6363
+ className: classAlias(c.name, w.className)
6364
+ };
6365
+ services[c.binding] = neverCalled;
6366
+ for (const s of c.services) services[qualified(c.name, s)] = neverCalled;
6367
+ for (const q of c.queues) queues[qualified(c.name, q.binding)] = q.queue;
6368
+ for (const [k, v] of Object.entries(c.vars)) vars[qualified(c.name, k)] = v;
6369
+ }
6370
+ const options = {};
6371
+ const add = (key, value) => {
6372
+ if (Object.keys(value).length > 0) options[key] = value;
6373
+ };
6374
+ add("d1Databases", d1);
6375
+ add("r2Buckets", r2);
6376
+ add("kvNamespaces", kv);
6377
+ add("durableObjects", dos);
6378
+ add("workflows", workflows);
6379
+ add("queueProducers", queues);
6380
+ add("bindings", vars);
6381
+ const data = JSON.stringify(options);
6382
+ const bindings = Object.keys(services);
6383
+ if (bindings.length === 0) return data;
6384
+ const literal = `"serviceBindings":{${bindings.map((b) => `${JSON.stringify(b)}:${neverCalled}`).join(",")}}`;
6385
+ return data === "{}" ? `{${literal}}` : `${data.slice(0, -1)},${literal}}`;
6386
+ }
6387
+ /** The caller's resources from its wrangler config, when the config can be read (JSON or JSONC); none otherwise. */
6388
+ function readCallerResources(wranglerPath) {
6389
+ try {
6390
+ const config = readWranglerConfig(wranglerPath);
6391
+ const dos = config["durable_objects"];
6392
+ return {
6393
+ name: str$1(config["name"]) || void 0,
6394
+ d1: list(config["d1_databases"]).map((d) => ({
6395
+ binding: str$1(d["binding"]),
6396
+ id: str$1(d["database_id"], str$1(d["database_name"], str$1(d["binding"])))
6397
+ })),
6398
+ r2: list(config["r2_buckets"]).map((b) => ({
6399
+ binding: str$1(b["binding"]),
6400
+ bucket: str$1(b["bucket_name"], str$1(b["binding"]))
6401
+ })),
6402
+ kv: list(config["kv_namespaces"]).map((k) => ({
6403
+ binding: str$1(k["binding"]),
6404
+ id: str$1(k["id"], str$1(k["binding"]))
6405
+ })),
6406
+ durableObjects: list(dos?.bindings).map((b) => ({
6407
+ binding: str$1(b["name"]),
6408
+ className: str$1(b["class_name"]),
6409
+ ...b["script_name"] === void 0 ? {} : { scriptName: str$1(b["script_name"]) }
6410
+ })),
6411
+ services: list(config["services"]).map((b) => ({
6412
+ binding: str$1(b["binding"]),
6413
+ ...typeof b["entrypoint"] === "string" ? { entrypoint: b["entrypoint"] } : {},
6414
+ ...typeof b["props"] === "object" && b["props"] !== null ? { props: b["props"] } : {}
6415
+ }))
6416
+ };
6417
+ } catch {
6418
+ return;
6419
+ }
6420
+ }
6421
+ /** What the caller's binding to a callee carries (its entrypoint and props), for the test to pass with the module. */
6422
+ function bindingCarries(caller, binding) {
6423
+ const s = caller?.services.find((x) => x.binding === binding);
6424
+ return {
6425
+ ...s?.entrypoint === void 0 ? {} : { entrypoint: s.entrypoint },
6426
+ ...s?.props === void 0 ? {} : { props: s.props }
6427
+ };
6428
+ }
6429
+ /**
6430
+ * The isolate's shared resources, from the two configs: a callee binding
6431
+ * that names a resource the caller binds too (the same `database_id`,
6432
+ * `bucket_name` or KV `id`; a Durable Object class of the caller's script,
6433
+ * or a caller binding to a class of the callee's script) is an alias of the
6434
+ * caller's binding, set up and snapshotted under the caller's name; a
6435
+ * caller's binding to a callee's class is redirected to the generated alias
6436
+ * class. What a callee binds in a third Worker's script is named as not
6437
+ * added.
6438
+ */
6439
+ function isolateOf(callees, caller) {
6440
+ const aliases = {};
6441
+ const redirected = {};
6442
+ const extraClasses = {};
6443
+ const notAdded = [];
6444
+ const alias = (name, own) => {
6445
+ if (own !== name) aliases[name] = own;
6446
+ };
6447
+ for (const c of callees) {
6448
+ if (caller) {
6449
+ for (const d of c.d1) {
6450
+ const own = caller.d1.find((x) => x.id === d.id);
6451
+ if (own) alias(qualified(c.name, d.binding), own.binding);
6452
+ }
6453
+ for (const b of c.r2) {
6454
+ const own = caller.r2.find((x) => x.bucket === b.bucket);
6455
+ if (own) alias(qualified(c.name, b.binding), own.binding);
6456
+ }
6457
+ for (const k of c.kv) {
6458
+ const own = caller.kv.find((x) => x.id === k.id);
6459
+ if (own) alias(qualified(c.name, k.binding), own.binding);
6460
+ }
6461
+ for (const o of caller.durableObjects) {
6462
+ if (o.scriptName !== c.name) continue;
6463
+ const theirs = c.durableObjects.find((x) => x.className === o.className && x.scriptName === void 0);
6464
+ redirected[o.binding] = {
6465
+ className: classAlias(c.name, o.className),
6466
+ ...c.sqliteClasses.includes(o.className) ? { useSQLite: true } : {}
6467
+ };
6468
+ if (theirs) alias(qualified(c.name, theirs.binding), o.binding);
6469
+ else {
6470
+ const extra = extraClasses[c.name] ?? [];
6471
+ extra.push(o.className);
6472
+ extraClasses[c.name] = extra;
6473
+ }
6474
+ }
6475
+ }
6476
+ for (const o of c.durableObjects) {
6477
+ if (o.scriptName === void 0) continue;
6478
+ const own = caller && o.scriptName === caller.name ? caller.durableObjects.find((x) => x.className === o.className && x.scriptName === void 0) : void 0;
6479
+ if (own) alias(qualified(c.name, o.binding), own.binding);
6480
+ else notAdded.push(`${c.binding}: durable_objects binding ${o.binding} (script_name ${o.scriptName}: a class of another Worker)`);
6481
+ }
6482
+ }
6483
+ return {
6484
+ aliases,
6485
+ redirected,
6486
+ extraClasses,
6487
+ notAdded
6488
+ };
6489
+ }
6490
+ /** An isolate with nothing shared. */
6491
+ const noIsolate = {
6492
+ aliases: {},
6493
+ redirected: {},
6494
+ extraClasses: {},
6495
+ notAdded: []
6496
+ };
6497
+ /** Where a callee's config path and entry sit, for messages. */
6498
+ function describeCallee(c, scenarioDir) {
6499
+ return `${c.binding} (${c.name}, ${toPosix$1(relative(scenarioDir, c.entry))})`;
6500
+ }
5979
6501
  // packages/cli/src/generate.ts
5980
6502
  /**
5981
6503
  * The files `eutaxy check` writes into `<scenario dir>/.eutaxy/` before
5982
6504
  * running Vitest: a test that performs the check inside workerd and prints
5983
6505
  * the verdict on one marked line, and a Vitest config with the Cloudflare
5984
- * plugin pointed at the scenario's wrangler config.
6506
+ * plugin pointed at the scenario's wrangler config. For a scenario with
6507
+ * callees the test imports their modules, the config names a generated main
6508
+ * module and adds their resources through miniflare options (`callees.ts`).
5985
6509
  */
5986
6510
  /** Key under which the generated test stores its result in the Vitest task meta, read back from the JSON reporter. */
5987
6511
  const metaKey = "eutaxy";
@@ -5992,29 +6516,37 @@ const metaKey = "eutaxy";
5992
6516
  */
5993
6517
  function checkTestSource(g) {
5994
6518
  const options = `seed: ${JSON.stringify(g.seed)}` + (g.maxRuns === void 0 ? "" : `, maxRuns: ${g.maxRuns}`) + (g.budgetMs === void 0 ? "" : `, budgetMs: ${g.budgetMs}`) + (g.exhaustive ? ", exhaustive: true" : "");
6519
+ const callees = g.callees ?? [];
6520
+ const sqlImports = g.sqlImports ?? [];
6521
+ const calleeImports = callees.map((c, i) => `import * as callee_${i} from ${JSON.stringify(c.importPath)};\n`);
6522
+ const sqlImportLines = sqlImports.map((f, i) => `import sql_${i} from ${JSON.stringify(`${f.importPath}?raw`)};\n`);
6523
+ const calleesOption = callees.length === 0 ? "" : `, callees: { ${callees.map((c, i) => `${JSON.stringify(c.binding)}: { name: ${JSON.stringify(c.name)}, exports: callee_${i}${c.entrypoint === void 0 ? "" : `, entrypoint: ${JSON.stringify(c.entrypoint)}`}${c.props === void 0 ? "" : `, props: ${JSON.stringify(c.props)}`} }`).join(", ")} }`;
6524
+ const extraSql = sqlImports.length === 0 ? "" : `, extraSql: { ${sqlImports.map((f, i) => `${JSON.stringify(f.key)}: sql_${i}`).join(", ")} }`;
6525
+ const aliases = g.aliases === void 0 || Object.keys(g.aliases).length === 0 ? "" : `, aliases: ${JSON.stringify(g.aliases)}`;
5995
6526
  return `// Generated by eutaxy check; deleted after the run.
5996
6527
  import { checkInWorkerd } from "eutaxy/cloudflare";
5997
6528
  import { env } from "cloudflare:workers";
5998
6529
  import * as durableObjects from "cloudflare:test";
5999
6530
  import { test } from "vitest";
6000
6531
  import scenario from ${JSON.stringify(g.scenarioImport)};
6001
- import { specEntries } from "./specs.ts";
6532
+ ${calleeImports.join("")}${sqlImportLines.join("")}import { specEntries } from "./specs.ts";
6002
6533
 
6003
6534
  const sqlFiles = import.meta.glob("../**/*.sql", { query: "?raw", import: "default", eager: true }) as Record<string, string>;
6004
6535
  const modules = import.meta.glob(["../**/*.ts", "!../**/*.test.ts", "!../**/*.sim.ts", "!../**/node_modules/**", "!../**/.eutaxy/**"]);
6005
6536
 
6006
6537
  test("eutaxy check", async ({ task }) => {
6007
- task.meta[${JSON.stringify(metaKey)}] = await checkInWorkerd({ scenario, env, durableObjects, sqlFiles, modules, specEntries, ${options} });
6538
+ task.meta[${JSON.stringify(metaKey)}] = await checkInWorkerd({ scenario, env, durableObjects, sqlFiles, modules, specEntries${calleesOption}${extraSql}${aliases}, ${options} });
6008
6539
  });
6009
6540
  `;
6010
6541
  }
6011
- function vitestConfigSource(wranglerConfigPath, testPath, outputFile) {
6542
+ function vitestConfigSource(wranglerConfigPath, testPath, outputFile, isolate) {
6543
+ const plugin = isolate === void 0 ? `cloudflareTest({ wrangler: { configPath: ${JSON.stringify(wranglerConfigPath)} } })` : `cloudflareTest({ main: ${JSON.stringify(isolate.main)}, wrangler: { configPath: ${JSON.stringify(wranglerConfigPath)} }, miniflare: ${isolate.miniflare} })`;
6012
6544
  return `// Generated by eutaxy check; deleted after the run.
6013
6545
  import { cloudflareTest } from "@cloudflare/vitest-plugin";
6014
6546
  import { defineConfig } from "vitest/config";
6015
6547
 
6016
- export default defineConfig({
6017
- plugins: [cloudflareTest({ wrangler: { configPath: ${JSON.stringify(wranglerConfigPath)} } })],
6548
+ ${isolate === void 0 ? "" : `const ${neverCalled} = () => new Response("eutaxy: a service binding the scenario scripts or runs as a callee is never called", { status: 500 });\n\n`}export default defineConfig({
6549
+ plugins: [${plugin}],
6018
6550
  test: {
6019
6551
  include: [${JSON.stringify(testPath)}],
6020
6552
  testTimeout: 600_000,
@@ -6240,14 +6772,48 @@ async function runCheck(o) {
6240
6772
  const workDir = join(dir, ".eutaxy");
6241
6773
  const testPath = join(workDir, `${name}.${stamp}.check.test.ts`);
6242
6774
  const configPath = join(workDir, `vitest.config.${stamp}.mts`);
6775
+ const mainPath = join(workDir, `main.${stamp}.ts`);
6776
+ let callees = [];
6777
+ let loaded;
6778
+ if (mentionsCallee(readFileSync(scenarioPath, "utf8"))) {
6779
+ try {
6780
+ loaded = await loadScenario(scenarioPath);
6781
+ callees = calleeSteps(loaded.setup).map((step) => readCalleeConfig(step, dir));
6782
+ } catch (err) {
6783
+ o.stderr(`could not read the scenario's callees: ${String(err)}\n`);
6784
+ return exitCodes.error;
6785
+ }
6786
+ for (const c of callees) if (c.notAdded.length > 0) o.stderr(`callee ${describeCallee(c, dir)}: not added to the test's isolate: ${c.notAdded.join(", ")}\n`);
6787
+ }
6788
+ const callerResources = callees.length > 0 ? readCallerResources(wrangler) : void 0;
6789
+ const isolate = isolateOf(callees, callerResources);
6790
+ for (const reason of isolate.notAdded) o.stderr(`not added to the test's isolate: ${reason}\n`);
6243
6791
  mkdirSync(workDir, { recursive: true });
6244
6792
  try {
6793
+ const sqlImports = [];
6794
+ if (callees.length > 0 && loaded) for (const step of loaded.setup) {
6795
+ if (step.kind !== "d1") continue;
6796
+ const file = String(step["schemaFile"]);
6797
+ if (!relative(dir, resolve(dir, file)).startsWith("..")) continue;
6798
+ sqlImports.push({
6799
+ key: globKey(file),
6800
+ importPath: toPosix(relative(workDir, resolve(dir, file)))
6801
+ });
6802
+ }
6245
6803
  writeFileSync(testPath, checkTestSource({
6246
6804
  seed: o.seed ?? name,
6247
6805
  ...o.maxRuns === void 0 ? {} : { maxRuns: o.maxRuns },
6248
6806
  ...o.budgetMs === void 0 ? {} : { budgetMs: o.budgetMs },
6249
6807
  ...o.exhaustive ? { exhaustive: true } : {},
6250
- scenarioImport: `../${basename(scenarioPath)}`
6808
+ scenarioImport: `../${basename(scenarioPath)}`,
6809
+ ...callees.length === 0 ? {} : { callees: callees.map((c) => ({
6810
+ binding: c.binding,
6811
+ name: c.name,
6812
+ importPath: toPosix(relative(workDir, c.entry)),
6813
+ ...bindingCarries(callerResources, c.binding)
6814
+ })) },
6815
+ ...sqlImports.length === 0 ? {} : { sqlImports },
6816
+ ...Object.keys(isolate.aliases).length === 0 ? {} : { aliases: isolate.aliases }
6251
6817
  }));
6252
6818
  const specModules = findSpecModules(dir);
6253
6819
  for (const f of specFiles(specModules, workDir)) {
@@ -6256,7 +6822,14 @@ async function runCheck(o) {
6256
6822
  }
6257
6823
  const reportPath = join(workDir, `vitest-report.${stamp}.json`);
6258
6824
  rmSync(reportPath, { force: true });
6259
- writeFileSync(configPath, vitestConfigSource(wrangler, testPath, reportPath));
6825
+ if (callees.length > 0 && loaded) {
6826
+ const callerEntry = resolve(dir, loaded.worker.entry);
6827
+ writeFileSync(mainPath, mainModuleSource(workDir, callerEntry, callees, isolate));
6828
+ writeFileSync(configPath, vitestConfigSource(wrangler, testPath, reportPath, {
6829
+ main: mainPath,
6830
+ miniflare: miniflareOptionsSource(callees, isolate)
6831
+ }));
6832
+ } else writeFileSync(configPath, vitestConfigSource(wrangler, testPath, reportPath));
6260
6833
  const { code, output } = await runVitest(vitestBin(dir), configPath, dir);
6261
6834
  const transport = code === 0 ? readTransport(reportPath) : null;
6262
6835
  if (!transport) {
@@ -6291,10 +6864,26 @@ async function runCheck(o) {
6291
6864
  const outDir = dirname(outPath);
6292
6865
  const schemaPaths = {};
6293
6866
  for (const step of transport.setup) if (step.kind === "d1") schemaPaths[String(step["binding"])] = toPosix(relative(outDir, resolve(dir, String(step["schemaFile"]))));
6867
+ const calleePaths = {};
6868
+ for (const step of transport.setup) {
6869
+ if (step.kind !== "callee") continue;
6870
+ const binding = String(step["binding"]);
6871
+ const carried = transport.callees?.[binding];
6872
+ if (carried === void 0) continue;
6873
+ calleePaths[binding] = {
6874
+ ...carried,
6875
+ path: toPosix(relative(outDir, resolve(dir, String(step["entry"]))))
6876
+ };
6877
+ }
6294
6878
  const source = cloudflareRegressionTest(verdict, {
6295
6879
  scenarioPath: toPosix(relative(outDir, scenarioPath)),
6296
6880
  workerPath: toPosix(relative(outDir, resolve(dir, transport.worker.entry))),
6297
6881
  schemaPaths,
6882
+ ...Object.keys(calleePaths).length === 0 ? {} : {
6883
+ callees: calleePaths,
6884
+ calleeBindings: isolateBindings(callees).filter((b) => !(b in isolate.aliases)),
6885
+ ...transport.aliases === void 0 ? {} : { aliases: transport.aliases }
6886
+ },
6298
6887
  ...o.budgetMs === void 0 ? {} : { budgetMs: o.budgetMs },
6299
6888
  ...transport.setup.some((s) => s.kind === "durable_object") ? { durableObjects: true } : {},
6300
6889
  ...transport.setup.some((s) => s.kind === "workflow") || transport.drive?.kind === "rpc" && transport.drive["entrypoint"] !== void 0 ? { exports: true } : {},
@@ -6864,25 +7453,6 @@ function unknownAll(m, cause, reason) {
6864
7453
  assumptions: []
6865
7454
  })));
6866
7455
  }
6867
- /**
6868
- * Inside the module's process: a relative import from a `.ts` file that Node cannot
6869
- * resolve is tried as TypeScript resolves it, so `./domain.js` and
6870
- * `./domain` find `domain.ts` (or `domain/index.ts`), as `tsc` would.
6871
- */
6872
- function resolveAsTypeScript() {
6873
- registerHooks({ resolve(specifier, context, nextResolve) {
6874
- try {
6875
- return nextResolve(specifier, context);
6876
- } catch (err) {
6877
- if (!(specifier.startsWith("./") || specifier.startsWith("../")) || !context.parentURL?.endsWith(".ts")) throw err;
6878
- const stem = specifier.endsWith(".js") ? specifier.slice(0, -3) : specifier;
6879
- for (const candidate of [`${stem}.ts`, `${stem}/index.ts`]) try {
6880
- return nextResolve(candidate, context);
6881
- } catch {}
6882
- throw err;
6883
- }
6884
- } });
6885
- }
6886
7456
  /** Inside the module's process: load the module and its spec file, run the `TESTED` rung. */
6887
7457
  async function testHere(m, seed) {
6888
7458
  resolveAsTypeScript();
@@ -7052,7 +7622,7 @@ async function runReport(o) {
7052
7622
  }
7053
7623
  // packages/cli/src/version.ts
7054
7624
  /** The published package's version, as the MCP server reports it; the release tooling keeps it in step. */
7055
- const eutaxyVersion = "0.13.0";
7625
+ const eutaxyVersion = "0.14.0";
7056
7626
  // packages/cli/src/mcp.ts
7057
7627
  /**
7058
7628
  * `eutaxy mcp`: a Model Context Protocol server over stdio, so a coding
@@ -7699,4 +8269,4 @@ async function main(argv, io) {
7699
8269
  }
7700
8270
  export { main as t };
7701
8271
 
7702
- //# sourceMappingURL=cli-D3SPblWw.mjs.map
8272
+ //# sourceMappingURL=cli-BppjMaqL.mjs.map