eutaxy 0.16.0 → 0.16.1

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,6 +1,6 @@
1
- import { A as writeFaults, C as toJson, F as getPath, I as invocationOf, L as redelivery, O as decisionFaults, R as canonicalJson, T as validateScenario, _ as replyOf, a as explore, b as realTick, c as decide, d as runInvocation, f as CrashSignal, g as parseBody, h as isRedirect, i as rawRun, k as readFaults, l as hostInvocation, m as findResponse, n as compareSides, p as InjectedEffectError, r as proxiedSide, t as observeCore, u as note, v as toResponse, w as defaultBounds, x as virtualEpoch, y as withoutNetwork } from "./src-CmHdPsZy.mjs";
2
- import { n as atLeastOncePerMessage$1 } from "./delivery-invariants-90c5xBcd.mjs";
3
- import { c as checkSpecModule, s as emitRegressionTest, t as renderJson, y as describeVerdict } from "./src-Dz9Wn2vL.mjs";
1
+ import { A as writeFaults, C as toJson, F as getPath, I as invocationOf, L as redelivery, O as decisionFaults, R as canonicalJson, T as validateScenario, _ as replyOf, a as explore, b as realTick, c as decide, d as runInvocation, f as CrashSignal, g as parseBody, h as isRedirect, i as rawRun, k as readFaults, l as hostInvocation, m as findResponse, n as compareSides, p as InjectedEffectError, r as proxiedSide, t as observeCore, u as note, v as toResponse, w as defaultBounds, x as virtualEpoch, y as withoutNetwork } from "./src-dkn6Illb.mjs";
2
+ import { n as atLeastOncePerMessage$1 } from "./delivery-invariants-BfRnb9yR.mjs";
3
+ import { c as checkSpecModule, s as emitRegressionTest, t as renderJson, y as describeVerdict } from "./src-DWRaG5aV.mjs";
4
4
  // packages/cli/src/regression.ts
5
5
  /**
6
6
  * Identifiers for binding names: a qualified name (`orders/DB`) becomes
@@ -119,6 +119,179 @@ async function drainBackground(hooks, inv, invocation, target, background) {
119
119
  return true;
120
120
  }
121
121
  }
122
+ // packages/cloudflare/src/proxy-context.ts
123
+ /** The effect point of a proxied call: the invocation running now, the binding's target, the call. */
124
+ function pointAt(ctx, target, op, args, allowed) {
125
+ return {
126
+ invocation: ctx.currentInvocation(),
127
+ target,
128
+ op,
129
+ args,
130
+ allowed
131
+ };
132
+ }
133
+ /** Report why the run cannot be trusted and refuse the call with the same reason. */
134
+ function refuse(ctx, reason) {
135
+ ctx.hooks.unsupported(reason);
136
+ throw new Error(`eutaxy: ${reason}`);
137
+ }
138
+ // packages/cloudflare/src/services.ts
139
+ /**
140
+ * Service bindings with the callee scripted. A Worker reaches a peer through
141
+ * `env.BINDING`, by RPC method or by `fetch()`; Cloudflare routes the call on
142
+ * the same thread and retries nothing (Workers, service bindings). The real
143
+ * binding is never called here: the scenario's `service()` setup scripts the
144
+ * replies, and each call is one effect with the faults of a Durable Object
145
+ * stub call, where `crash_before` and `error` mean the call never reached
146
+ * the callee, `ambiguous` that it acted and the answer was lost, and
147
+ * `crash_after` that the caller died after it. The stub itself (callable
148
+ * methods, awaited properties, `fetch`, the pipelining guards) is shared
149
+ * with the callee that runs for real (`callees.ts`).
150
+ */
151
+ /** Marks of the other kinds of binding, which a service binding's duck type must not carry. */
152
+ const otherKinds = [
153
+ "prepare",
154
+ "idFromName",
155
+ "head",
156
+ "createBatch"
157
+ ];
158
+ /**
159
+ * Whether an env value is a service binding (the runtime's `Fetcher`). In
160
+ * workerd it is an RPC stub whose every property read yields a callable, so
161
+ * duck typing alone would take it for any other kind: the runtime's class is
162
+ * checked first, and the duck type (fetch and connect, none of the other
163
+ * kinds' marks) serves test doubles.
164
+ */
165
+ function isServiceBinding(value) {
166
+ if (typeof value !== "object" || value === null) return false;
167
+ const fetcher = globalThis.Fetcher;
168
+ if (typeof fetcher === "function" && value instanceof fetcher) return true;
169
+ if ((Object.getPrototypeOf(value)?.constructor)?.name === "Fetcher") return true;
170
+ const v = value;
171
+ return typeof v["fetch"] === "function" && typeof v["connect"] === "function" && otherKinds.every((k) => typeof v[k] !== "function");
172
+ }
173
+ /** The built-in error classes RPC carries across as themselves (workerd keeps the type). */
174
+ const builtInErrors = {
175
+ Error,
176
+ EvalError,
177
+ RangeError,
178
+ ReferenceError,
179
+ SyntaxError,
180
+ TypeError,
181
+ URIError
182
+ };
183
+ /**
184
+ * The error the caller sees for a `throws` reply, `"<Name>: <message>"`: a
185
+ * built-in error class is that class, so `instanceof` holds as it does over
186
+ * RPC; any other name is an `Error` carrying the name.
187
+ */
188
+ function scriptedError(spec) {
189
+ const at = spec.indexOf(": ");
190
+ if (at < 0) return new Error(spec);
191
+ const name = spec.slice(0, at);
192
+ const message = spec.slice(at + 2);
193
+ const builtIn = builtInErrors[name];
194
+ if (builtIn) return new builtIn(message);
195
+ const error = new Error(message);
196
+ error.name = name;
197
+ return error;
198
+ }
199
+ /** Read a request for the log without consuming it: the callee may still read the body. */
200
+ async function recordRequest(request) {
201
+ const method = request.method.toUpperCase();
202
+ const headers = {};
203
+ request.headers.forEach((value, name) => {
204
+ headers[name.toLowerCase()] = value;
205
+ });
206
+ const body = parseBody(await request.clone().text());
207
+ return {
208
+ url: request.url,
209
+ method,
210
+ headers,
211
+ body
212
+ };
213
+ }
214
+ /**
215
+ * The stub a Worker sees under a service binding's name: methods callable
216
+ * and awaitable, `fetch`, and the guards against what is not modelled
217
+ * (promise pipelining, `connect()`), with the answers supplied.
218
+ */
219
+ function serviceStub(binding, ctx, answers) {
220
+ const unsupported = (what) => refuse(ctx, `service binding ${binding}: ${what}`);
221
+ /**
222
+ * The promise a call returns. On the real stub it is an RPC promise that
223
+ * pipelines property reads (`stub.charge().id`); this one is not, so a read
224
+ * on it makes the run UNSUPPORTED instead of yielding undefined.
225
+ */
226
+ const pipelineGuard = (promise, method) => new Proxy(promise, { get(target, prop) {
227
+ if (typeof prop === "symbol" || prop === "then" || prop === "catch" || prop === "finally") {
228
+ const value = Reflect.get(target, prop, target);
229
+ return typeof value === "function" ? value.bind(target) : value;
230
+ }
231
+ ctx.hooks.unsupported(`service binding ${binding}: RPC promise pipelining (reading .${prop} on ${method}()'s promise) is not supported; await the call first`);
232
+ } });
233
+ /** One call: `stub.method(...)`, or `await stub.property` (an RPC getter). */
234
+ const call = (method) => {
235
+ const invoke = (...args) => pipelineGuard(answers.call(method, args), method);
236
+ const awaitable = (onFulfilled, onRejected) => answers.property(method).then(onFulfilled, onRejected);
237
+ return new Proxy(invoke, { get(fn, key) {
238
+ if (key === "then") return awaitable;
239
+ if (typeof key === "symbol") return Reflect.get(fn, key);
240
+ ctx.hooks.unsupported(`service binding ${binding}: RPC promise pipelining (reading .${method}.${key}) is not supported; await .${method} first`);
241
+ } });
242
+ };
243
+ const fetchThrough = async (input, init) => answers.fetch(new Request(input, init));
244
+ return new Proxy({}, { get(_stub, prop) {
245
+ if (prop === "then" || typeof prop === "symbol") return void 0;
246
+ if (prop === "fetch") return fetchThrough;
247
+ if (prop === "connect") return () => unsupported("connect() (a raw TCP socket) is not modelled");
248
+ return call(prop);
249
+ } });
250
+ }
251
+ /** The scripted stub a Worker sees under a service binding's name. */
252
+ function proxyService(binding, ctx, script) {
253
+ const target = `Service:${binding}`;
254
+ const point = (op, args) => pointAt(ctx, target, op, args, writeFaults);
255
+ const unsupported = (what) => refuse(ctx, `service binding ${binding}: ${what}`);
256
+ /** The scripted reply to a method, by name; a method the script lacks cannot be answered. */
257
+ const replyTo = (method) => {
258
+ if (script.methods === void 0) return { returns: null };
259
+ if (!Object.hasOwn(script.methods, method)) return unsupported(`no scripted reply for method ${method}; add it to the service(${JSON.stringify(binding)}) setup's methods`);
260
+ return script.methods[method];
261
+ };
262
+ const answer = (method) => {
263
+ const reply = replyTo(method);
264
+ if ("throws" in reply) throw scriptedError(reply.throws);
265
+ return structuredClone(reply.returns);
266
+ };
267
+ const summarize = (value) => ({ value: toJson(value) });
268
+ return serviceStub(binding, ctx, {
269
+ call: (method, args) => ctx.hooks.effect(point(method, { args: args.map((a) => toJson(a)) }), async () => answer(method), summarize),
270
+ property: (method) => ctx.hooks.effect(point(method, { property: true }), async () => answer(method), summarize),
271
+ async fetch(request) {
272
+ const url = new URL(request.url);
273
+ const { method, headers, body } = await recordRequest(request);
274
+ const reply = await ctx.hooks.effect(point(method, {
275
+ url: request.url,
276
+ method,
277
+ headers,
278
+ body
279
+ }), async () => {
280
+ const found = findResponse({
281
+ name: binding,
282
+ host: url.host,
283
+ guarantees: {},
284
+ ...script.fetch === void 0 ? {} : { responses: script.fetch }
285
+ }, method, url.pathname);
286
+ if (found === void 0) return unsupported(`no scripted reply for fetch ${method} ${url.pathname}; add it to the service(${JSON.stringify(binding)}) setup's fetch`);
287
+ const reply = replyOf(found);
288
+ if (isRedirect(reply.status) && request.redirect !== "manual") return unsupported(`the scripted reply to ${method} ${url.pathname} is a ${reply.status} redirect, which the runtime would follow; script the final reply or fetch with redirect: "manual"`);
289
+ return reply;
290
+ }, (r) => ({ status: r.status }));
291
+ return toResponse(reply);
292
+ }
293
+ });
294
+ }
122
295
  // packages/cloudflare/src/object-access.ts
123
296
  /** The host an object's code runs as (`EffectOptions.host`): its namespace's target and its name. */
124
297
  function hostOf(target, object) {
@@ -171,6 +344,57 @@ function hostMethod(hooks, host, instance, method) {
171
344
  });
172
345
  }
173
346
  }
347
+ /** Who each guarded instance is and the run it belongs to, set each time a call enters it. */
348
+ const guardOfInstance = /* @__PURE__ */ new WeakMap();
349
+ /**
350
+ * Keep an object's calls on its own service bindings from passing for the
351
+ * scenario's. The runtime hands an object the Worker's real `env`, where a
352
+ * service binding is never the scenario's script or callee: a call through
353
+ * it would reach whatever the isolate holds under that name and fail or
354
+ * answer outside the simulation, unseen. So the instance's `env` is put
355
+ * behind a view under which every call on a service binding ends the run
356
+ * `UNSUPPORTED` with the reason. Reading the binding does nothing; the
357
+ * object's other bindings are its own to use, unrecorded, as before. An
358
+ * `env` the class keeps elsewhere than `this.env` (a private field, a
359
+ * closure of its constructor) is out of reach.
360
+ */
361
+ function guardEnv(hooks, binding, object, instance) {
362
+ if (instance === null || typeof instance !== "object") return;
363
+ const guarded = guardOfInstance.has(instance);
364
+ guardOfInstance.set(instance, {
365
+ hooks,
366
+ binding,
367
+ object
368
+ });
369
+ if (guarded) return;
370
+ const descriptor = Object.getOwnPropertyDescriptor(instance, "env");
371
+ const env = descriptor?.value;
372
+ if (!descriptor?.writable || env === null || typeof env !== "object") return;
373
+ const refuse = (name) => {
374
+ const of = guardOfInstance.get(instance) ?? {
375
+ hooks,
376
+ binding,
377
+ object
378
+ };
379
+ const reason = `Durable Object ${of.binding} ${of.object} called the service binding ${name} through its own env: an object's own binding calls are outside the simulation, so no service() script or callee() answers them`;
380
+ of.hooks.unsupported(reason);
381
+ throw new Error(`eutaxy: ${reason}`);
382
+ };
383
+ const stubs = /* @__PURE__ */ new Map();
384
+ const stubFor = (name) => {
385
+ let stub = stubs.get(name);
386
+ if (!stub) {
387
+ const refused = Object.assign(async () => refuse(name), { then: (onFulfilled, onRejected) => refused().then(onFulfilled, onRejected) });
388
+ stub = new Proxy({}, { get: (_t, prop) => prop === "then" || typeof prop === "symbol" ? void 0 : refused });
389
+ stubs.set(name, stub);
390
+ }
391
+ return stub;
392
+ };
393
+ instance.env = new Proxy(env, { get(target, prop) {
394
+ const value = Reflect.get(target, prop, target);
395
+ return typeof prop === "string" && isServiceBinding(value) ? stubFor(prop) : value;
396
+ } });
397
+ }
174
398
  /**
175
399
  * One effect of `inv` performed inside the object `id` of `binding`: `perform`
176
400
  * runs as the effect, which hosts what the object does; a fault that
@@ -771,6 +995,7 @@ function enterObject(stub, binding, ctx, helpers, state, id, object, fn) {
771
995
  watchGate(live);
772
996
  state.states.set(id, live);
773
997
  await takeOverAlarms(live.storage, alarmControl(state.alarms, binding, id, object, () => ctx.hooks));
998
+ guardEnv(ctx.hooks, binding, object, instance);
774
999
  return fn(instance, live);
775
1000
  });
776
1001
  }
@@ -938,22 +1163,6 @@ function entrypointHandler(cls) {
938
1163
  };
939
1164
  return out;
940
1165
  }
941
- // packages/cloudflare/src/proxy-context.ts
942
- /** The effect point of a proxied call: the invocation running now, the binding's target, the call. */
943
- function pointAt(ctx, target, op, args, allowed) {
944
- return {
945
- invocation: ctx.currentInvocation(),
946
- target,
947
- op,
948
- args,
949
- allowed
950
- };
951
- }
952
- /** Report why the run cannot be trusted and refuse the call with the same reason. */
953
- function refuse(ctx, reason) {
954
- ctx.hooks.unsupported(reason);
955
- throw new Error(`eutaxy: ${reason}`);
956
- }
957
1166
  // packages/cloudflare/src/caller.ts
958
1167
  /**
959
1168
  * The caller of an inbound request or RPC call. Cloudflare retries neither,
@@ -1976,163 +2185,6 @@ function callMethod(cls, call, ctx, env) {
1976
2185
  if (!method) throw new TypeError(`The RPC receiver does not implement the method "${call.method}".`);
1977
2186
  return method.apply(instance, structuredClone(call.args));
1978
2187
  }
1979
- // packages/cloudflare/src/services.ts
1980
- /**
1981
- * Service bindings with the callee scripted. A Worker reaches a peer through
1982
- * `env.BINDING`, by RPC method or by `fetch()`; Cloudflare routes the call on
1983
- * the same thread and retries nothing (Workers, service bindings). The real
1984
- * binding is never called here: the scenario's `service()` setup scripts the
1985
- * replies, and each call is one effect with the faults of a Durable Object
1986
- * stub call, where `crash_before` and `error` mean the call never reached
1987
- * the callee, `ambiguous` that it acted and the answer was lost, and
1988
- * `crash_after` that the caller died after it. The stub itself (callable
1989
- * methods, awaited properties, `fetch`, the pipelining guards) is shared
1990
- * with the callee that runs for real (`callees.ts`).
1991
- */
1992
- /** Marks of the other kinds of binding, which a service binding's duck type must not carry. */
1993
- const otherKinds = [
1994
- "prepare",
1995
- "idFromName",
1996
- "head",
1997
- "createBatch"
1998
- ];
1999
- /**
2000
- * Whether an env value is a service binding (the runtime's `Fetcher`). In
2001
- * workerd it is an RPC stub whose every property read yields a callable, so
2002
- * duck typing alone would take it for any other kind: the runtime's class is
2003
- * checked first, and the duck type (fetch and connect, none of the other
2004
- * kinds' marks) serves test doubles.
2005
- */
2006
- function isServiceBinding(value) {
2007
- if (typeof value !== "object" || value === null) return false;
2008
- const fetcher = globalThis.Fetcher;
2009
- if (typeof fetcher === "function" && value instanceof fetcher) return true;
2010
- if ((Object.getPrototypeOf(value)?.constructor)?.name === "Fetcher") return true;
2011
- const v = value;
2012
- return typeof v["fetch"] === "function" && typeof v["connect"] === "function" && otherKinds.every((k) => typeof v[k] !== "function");
2013
- }
2014
- /** The built-in error classes RPC carries across as themselves (workerd keeps the type). */
2015
- const builtInErrors = {
2016
- Error,
2017
- EvalError,
2018
- RangeError,
2019
- ReferenceError,
2020
- SyntaxError,
2021
- TypeError,
2022
- URIError
2023
- };
2024
- /**
2025
- * The error the caller sees for a `throws` reply, `"<Name>: <message>"`: a
2026
- * built-in error class is that class, so `instanceof` holds as it does over
2027
- * RPC; any other name is an `Error` carrying the name.
2028
- */
2029
- function scriptedError(spec) {
2030
- const at = spec.indexOf(": ");
2031
- if (at < 0) return new Error(spec);
2032
- const name = spec.slice(0, at);
2033
- const message = spec.slice(at + 2);
2034
- const builtIn = builtInErrors[name];
2035
- if (builtIn) return new builtIn(message);
2036
- const error = new Error(message);
2037
- error.name = name;
2038
- return error;
2039
- }
2040
- /** Read a request for the log without consuming it: the callee may still read the body. */
2041
- async function recordRequest(request) {
2042
- const method = request.method.toUpperCase();
2043
- const headers = {};
2044
- request.headers.forEach((value, name) => {
2045
- headers[name.toLowerCase()] = value;
2046
- });
2047
- const body = parseBody(await request.clone().text());
2048
- return {
2049
- url: request.url,
2050
- method,
2051
- headers,
2052
- body
2053
- };
2054
- }
2055
- /**
2056
- * The stub a Worker sees under a service binding's name: methods callable
2057
- * and awaitable, `fetch`, and the guards against what is not modelled
2058
- * (promise pipelining, `connect()`), with the answers supplied.
2059
- */
2060
- function serviceStub(binding, ctx, answers) {
2061
- const unsupported = (what) => refuse(ctx, `service binding ${binding}: ${what}`);
2062
- /**
2063
- * The promise a call returns. On the real stub it is an RPC promise that
2064
- * pipelines property reads (`stub.charge().id`); this one is not, so a read
2065
- * on it makes the run UNSUPPORTED instead of yielding undefined.
2066
- */
2067
- const pipelineGuard = (promise, method) => new Proxy(promise, { get(target, prop) {
2068
- if (typeof prop === "symbol" || prop === "then" || prop === "catch" || prop === "finally") {
2069
- const value = Reflect.get(target, prop, target);
2070
- return typeof value === "function" ? value.bind(target) : value;
2071
- }
2072
- ctx.hooks.unsupported(`service binding ${binding}: RPC promise pipelining (reading .${prop} on ${method}()'s promise) is not supported; await the call first`);
2073
- } });
2074
- /** One call: `stub.method(...)`, or `await stub.property` (an RPC getter). */
2075
- const call = (method) => {
2076
- const invoke = (...args) => pipelineGuard(answers.call(method, args), method);
2077
- const awaitable = (onFulfilled, onRejected) => answers.property(method).then(onFulfilled, onRejected);
2078
- return new Proxy(invoke, { get(fn, key) {
2079
- if (key === "then") return awaitable;
2080
- if (typeof key === "symbol") return Reflect.get(fn, key);
2081
- ctx.hooks.unsupported(`service binding ${binding}: RPC promise pipelining (reading .${method}.${key}) is not supported; await .${method} first`);
2082
- } });
2083
- };
2084
- const fetchThrough = async (input, init) => answers.fetch(new Request(input, init));
2085
- return new Proxy({}, { get(_stub, prop) {
2086
- if (prop === "then" || typeof prop === "symbol") return void 0;
2087
- if (prop === "fetch") return fetchThrough;
2088
- if (prop === "connect") return () => unsupported("connect() (a raw TCP socket) is not modelled");
2089
- return call(prop);
2090
- } });
2091
- }
2092
- /** The scripted stub a Worker sees under a service binding's name. */
2093
- function proxyService(binding, ctx, script) {
2094
- const target = `Service:${binding}`;
2095
- const point = (op, args) => pointAt(ctx, target, op, args, writeFaults);
2096
- const unsupported = (what) => refuse(ctx, `service binding ${binding}: ${what}`);
2097
- /** The scripted reply to a method, by name; a method the script lacks cannot be answered. */
2098
- const replyTo = (method) => {
2099
- if (script.methods === void 0) return { returns: null };
2100
- if (!Object.hasOwn(script.methods, method)) return unsupported(`no scripted reply for method ${method}; add it to the service(${JSON.stringify(binding)}) setup's methods`);
2101
- return script.methods[method];
2102
- };
2103
- const answer = (method) => {
2104
- const reply = replyTo(method);
2105
- if ("throws" in reply) throw scriptedError(reply.throws);
2106
- return structuredClone(reply.returns);
2107
- };
2108
- const summarize = (value) => ({ value: toJson(value) });
2109
- return serviceStub(binding, ctx, {
2110
- call: (method, args) => ctx.hooks.effect(point(method, { args: args.map((a) => toJson(a)) }), async () => answer(method), summarize),
2111
- property: (method) => ctx.hooks.effect(point(method, { property: true }), async () => answer(method), summarize),
2112
- async fetch(request) {
2113
- const url = new URL(request.url);
2114
- const { method, headers, body } = await recordRequest(request);
2115
- const reply = await ctx.hooks.effect(point(method, {
2116
- url: request.url,
2117
- method,
2118
- headers,
2119
- body
2120
- }), async () => {
2121
- const found = findResponse({
2122
- name: binding,
2123
- host: url.host,
2124
- guarantees: {},
2125
- ...script.fetch === void 0 ? {} : { responses: script.fetch }
2126
- }, method, url.pathname);
2127
- if (found === void 0) return unsupported(`no scripted reply for fetch ${method} ${url.pathname}; add it to the service(${JSON.stringify(binding)}) setup's fetch`);
2128
- const reply = replyOf(found);
2129
- if (isRedirect(reply.status) && request.redirect !== "manual") return unsupported(`the scripted reply to ${method} ${url.pathname} is a ${reply.status} redirect, which the runtime would follow; script the final reply or fetch with redirect: "manual"`);
2130
- return reply;
2131
- }, (r) => ({ status: r.status }));
2132
- return toResponse(reply);
2133
- }
2134
- });
2135
- }
2136
2188
  // packages/cloudflare/src/callees.ts
2137
2189
  /**
2138
2190
  * Service bindings with the callee real. A scenario names the Worker behind a
@@ -4710,24 +4762,31 @@ async function deliverMessage(event, hooks, c, data, deps) {
4710
4762
  * documented by Cloudflare, and for requests the caller's retry policy
4711
4763
  * declared in the drive.
4712
4764
  */
4765
+ /**
4766
+ * Whether an env value is a binding and not a var: something with methods.
4767
+ * A JSON var is plain data, whose only methods are `Object.prototype`'s or
4768
+ * an array's, so those do not count; a test double written as an object
4769
+ * literal counts by the functions it holds itself.
4770
+ */
4713
4771
  function isBindingLike(value) {
4714
4772
  if (typeof value === "function") return true;
4715
- if (typeof value !== "object" || value === null) return false;
4773
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
4716
4774
  const proto = Object.getPrototypeOf(value);
4717
- return [...Object.getOwnPropertyNames(value), ...Object.getOwnPropertyNames(proto ?? {})].some((k) => k !== "constructor" && typeof value[k] === "function");
4775
+ const inherited = proto === null || proto === Object.prototype ? {} : proto;
4776
+ return [...Object.getOwnPropertyNames(value), ...Object.getOwnPropertyNames(inherited)].some((k) => k !== "constructor" && typeof value[k] === "function");
4718
4777
  }
4719
4778
  const assumptions = [
4720
4779
  "platform model: Cloudflare Queues at-least-once delivery; the first ack or retry decision per message wins; unacked messages are redelivered up to max_retries then dead-lettered",
4721
- "D1 statements run against Miniflare's SQLite; each run/first/all/raw/batch/exec is one effect",
4780
+ "D1 statements run against Miniflare's SQLite; each run/first/all/raw/batch/exec is one effect; SQL that reads the time or draws randomness itself (CURRENT_TIMESTAMP, strftime('now'), random()) reads SQLite's own clock and generator, not the virtual ones, so a value it stores differs from run to run",
4722
4781
  "message.timestamp is the virtual clock's time at delivery",
4723
- "only D1, Durable Object, R2, Workflow and scripted service bindings are proxied; touching any other binding makes the run UNSUPPORTED",
4782
+ "only D1, Durable Object, R2, Workflow and scripted service bindings are proxied; a call on any other binding makes the run UNSUPPORTED (reading one off env does not)",
4724
4783
  "service bindings are scripted callees unless the scenario names a callee for them: the Worker behind a scripted binding is never called; each RPC method call or fetch() through it is one effect answered from the scenario's service() setup, where crash_before and error mean the call never reached the callee, ambiguous that it acted and the answer was lost, and crash_after that the caller died after it (developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/); Cloudflare does not retry such a call",
4725
4784
  "a binding named as an alias of another (the same database, the same Durable Object namespace, in two Workers' configs) is that binding: its effects and snapshot carry the other's name, and a callee's Workflow runs the callee's class with the callee's env",
4726
4785
  "a service binding with a callee() setup runs that Worker's real code in the caller's simulation, in the same isolate, as Cloudflare runs both Workers on one thread (developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/): each RPC method call or fetch() through it is one effect hosting the callee's invocation (<caller invocation>/<binding>.<method>), which constructs the entrypoint anew with a fresh ExecutionContext and the callee's env (its bindings under <worker name>/<binding>) and answers with the return value, plain data by copy, or the Response as it is; what the callee throws reaches the caller as a new error with its name, message and serializable own properties, a built-in class as itself (developers.cloudflare.com/workers/runtime-apis/rpc/error-handling/); the callee's waitUntil work finishes before its answer crosses; crash_before means the call never reached the callee, ambiguous that it acted and the answer was lost, crash_after that the caller died after it, and a fault that crashes the callee ends its invocation and throws an Error to the caller; Cloudflare retries nothing",
4727
4786
  "R2 buckets are Miniflare's real ones, emptied and seeded before each run and snapshotted after it; R2 is strongly consistent and the last writer wins (developers.cloudflare.com/r2/reference/consistency/); each put, delete, get, head and list is one effect, a body is read inside its get, and an object's version and upload time are stand-ins so traces repeat; multipart uploads and conditions on the upload time are not modelled",
4728
- "Durable Objects are the real objects workerd runs (storage, transactions, input and output gates are the runtime's own); each stub call is one effect: crash_before or error means it never reached the object, ambiguous means the object committed and the caller lost the answer, crash_after means the caller died after it; in a concurrent run an object's own outbound I/O during a call is a turn, so another event may enter the object meanwhile (its input gate is open then), except while it holds the gate with blockConcurrencyWhile, when its effects run at once; work an object starts and does not await (a promise left running, a timer, ctx.waitUntil) goes on after its answer as the object's own invocation, DO:<binding>/<object>/after, whose effects are turns of their own and take faults by their position in it, until nothing of it can move or a crash resets the object, which ends it with the instance (work that keeps setting timers is waited for up to 100 firings without settling, then the run is UNSUPPORTED); an object that awaits a timer of its own before answering is woken by it; an effect it issued before its answer and did not await, a timer it set and real work it started (Web Crypto) are its own once the call has answered: the caller's crash does not end them and a fault in them resets the object, not the caller; in a sequential run that work runs to rest before the next event (developers.cloudflare.com/durable-objects/concepts/durable-object-lifecycle/); storage operations are not turns (the input gate holds other events during them); the object's own binding calls are not recorded; objects are cleared, seeded and evicted before each run and their storage is snapshotted after it (developers.cloudflare.com/durable-objects/api/storage-api/)",
4787
+ "Durable Objects are the real objects workerd runs (storage, transactions, input and output gates are the runtime's own); each stub call is one effect: crash_before or error means it never reached the object, ambiguous means the object committed and the caller lost the answer, crash_after means the caller died after it; in a concurrent run an object's own outbound I/O during a call is a turn, so another event may enter the object meanwhile (its input gate is open then), except while it holds the gate with blockConcurrencyWhile, when its effects run at once; work an object starts and does not await (a promise left running, a timer, ctx.waitUntil) goes on after its answer as the object's own invocation, DO:<binding>/<object>/after, whose effects are turns of their own and take faults by their position in it, until nothing of it can move or a crash resets the object, which ends it with the instance (work that keeps setting timers is waited for up to 100 firings without settling, then the run is UNSUPPORTED); an object that awaits a timer of its own before answering is woken by it; an effect it issued before its answer and did not await, a timer it set and real work it started (Web Crypto) are its own once the call has answered: the caller's crash does not end them and a fault in them resets the object, not the caller; in a sequential run that work runs to rest before the next event (developers.cloudflare.com/durable-objects/concepts/durable-object-lifecycle/); storage operations are not turns (the input gate holds other events during them); the object's own binding calls are not recorded, and a call it makes on a service binding through this.env makes the run UNSUPPORTED, since no service() script or callee() answers inside the object; objects are cleared, seeded and evicted before each run and their storage is snapshotted after it (developers.cloudflare.com/durable-objects/api/storage-api/)",
4729
4788
  "Durable Object alarms are taken over so none is scheduled on the real clock and fire in virtual time: one alarm per object, a later setAlarm replaces it, setAlarm in a transaction applies on commit, the alarm survives eviction, alarm() is one effect (crash_before: it never ran; crash_after: it ran and counts as failed; error: it threw), and a failed alarm is retried after 2 s, 4 s, 8 s ... up to six retries and maxRedeliveries, with retryCount and isRetry (developers.cloudflare.com/durable-objects/api/base/#alarm); each object's alarm fires at most alarmsPerObject times per run (default 3)",
4730
- "Workflows are a model of the engine, never the local one, running the scenario's own class: create is one effect that queues the instance; each step.do attempt is two effect points around its callback, which runs as the instance's own code (step, crash_before: the engine restarts before it; step_result, crash_after: it ran and committed but its result was not persisted, so it runs again; ambiguous: the attempt ran but counted as failed, as a timeout does); a failed attempt is retried after its delay in virtual time (defaults 5 retries, 10 s, exponential, merged field by field with a step's config), up to its limit and maxRedeliveries, except a NonRetryableError; a restart re-runs run() from the start with the persisted step and sleep results, so code outside steps repeats; step timeouts are not measured (developers.cloudflare.com/workflows/build/rules-of-workflows/, /workflows/build/sleeping-and-retrying/)",
4789
+ "Workflows are a model of the engine, never the local one, running the scenario's own class: create is one effect that queues the instance; each step.do attempt is two effect points around its callback, which runs as the instance's own code (step, crash_before: the engine restarts before it; step_result, crash_after: it ran and committed but its result was not persisted, so it runs again; ambiguous at step: the attempt outlives its timeout from its start; ambiguous at step_result: it ran but counted as failed just after its work, as a timeout does); a failed attempt is retried after its delay in virtual time (defaults 5 retries, 10 s, exponential, merged field by field with a step's config), up to its limit and maxRedeliveries, except a NonRetryableError; a restart re-runs run() from the start with the persisted step and sleep results, so code outside steps repeats; a step's timeout is measured in virtual time (default 10 minutes), and an attempt that passes it is not stopped, as the engine cannot stop it either: it runs on as the late attempt while the step is retried or fails for good, its result dropped, and in a concurrent run its remaining effects land before, between or after the retry's or the recovery's (a sequential run lets it run first) (developers.cloudflare.com/workflows/build/rules-of-workflows/, /workflows/build/sleeping-and-retrying/)",
4731
4790
  "state invariants read a snapshot of every D1 binding named in setup, taken after the last event",
4732
4791
  "work passed to ctx.waitUntil runs after the handler returns and never affects acknowledgement or the response; a cut_off fault at that point loses work not yet started, and an effect in flight commits without its continuation",
4733
4792
  "concurrent invocations (maxConcurrentInvocations above 1) share one isolate's module state and bindings, and another may run while one awaits I/O (developers.cloudflare.com/workers/reference/how-workers-works/); queue consumers run concurrently up to max_concurrency (developers.cloudflare.com/queues/configuration/consumer-concurrency/)",
@@ -4788,6 +4847,42 @@ function createCloudflarePlatform(options) {
4788
4847
  ];
4789
4848
  const own = (prop) => typeof prop !== "string" || !prop.startsWith("__VITEST_POOL_WORKERS_");
4790
4849
  const aliasKeys = Object.keys(aliases).filter((a) => canonical(a) in env);
4850
+ /**
4851
+ * What the Worker sees under a binding of a kind the simulation does not
4852
+ * model: the binding with every method refused. Reading it does nothing,
4853
+ * as code that builds its dependencies from `env` on every call does;
4854
+ * the first call on it ends the run `UNSUPPORTED` and is never passed to
4855
+ * the real binding.
4856
+ */
4857
+ const standIns = /* @__PURE__ */ new Map();
4858
+ const unproxied = (name, real) => {
4859
+ let p = standIns.get(name);
4860
+ if (!p) {
4861
+ const refuseCall = () => refuse(ctx, `binding ${name} is not proxied`);
4862
+ p = new Proxy(typeof real === "function" ? refuseCall : {}, {
4863
+ get(_t, prop) {
4864
+ const value = Reflect.get(real, prop, real);
4865
+ return typeof value === "function" ? refuseCall : value;
4866
+ },
4867
+ has: (_t, prop) => Reflect.has(real, prop),
4868
+ ownKeys: () => Reflect.ownKeys(real),
4869
+ getOwnPropertyDescriptor(_t, prop) {
4870
+ const d = Reflect.getOwnPropertyDescriptor(real, prop);
4871
+ if (!d) return void 0;
4872
+ const value = Reflect.get(real, prop, real);
4873
+ return {
4874
+ value: typeof value === "function" ? refuseCall : value,
4875
+ enumerable: d.enumerable ?? false,
4876
+ configurable: true,
4877
+ writable: false
4878
+ };
4879
+ },
4880
+ apply: refuseCall
4881
+ });
4882
+ standIns.set(name, p);
4883
+ }
4884
+ return p;
4885
+ };
4791
4886
  const proxiedEnv = new Proxy(env, {
4792
4887
  get(target, prop, receiver) {
4793
4888
  if (!own(prop)) return void 0;
@@ -4799,8 +4894,7 @@ function createCloudflarePlatform(options) {
4799
4894
  const proxied = binding.proxy(name, value, ctx);
4800
4895
  if (proxied !== void 0) return proxied;
4801
4896
  }
4802
- if (isBindingLike(value)) ctx.hooks.unsupported(`binding ${name} is not proxied`);
4803
- return value;
4897
+ return isBindingLike(value) ? unproxied(name, value) : value;
4804
4898
  },
4805
4899
  has: (target, prop) => own(prop) && (Reflect.has(target, prop) || typeof prop === "string" && aliasKeys.includes(prop)),
4806
4900
  ownKeys: (target) => [.../* @__PURE__ */ new Set([...Reflect.ownKeys(target).filter(own), ...aliasKeys])],
@@ -5354,8 +5448,8 @@ async function checkInWorkerd(input) {
5354
5448
  ...input.extraSql
5355
5449
  });
5356
5450
  const load = input.modules[globKey(scenario.worker.entry)];
5357
- if (!load) throw new Error(`worker entry ${scenario.worker.entry} not found next to the scenario`);
5358
- const worker = await load();
5451
+ if (!input.worker && !load) throw new Error(`worker entry ${scenario.worker.entry} not found next to the scenario`);
5452
+ const worker = input.worker ?? await load?.();
5359
5453
  const platform = createCloudflarePlatform({
5360
5454
  env: input.env,
5361
5455
  handler: worker.default,
@@ -5406,4 +5500,4 @@ async function checkInWorkerd(input) {
5406
5500
  }
5407
5501
  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 };
5408
5502
 
5409
- //# sourceMappingURL=workerd-D9cUGjYv.mjs.map
5503
+ //# sourceMappingURL=workerd-9Tt0BV-3.mjs.map