@voltro/testing 0.39.1 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -39,6 +39,164 @@ _Changes staged for the next release accumulate here (rolled up from
39
39
 
40
40
  ---
41
41
 
42
+ ## [0.40.0] — 2026-08-16
43
+
44
+ ### ⚠ BREAKING
45
+
46
+ - **@voltro/client, @voltro/web** — A subscription whose COLD START failed is its own state — `failed: true`, `loading: false` — so "it is loading" is a true statement again.
47
+
48
+ The old shape left `loading: true` for a subscription where nothing was in flight and nothing more was coming. The type's own comment predicted the consequence:
49
+
50
+ > A cold-start failure leaves `loading` TRUE … so a component that branches on > `loading` alone renders a skeleton forever. Check `error` to break out of it.
51
+
52
+ A consumer quoted that back with the right conclusion: **a comment that predicts the misbehaviour of its own field is an API resting on discipline.** `loading` means "something is coming" everywhere else; here it meant "something is coming OR never again", and the escape hatch was a second field that the natural shape of a wrapper — pass `{ data, loading }` through — silently drops. They had three such wrappers. The framework had six, in `useWorkflow.ts`, and the compiler named all six the moment the state existed.
53
+
54
+ `failed` is a positive discriminant, so the check reads as one:
55
+
56
+ ```tsx
57
+ if (s.loading) return <Skeleton/>
58
+ if (s.failed) return <RetryPanel error={s.error}/>
59
+ return <Table rows={s.data}/>
60
+ ```
61
+
62
+ **BREAKING**: `!loading` no longer proves `data` is present, so every call site that reads `data` after a bare `loading` check is a type error naming file and line. Nothing fails silently. The codemod is `manual` on purpose — a transform could add `|| s.failed` everywhere and would be wrong about half of them, since an infinite skeleton is precisely what this removes.
63
+
64
+ **Measured blast radius**, because the estimate was worse than the reality: 20 errors inside `@voltro/client` (mostly its own `useWorkflow` wrapper and the type-tests) and **zero** in `@voltro/web`, `devtools-ui`, the devtools app, the cloud app, and all 45 templates. Most consumers were already using a `fallback` or a wrapper, which is what made the original defect so quiet.
65
+
66
+ Unchanged: a failure AFTER the first snapshot still leaves good data on screen with `error` set — only the cold start is `failed`. A `fallback` subscription still has `data` always present, so `failed` reports there rather than gating. `idle` stays opt-in by overload; `failed` is not opt-in, because any subscription's cold start can fail. And the state is terminal for one TRANSPORT: a reconnect discards the error and re-subscribes.
67
+ - **@voltro/protocol, @voltro/runtime, @voltro/voltro** — A guard refusing a caller whose credential was REJECTED now answers `Unauthenticated`, not `ScopeError`.
68
+
69
+ Measured by a consumer: a user's tab outlived their IdP's token lifetime. The strategy logged it plainly —
70
+
71
+ ```
72
+ WARN auth strategy "supabase" rejected request: supabase jwt expired
73
+ WARN mutation.tasks.update failed: missing required scope 'task:u:o'
74
+ ```
75
+
76
+ — and the wire said the caller lacked a scope. Technically true (an anonymous caller holds none) and it sends everyone who reads it into the permissions system while the problem is an expired session. They did that round; the subject was their administrator, and the same call with a fresh token worked.
77
+
78
+ **The obvious fix would have broken more than it fixed**, which is why this shape and not that one. Failing hard when a strategy rejects would break every `openAccess` procedure for anyone holding a stale cookie — a public page that needs no session at all would start refusing. So the FACT travels instead: a rejected credential stamps `credentialRejected` on the anonymous subject it falls back to, and only a guard that actually refuses spends it. `openAccess` never reaches that point and is untouched.
79
+
80
+ Three details worth knowing if you touch it:
81
+
82
+ - **The stamp happens AFTER the app's `fallback`.** That callback builds its own anonymous subject and knows nothing about the rejection; stamping before it would be silently discarded — the shape of every "wired on one path" defect in this codebase. - **ONE conversion point** (`asRefusal`), at the exit rather than at each `return`. Every branch builds the `ScopeError` it always built; one place decides what it MEANS. - **`Unauthenticated` is merged into the wire union** for guarded procedures AND guarded events, beside `ScopeError`. Without that it would be a tagged error the descriptor cannot represent, and the server would collapse it to `InternalError` — the defect another consumer reported the same week.
83
+
84
+ A caller who presented NO credential still gets `ScopeError`. Collapsing both would send a genuinely under-privileged user to the login page.
85
+
86
+ **Why this is BREAKING although nothing was removed.** Three published results gained a union member:
87
+
88
+ ```ts
89
+ checkGuards(…) // ScopeError | Unauthenticated | null (was ScopeError | null)
90
+ checkGuardsEffect(…) // Effect<ScopeError | Unauthenticated | null>
91
+ bindEvent(…) // Stream<…, ScopeError | Unauthenticated, …>
92
+ ```
93
+
94
+ The test for breaking is not "did a symbol disappear", it is whether code that COMPILED can stop compiling — and a widened return does that wherever the old union is named (`const refusal: ScopeError | null = checkGuards(…)`), or narrowed exhaustively. It was filed as `Added` first; the golden diff is what showed otherwise, and the rule is worth more than the classification that felt right. `anonymousSubject`'s new second parameter is OPTIONAL and breaks nothing.
95
+
96
+ `voltro update` carries you across it — codemod `0.40.0/02_rejected-credential-widens-guard-results`, a written note. A transform would widen each annotation, which compiles and keeps the reported behaviour: the decision at each site is what an expired session should do that a missing permission should not.
97
+
98
+ ### Added
99
+
100
+ - **@voltro/client, @voltro/web** — The client re-resolves `authHeaders` when the server says the credential was rejected — and `client.refreshAuth()` for an app that knows earlier.
101
+
102
+ `authHeaders` is resolved once per CONNECTION and attached per frame, so a tab open longer than the IdP's token lifetime keeps presenting a dead token until something reconnects. A consumer measured it: dragging a card on a board failed, their ADMINISTRATOR's token had simply expired while the page stood, and nothing in `@voltro/client` could force the re-resolve.
103
+
104
+ The trigger is the `Unauthenticated` error — which only became distinguishable from `ScopeError` in this same release. Before that the client could not have told "your session died" from "you lack a permission", and reconnecting on the second would have been wrong.
105
+
106
+ `refreshAuth()` is a SAME-SUBJECT rebuild, and the difference from `reconnect()` is one flag and a security boundary: `reconnect()` exists for a login / logout / tenant switch, where the next subject may be entitled to strictly LESS, so the cache must not be seeded from the old one. A token refresh is the same person with a fresh credential, so seeding is correct and the screen keeps its rows instead of blanking for the round trip. Getting that backwards is silent in both directions — seed on a subject change and you paint one user's rows into another's; refuse to seed on a refresh and every open screen blinks on every rotation.
107
+
108
+ The policy lives in ONE function (`wireAuthRefresh`) that every host wires, because "when do we reconnect on an auth error" is exactly the kind of decision this repo has watched drift when it was written twice. Two guards, answering different questions: a **rate** ceiling (one rebuild per window — a rejected mutation arrives alongside every rejected subscription on the page) and a **total** ceiling (stop after N refreshes with no successful call between, because at that point the credential is not stale, it is refused, and the answer is a sign-in screen rather than another socket).
109
+ - **@voltro/cli** — `middleware.ts` — a web app's one server-only hook, for renewing a credential before the SSR render uses it.
110
+
111
+ Reported: a consumer's SSR detail pages arrived empty on the first request of every day. Their cookie token had outlived the IdP's lifetime, the api resolved the caller to anonymous, and every `preload` on the page failed. They could not fix it in the app, and the reason is structural: `ctx.query` and every `preload` entry are bound from ONE cookie string **before any loader runs**, so a layout loader that renews the session cannot reach them — and a `type: 'web'` app has no auth middleware.
112
+
113
+ ```ts
114
+ // middleware.ts — web app root, server-only
115
+ export default async (req) => {
116
+ const fresh = await refreshSession(req.cookies['sb-session'])
117
+ if (!fresh) return
118
+ return {
119
+ headers: { authorization: `Bearer ${fresh.accessToken}` },
120
+ setCookies: [{ name: 'sb-session', value: fresh.cookie, maxAge: 3600 }],
121
+ }
122
+ }
123
+ ```
124
+
125
+ **Why not `app.config.ts`.** That file is imported into the CLIENT bundle, verbatim, the moment any api declares `authHeaders` — the thunk is a function, so it cannot be serialised. A hook that renews a session reaches for an IdP SDK by definition, so putting it there drags the server graph into the browser. The consumer proposed exactly that shape (`serverAuthHeaders` beside `authHeaders`) and it is the one place it cannot go.
126
+
127
+ **Why `setCookies` is not optional.** We asked whether writing cookies back was in scope, expecting the answer to be about a round trip. It was about correctness: Supabase ROTATES refresh tokens and detects reuse, so a hook that renews server-side and does not write the result back leaves the browser holding a consumed token. Without it the hook is not "slower but correct" — it can destroy the session.
128
+
129
+ **Deliberately not a general middleware.** It can replace credentials and set cookies. It cannot redirect, return a response, or rewrite a route — because authorization belongs on the API, which is the only thing that sees the data, and a web-side hook that can refuse a request becomes a second authorization layer beside the real one. A hook that cannot refuse also cannot be mistaken for a guard. For a login redirect, a loader already throws `RedirectError`.
130
+
131
+ Details worth knowing: only auth-shaped headers (`authorization`, `x-tenant`, `x-voltro-*`) are forwarded to the api, so a returned `host` or `content-length` cannot produce a failure that looks like anything but a header copy; cookies default to `HttpOnly` + `Path=/` + `SameSite=lax`; multiple cookies are written as separate header lines, never comma-joined (a cookie's `Expires` contains a comma); the file is loaded ONCE per boot; a failure to IMPORT is fatal rather than degrading to "no middleware", and a middleware that THROWS fails the request — the render must not proceed on the credential it was told to replace.
132
+
133
+ Wired on BOTH SSR boot paths (`voltro dev` and `voltro start`), with the cookies written on every response arm — streamed, buffered, redirect and 404. A partial application would renew a rotating token and drop it.
134
+ - **@voltro/testing** — `makeTestContext` supplies `ctx.events`, so an executor that publishes can be unit-tested at all.
135
+
136
+ `ctx.events` is a field PRODUCTION puts on every `AppContext`, and the test harness did not — so any handler containing `ctx.events.publish(...)` died on `Cannot read properties of undefined (reading 'publish')` the moment it ran under test.
137
+
138
+ **The shipped `api-durable` template demonstrates exactly that pattern** (publish inside the mutation's transaction, so it fires on COMMIT and not on rollback), and its own test passed anyway — because it called the executor with `await` instead of running it. An executor written in the Effect style RETURNS an Effect, and awaiting a non-thenable hands the object straight back, unrun. The assertion then failed on `row.status` being `undefined` and pointed at the assertion rather than at the call. Two defects propping each other up: the harness could not have run that handler, and the test never asked it to.
139
+
140
+ It is the REAL `makeEventPublisher` over a real `EventBus`, not a stub. A fake would re-implement the payload validation and the tenant stamping and would be wrong the first time either gains a case — the lesson `plugin-broadcast` paid for twice. `ctx.eventBus` is the read side:
141
+
142
+ ```ts
143
+ const seen = ctx.eventBus.subscribe(orderPlaced, { orderId })
144
+ await invoke(placeOrder, executor, input, ctx)
145
+ expect(seen.received).toHaveLength(1)
146
+ ```
147
+
148
+ One bus for the whole harness so a `withSubject` / `withTenant` re-scope still publishes where the test is listening; the PUBLISHER is per-subject, because the tenant it stamps is the caller's.
149
+
150
+ ### Fixed
151
+
152
+ - **@voltro/cli** — `voltro agents-md --force` no longer exits 0 when it wrote nothing.
153
+
154
+ Reported: a consumer's `agent-docs/` is owned by the pod (root). They ran the command as `admin`, and it **overwrote nothing, said nothing, and exited 0**. They read the unchanged file as "the framework has not fixed this yet" — it had — and lost a full round to it.
155
+
156
+ The cause was three `orElseSucceed`s in the agent-docs copy. `makeDirectory`, `readDirectory` and every `copyFile` degraded to success, so a destination the process could not write produced an empty run that reported itself as done. An unreadable source directory came back as `[]` and did the same.
157
+
158
+ Failures are collected and reported now, and the command **exits 1** when the seed is incomplete:
159
+
160
+ ```
161
+ agents-md: 12 file(s) could NOT be written — the seed is INCOMPLETE.
162
+ The commonest cause is ownership: a container wrote these as root and you are
163
+ running as someone else.
164
+ ```
165
+
166
+ `--force` is an explicit instruction to overwrite, so silently not overwriting is the one outcome that must never be reported as done. `stat` is the single remaining silent degrade, deliberately: a source entry that vanished mid-walk is not a write failure and must not fail the run.
167
+
168
+ Pinned in both directions — a real unwritable directory yields failures, a clean copy yields none, and a source guard asserts that `stat` is the ONLY call on that path allowed to swallow. Red-verified by restoring the original `orElseSucceed`.
169
+ - **@voltro/cli** — Every server-side loader context is now checked by the compiler, and the static prerender stopped handing loaders a context missing `search` and `headers`.
170
+
171
+ `ctx.isServer` shipped with a source-reading guard, and that guard had the defect it exists to prevent: it matched context literals by shape (`loader({` / `ctx: {`) and therefore found ONE of the two in `build.ts`, missing the one built as a typed arrow return. Its tripwire — "at least 5 sites" — passed, because a floor cannot tell 5-of-8 from 5-of-5. The gap was found by a parallel report, not by the guard.
172
+
173
+ The invariant moved from "the literal mentions `isServer`" to "the literal is CHECKED BY THE COMPILER": every server loader context is now `satisfies SegmentLoaderContext`, whose `isServer` is required. A site that forgets it is a type error naming the file and line — strictly stronger than any regex over shapes, and verified by removing one.
174
+
175
+ **It caught a second defect immediately.** The static prerender built its page loader context with only `params`, `pathname`, `signal` — no `search`, no `headers`, no `query` — while `LoaderContext.search` is declared `string`. A static page's loader reading `ctx.search` got `undefined` where the type promised a value. The segment context twenty lines above it in the same file already passed `search: ''` with a comment explaining why.
176
+
177
+ Two smaller things worth knowing if you touch the guard: the closing brace is part of its pattern because the bare phrase also appears in the comment explaining the rule (the first version counted its own documentation), and the CLI's `SegmentLoaderContext` mirror keeping `isServer` non-optional is what the whole enforcement rests on — `isServer?:` would make every `satisfies` pass while a forgetful site reports itself as the browser.
178
+ - **@voltro/protocol, @voltro/cli** — A guard's `ScopeError` reaches the client as `ScopeError` on a mutation, not as `InternalError`.
179
+
180
+ Measured by a consumer over the wire, same session, same foreign team:
181
+
182
+ | kind | declared `error:` | denial arrived as | |---|---|---| | query `webhooks.list` | `AccessDeniedError` | `_tag: 'ScopeError'` ✓ | | mutation `…updateReferenceLabels` | `AccessDeniedError` | `InternalError` ✗ | | the same mutation, after adding `ScopeError` to its union | | `_tag: 'ScopeError'` ✓ |
183
+
184
+ Their client maps `ScopeError` to *forbidden* and `InternalError` to *something went wrong*, so a permissions refusal looked like a crash — on every relationship-guarded write in the app.
185
+
186
+ **Their observation was exact; the mechanism was not, and the difference is where the fix goes.** They diagnosed it as "the merge only happens on the streaming path". `withGuardError` is called by every lifter, so the wire union carries `ScopeError` on both. What differs is a SECOND reader: the server refuses to ship a tagged error the descriptor cannot represent, collapsing it to `InternalError` rather than emitting a raw defect tree — and it was handed `descriptor.error`, the RAW declaration, while the union it protects is the WIDENED one. It judged against a narrower set than it had advertised. A query never reaches that check (it is delivered through `wireErrorFromCause`, which preserves the tag), which is exactly why the split fell along query/mutation.
187
+
188
+ `wireErrorUnion(descriptor, kind)` is now the single owner of "what can this procedure put on the wire", used by the lifters AND by both bind sites.
189
+
190
+ **Two more error classes were collapsed the same way, and neither was reported:**
191
+
192
+ - **`BusinessRuleViolation`** — unconditional for mutations. `withRuleError`'s own comment says it MUST be in the union "or the violation crosses the wire as an untyped defect". It was in the union, and collapsed before it got there. - **The `requiresApproval` refusals** — `ApprovalRequired` / `ApprovalExpired` / `ApprovalUnavailable`, so "parked for approval" was indistinguishable from "the server broke".
193
+
194
+ `openAccess:` still merges nothing: a procedure advertising a denial it cannot produce is what makes an error union stop meaning anything.
195
+
196
+ If you worked around this by declaring `ScopeError` yourself, the declaration is now redundant rather than wrong — the union is the same either way, and you can delete it whenever you like.
197
+
198
+ ---
199
+
42
200
  ## [0.39.1] — 2026-08-16
43
201
 
44
202
  ### Fixed
package/dist/index.d.ts CHANGED
@@ -747,6 +747,26 @@ export declare interface TestContext extends AppContext {
747
747
  * and the harness did not, so a mutation written the documented way —
748
748
  * `useWebhooks(ctx).emit(...)` — threw in every unit test. */
749
749
  readonly webhooks: MockWebhooks;
750
+ /**
751
+ * The event publisher, backed by a real in-process bus.
752
+ *
753
+ * `ctx.events` is a field PRODUCTION supplies on every `AppContext`, and this
754
+ * harness did not — so an executor containing `ctx.events.publish(...)` could
755
+ * not be unit-tested at all: it died on `Cannot read properties of undefined
756
+ * (reading 'publish')`. The shipped `api-durable` template demonstrates
757
+ * exactly that pattern (publish inside the mutation's transaction), so the
758
+ * example and the test helper contradicted each other, and the template's own
759
+ * test only passed because it awaited the Effect without running it.
760
+ *
761
+ * Real, not a stub: `makeEventPublisher` is the same constructor production
762
+ * uses, over a `testEventBus`. A fake would re-implement the validation and
763
+ * the tenant stamping, and would be wrong the first time either gains a case.
764
+ * `ctx.eventBus.received` is where a test reads what was published.
765
+ */
766
+ readonly events: EventPublisher;
767
+ /** The bus behind `ctx.events` — subscribe to it to assert what a handler
768
+ * published. */
769
+ readonly eventBus: TestEventBus;
750
770
  readonly llm: MockLLM;
751
771
  readonly ai?: MockAi;
752
772
  /** Re-scope to a different subject for one block (real subject swap, not
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AUTO_FILLED_COLUMNS as e, allRegisteredTables as t, changeDelete as n, changeInsert as r, changeSoftDelete as i, changeUpdate as a, clearRelationsRegistry as o, missingRequiredColumns as s, registerRelations as c } from "@voltro/database";
2
2
  import { Cause as l, Effect as u, Exit as d, Layer as f, Schema as p } from "effect";
3
- import { SubjectService as m, anonymousSubject as h, checkGuardsEffect as g, composeAuthStrategies as _, composeRpcInterceptors as v, eventRoute as ee, systemSubject as y, tenantScopedSubject as te } from "@voltro/protocol";
4
- import { EventBus as ne, InMemoryDataStore as re, NO_ROW_FILTER as b, applyRowFilterToDescriptor as ie, clearSystemStoreHandle as ae, getRowFilter as x, getSystemStoreHandle as oe, makeAppAccess as se, makeDataLoader as ce, makeEffectStoreLayer as le, makeOutboxFacade as ue, makeSchemaRegistry as de, publishEvent as fe, resolveRowFilterScopeFor as pe, runProvidedEffect as S, runWithDeadlockRetry as me, setSystemStoreHandle as C, wrapStoreWithMixinBehaviour as w } from "@voltro/runtime";
3
+ import { SubjectService as m, anonymousSubject as h, checkGuardsEffect as g, composeAuthStrategies as _, composeRpcInterceptors as v, eventRoute as y, systemSubject as b, tenantScopedSubject as ee } from "@voltro/protocol";
4
+ import { EventBus as te, InMemoryDataStore as ne, NO_ROW_FILTER as x, applyRowFilterToDescriptor as re, clearSystemStoreHandle as ie, getRowFilter as S, getSystemStoreHandle as ae, makeAppAccess as oe, makeDataLoader as se, makeEffectStoreLayer as ce, makeEventPublisher as le, makeOutboxFacade as ue, makeSchemaRegistry as de, publishEvent as fe, resolveRowFilterScopeFor as pe, runProvidedEffect as C, runWithDeadlockRetry as me, setSystemStoreHandle as w, wrapStoreWithMixinBehaviour as T } from "@voltro/runtime";
5
5
  import { installEnvSnapshot as he } from "@voltro/env";
6
6
  import ge from "node:net";
7
7
  import { describe as _e } from "vitest";
@@ -9,7 +9,7 @@ import { collectPublicApiRoutes as ve, dispatchSharedPath as ye, restRoutesToHtt
9
9
  import { createLogger as xe } from "@voltro/logger";
10
10
  import { CurrentWorkflowRunId as Se, inMemoryWorkflowEngineLayer as Ce, makeInMemoryRecorder as we } from "@voltro/workflow";
11
11
  //#region src/fixtureRow.ts
12
- var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
12
+ var Te = new Set(e), E = 0, D = () => ++E, Ee = (e, t) => {
13
13
  if (t.oneOf && t.oneOf.length > 0) return t.oneOf[0];
14
14
  if (t.enumValues && t.enumValues.length > 0) return t.enumValues[0];
15
15
  let n = t.unique === !0;
@@ -17,17 +17,17 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
17
17
  case "text":
18
18
  case "reference":
19
19
  case "id":
20
- case "enum": return n ? `${e}-${++T}` : e;
20
+ case "enum": return n ? `${e}-${++E}` : e;
21
21
  case "integer":
22
- case "real": return n ? ++T : 0;
22
+ case "real": return n ? ++E : 0;
23
23
  case "decimal":
24
- case "bigint": return n ? String(++T) : "0";
24
+ case "bigint": return n ? String(++E) : "0";
25
25
  case "boolean": return !1;
26
26
  case "timestamp":
27
27
  case "date": return /* @__PURE__ */ new Date(0);
28
28
  default: throw Error(`fixtureRow: column '${e}' is a required '${t.type}' with no default, and fixtureRow can't synthesize a safe placeholder for that type. Pass it explicitly: fixtureRow(table, { ${e}: … }).`);
29
29
  }
30
- }, D = (e, t = {}) => {
30
+ }, O = (e, t = {}) => {
31
31
  let n = {};
32
32
  for (let r of s(e, t)) Te.has(r) || (n[r] = Ee(r, e.fields[r]));
33
33
  return {
@@ -36,7 +36,7 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
36
36
  };
37
37
  }, De = (e) => {
38
38
  let t = {};
39
- for (let [n, r] of Object.entries(e)) t[n] = typeof r == "function" ? r(E()) : r;
39
+ for (let [n, r] of Object.entries(e)) t[n] = typeof r == "function" ? r(D()) : r;
40
40
  return t;
41
41
  }, Oe = (e) => {
42
42
  for (let [t, n] of Object.entries(e.fields)) if (n.type === "id") return t;
@@ -49,29 +49,29 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
49
49
  let s = n.references();
50
50
  if (i.includes(s.tableName)) throw Error(`defineFactory: creating '${t.tableName}' requires '${s.tableName}' via '${o}', and that reference is cyclic (${[...i, s.tableName].join(" → ")}). Insert one side first and pass the id: create(store, { ${o}: existing.id }).`);
51
51
  let c = r[o];
52
- a[o] = (c === void 0 ? await O(e, s, {}, {}, [...i, s.tableName]) : await c.create(e, {}))[Oe(s)];
52
+ a[o] = (c === void 0 ? await k(e, s, {}, {}, [...i, s.tableName]) : await c.create(e, {}))[Oe(s)];
53
53
  }
54
54
  return a;
55
- }, O = async (e, t, n, r, i) => {
55
+ }, k = async (e, t, n, r, i) => {
56
56
  let a = {
57
57
  ...await ke(e, t, n, r, i),
58
58
  ...n
59
59
  };
60
- return e.insert(t.tableName, D(t, a));
61
- }, k = (e, t) => typeof e == "function" ? e(t) : e ?? {}, Ae = (e, t = {}) => {
60
+ return e.insert(t.tableName, O(t, a));
61
+ }, A = (e, t) => typeof e == "function" ? e(t) : e ?? {}, Ae = (e, t = {}) => {
62
62
  let n = t.traits ?? {}, r = t.associations ?? {}, i = (t) => {
63
63
  let a = (e = {}) => ({
64
64
  ...De(t),
65
65
  ...e
66
- }), o = (t = {}) => D(e, a(t));
66
+ }), o = (t = {}) => O(e, a(t));
67
67
  return {
68
68
  table: e,
69
69
  build: o,
70
- buildList: (e, t) => Array.from({ length: e }, (e, n) => o(k(t, n))),
71
- create: (t, n = {}) => O(t, e, a(n), r, [e.tableName]),
70
+ buildList: (e, t) => Array.from({ length: e }, (e, n) => o(A(t, n))),
71
+ create: (t, n = {}) => k(t, e, a(n), r, [e.tableName]),
72
72
  createList: async (t, n, i) => {
73
73
  let o = [];
74
- for (let s = 0; s < n; s++) o.push(await O(t, e, a(k(i, s)), r, [e.tableName]));
74
+ for (let s = 0; s < n; s++) o.push(await k(t, e, a(A(i, s)), r, [e.tableName]));
75
75
  return o;
76
76
  },
77
77
  with: (...r) => {
@@ -93,19 +93,19 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
93
93
  };
94
94
  };
95
95
  return i(t.defaults ?? {});
96
- }, A = Symbol.for("voltro/testing/mockClock.installed"), j = () => globalThis, je = (e, t) => new Proxy(e, {
96
+ }, j = Symbol.for("voltro/testing/mockClock.installed"), M = () => globalThis, je = (e, t) => new Proxy(e, {
97
97
  construct: (e, n, r) => Reflect.construct(e, n.length === 0 ? [t()] : n, r),
98
98
  apply: () => new e(t()).toString(),
99
99
  get: (e, n, r) => n === "now" ? () => t() : Reflect.get(e, n, r)
100
- }), M = (e) => {
100
+ }), N = (e) => {
101
101
  if (typeof e == "number") return e;
102
102
  let t = e instanceof Date ? e.getTime() : Date.parse(e);
103
103
  if (Number.isNaN(t)) throw Error(`mockClock: cannot read an instant from '${String(e)}'`);
104
104
  return t;
105
- }, N = class {
105
+ }, P = class {
106
106
  currentMs;
107
107
  constructor(e = "2026-01-01T00:00:00Z") {
108
- this.currentMs = M(e);
108
+ this.currentMs = N(e);
109
109
  }
110
110
  now() {
111
111
  return this.currentMs;
@@ -117,16 +117,16 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
117
117
  this.currentMs += typeof e == "number" ? e : Fe(e);
118
118
  }
119
119
  set(e) {
120
- this.currentMs = M(e);
120
+ this.currentMs = N(e);
121
121
  }
122
122
  get installed() {
123
- return j()[A]?.clock === this;
123
+ return M()[j]?.clock === this;
124
124
  }
125
125
  install() {
126
- let e = j(), t = e[A];
126
+ let e = M(), t = e[j];
127
127
  if (t !== void 0) throw Error("mockClock: global time is already faked" + (t.clock === this ? " by this same clock" : " by another MockClock") + ". Uninstall it before installing again — a nested install restores the outer fake on the way out, which leaves the realm frozen with nothing pointing at why. `withFrozenTime` always restores, including on a throw.");
128
128
  let n = globalThis.Date;
129
- return e[A] = {
129
+ return e[j] = {
130
130
  realDate: n,
131
131
  clock: this
132
132
  }, globalThis.Date = je(n, () => this.currentMs), () => {
@@ -134,11 +134,11 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
134
134
  };
135
135
  }
136
136
  uninstall() {
137
- let e = j(), t = e[A];
138
- t !== void 0 && t.clock === this && (globalThis.Date = t.realDate, delete e[A]);
137
+ let e = M(), t = e[j];
138
+ t !== void 0 && t.clock === this && (globalThis.Date = t.realDate, delete e[j]);
139
139
  }
140
140
  }, Me = (e) => typeof e == "object" && !!e && typeof e.then == "function", Ne = (e, t) => {
141
- let n = e instanceof N ? e : new N(e);
141
+ let n = e instanceof P ? e : new P(e);
142
142
  n.install();
143
143
  let r = !1;
144
144
  try {
@@ -150,7 +150,7 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
150
150
  r || n.uninstall();
151
151
  }
152
152
  }, Pe = (e) => u.acquireRelease(u.sync(() => {
153
- let t = e instanceof N ? e : new N(e);
153
+ let t = e instanceof P ? e : new P(e);
154
154
  return t.install(), t;
155
155
  }), (e) => u.sync(() => {
156
156
  e.uninstall();
@@ -166,7 +166,7 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
166
166
  case "d": return n * 864e5;
167
167
  default: throw Error(`mockClock: unknown unit '${r}'`);
168
168
  }
169
- }, P = class {
169
+ }, F = class {
170
170
  emitted = [];
171
171
  async emit(e, t) {
172
172
  let n = typeof e == "string" ? e : e.id ?? e.event ?? "(unnamed event)";
@@ -185,7 +185,77 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
185
185
  clear() {
186
186
  this.emitted.length = 0;
187
187
  }
188
- }, F = class {
188
+ }, I = (e = {}) => {
189
+ let t = e.tenantId ?? null, n = new te({
190
+ origin: e.origin ?? "test",
191
+ ...e.ringSize === void 0 ? {} : { ringSize: e.ringSize }
192
+ });
193
+ return {
194
+ publish: async (e, r, i) => {
195
+ let a = await u.runPromise(u.either(fe({
196
+ bus: n,
197
+ tenantId: t
198
+ }, e, r, i)));
199
+ if (a._tag === "Left") {
200
+ let t = a.left;
201
+ throw Error(`testEventBus.publish(${e.name}) was rejected: ${t._tag}`, { cause: t });
202
+ }
203
+ return { n: a.right.n };
204
+ },
205
+ subscribe: (e, r, i) => {
206
+ let a = [], o = [];
207
+ return {
208
+ get received() {
209
+ return a.map((e) => e.payload);
210
+ },
211
+ get deliveries() {
212
+ return a;
213
+ },
214
+ get missed() {
215
+ return o;
216
+ },
217
+ get missedCount() {
218
+ return o.reduce((e, t) => e + t.count, 0);
219
+ },
220
+ stop: n.subscribe({
221
+ tenantId: i?.tenantId ?? t,
222
+ event: e.name,
223
+ key: r,
224
+ listener: (e) => {
225
+ if (e.kind === "gap") {
226
+ o.push({
227
+ count: e.missed,
228
+ reason: e.reason
229
+ });
230
+ return;
231
+ }
232
+ a.push({
233
+ payload: e.envelope.payload,
234
+ origin: e.envelope.origin,
235
+ n: e.envelope.n
236
+ });
237
+ },
238
+ ...i?.resume === void 0 ? {} : { options: { resume: i.resume } }
239
+ })
240
+ };
241
+ },
242
+ skipSerials: (e, r, i, a) => {
243
+ let o = a?.tenantId ?? t, s = {
244
+ route: y(o, e.name, r),
245
+ event: e.name,
246
+ origin: "test-gap",
247
+ n: i + 1,
248
+ emittedAt: Date.now(),
249
+ payload: void 0
250
+ };
251
+ n.injectRemote(s);
252
+ },
253
+ bus: n,
254
+ reset: () => {
255
+ n.clear();
256
+ }
257
+ };
258
+ }, L = class {
189
259
  queue;
190
260
  calls = [];
191
261
  constructor(e) {
@@ -200,27 +270,27 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
200
270
  remaining() {
201
271
  return this.queue.length;
202
272
  }
203
- }, Ie = (e) => e, I = "00000000000000000000000000000000", L = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), H = (e, t) => {
204
- let n = B.get(e) ?? [], r = t === "mutation" ? "interceptMutation" : t === "query" ? "interceptQuery" : "interceptAction", i = [];
273
+ }, Ie = (e) => e, R = "00000000000000000000000000000000", z = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), W = (e, t) => {
274
+ let n = H.get(e) ?? [], r = t === "mutation" ? "interceptMutation" : t === "query" ? "interceptQuery" : "interceptAction", i = [];
205
275
  for (let e of n) {
206
276
  let t = e[r];
207
277
  typeof t == "function" && i.push(t);
208
278
  }
209
279
  return v(i);
210
- }, U = (e) => {
211
- let t = (B.get(e) ?? []).map((e) => e.services).filter((e) => e !== void 0), n = V.get(e) ?? [], r = [...t, ...n];
280
+ }, G = (e) => {
281
+ let t = (H.get(e) ?? []).map((e) => e.services).filter((e) => e !== void 0), n = U.get(e) ?? [], r = [...t, ...n];
212
282
  if (r.length !== 0) return f.mergeAll(...r);
213
- }, W = (e) => {
214
- let t = R.get(e);
283
+ }, K = (e) => {
284
+ let t = B.get(e);
215
285
  t !== void 0 && (t.length = 0);
216
- }, G = async (e) => {
217
- let t = R.get(e);
286
+ }, q = async (e) => {
287
+ let t = B.get(e);
218
288
  if (t === void 0 || t.length === 0) return;
219
289
  let n = [...t];
220
290
  t.length = 0;
221
291
  for (let e of n) await e();
222
- }, Le = (e) => z.get(e) ?? [], K = async (e, t) => {
223
- let n = L.get(e);
292
+ }, Le = (e) => V.get(e) ?? [], J = async (e, t) => {
293
+ let n = z.get(e);
224
294
  return n === void 0 ? e.store.transactional(async (n) => t({
225
295
  ...e,
226
296
  store: n
@@ -293,28 +363,28 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
293
363
  }
294
364
  };
295
365
  }, Be = async (e, t) => {
296
- let n = oe();
297
- C(e);
366
+ let n = ae();
367
+ w(e);
298
368
  try {
299
369
  return await t();
300
370
  } finally {
301
- n === void 0 ? ae() : C(n);
371
+ n === void 0 ? ie() : w(n);
302
372
  }
303
- }, q = /* @__PURE__ */ new Set(), Ve = (e) => {
304
- q.has(e) || (q.add(e), console.warn(e));
373
+ }, Y = /* @__PURE__ */ new Set(), Ve = (e) => {
374
+ Y.has(e) || (Y.add(e), console.warn(e));
305
375
  }, He = (e, t, n) => {
306
376
  let r = Ue, i;
307
377
  return () => {
308
- let a = t ?? x();
309
- return t !== void 0 && x() !== void 0 && t !== x() && Ve("[voltro:testing] this test passes `rowFilter:` while a DIFFERENT filter is registered via `setRowFilter`. The option wins, so this test does not exercise your app's registration. Drop `rowFilter:` to run the real process-global one."), (i === void 0 || a !== r) && (r = a, i = Be(n, () => S(pe(a, e, (e) => {
378
+ let a = t ?? S();
379
+ return t !== void 0 && S() !== void 0 && t !== S() && Ve("[voltro:testing] this test passes `rowFilter:` while a DIFFERENT filter is registered via `setRowFilter`. The option wins, so this test does not exercise your app's registration. Drop `rowFilter:` to run the real process-global one."), (i === void 0 || a !== r) && (r = a, i = Be(n, () => C(pe(a, e, (e) => {
310
380
  console.error("[voltro:testing] row filter failed to load — reads refused for this subject", e);
311
381
  })))), i;
312
382
  };
313
- }, Ue = Symbol("unresolved"), J = (e, t) => new Proxy(e, { get: (e, n) => {
314
- if (n === "query") return async (n) => e.query(ie(await t(), n));
383
+ }, Ue = Symbol("unresolved"), We = (e, t) => new Proxy(e, { get: (e, n) => {
384
+ if (n === "query") return async (n) => e.query(re(await t(), n));
315
385
  let r = Reflect.get(e, n, e);
316
386
  return typeof r == "function" ? r.bind(e) : r;
317
- } }), We = (e = {}) => {
387
+ } }), Ge = (e = {}) => {
318
388
  if (he({
319
389
  ...process.env,
320
390
  ...e.env ?? {}
@@ -322,72 +392,77 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
322
392
  o();
323
393
  for (let t of e.relations) c(t);
324
394
  }
325
- let n = e.tables ?? t(), r = de(n), i = new re(e.store ?? {}), a = {
395
+ let n = e.tables ?? t(), r = de(n), i = new ne(e.store ?? {}), a = {
326
396
  dataStore: i,
327
397
  schemaRegistry: r
328
398
  };
329
- C(a);
330
- let s = new N(e.clockStart), l = new P(), u = new F(e.llmResponses ?? []), d = Re(() => s.now()), f = ze(() => s.now()), p = (t, n = i, o) => {
399
+ w(a);
400
+ let s = new P(e.clockStart), l = new F(), u = I(), d = new L(e.llmResponses ?? []), f = Re(() => s.now()), p = ze(() => s.now()), m = (t, n = i, o) => {
331
401
  let c = {
332
402
  subject: t,
333
- traceId: I
334
- }, m = o?.queued ?? [], h = o?.nudges ?? [], g = ce({ store: n }), _ = He(t, e.rowFilter, a), v = {
403
+ traceId: R
404
+ }, h = le({
405
+ bus: u.bus,
406
+ tenantId: t.tenantId ?? null
407
+ }), g = o?.queued ?? [], _ = o?.nudges ?? [], v = se({ store: n }), y = He(t, e.rowFilter, a), b = {
335
408
  clock: s,
336
409
  webhooks: l,
337
- llm: u,
410
+ events: h,
411
+ eventBus: u,
412
+ llm: d,
338
413
  ...e.ai === void 0 ? {} : { ai: e.ai },
339
414
  request: c,
340
- access: se(t),
341
- cache: d,
342
- kv: f,
343
- store: w(J(n, _), {
415
+ access: oe(t),
416
+ cache: f,
417
+ kv: p,
418
+ store: T(We(n, y), {
344
419
  subject: t,
345
420
  schemaRegistry: r,
346
- rowFilter: b
421
+ rowFilter: x
347
422
  }),
348
- storeForTenant: (e) => w(J(n, _), {
349
- subject: te(t, e),
423
+ storeForTenant: (e) => T(We(n, y), {
424
+ subject: ee(t, e),
350
425
  schemaRegistry: r,
351
- rowFilter: b
426
+ rowFilter: x
352
427
  }),
353
428
  outbox: ue({
354
429
  store: n,
355
430
  subject: t,
356
- traceId: I,
431
+ traceId: R,
357
432
  nudge: () => {
358
- h.push(I);
433
+ _.push(R);
359
434
  },
360
435
  afterCommit: (e) => {
361
- m.push(e);
436
+ g.push(e);
362
437
  }
363
438
  }),
364
- load: g.load,
365
- loadMany: g.loadMany,
366
- withSubject: (e, t) => Promise.resolve(t(p(e, n, {
367
- queued: m,
368
- nudges: h
439
+ load: v.load,
440
+ loadMany: v.loadMany,
441
+ withSubject: (e, t) => Promise.resolve(t(m(e, n, {
442
+ queued: g,
443
+ nudges: _
369
444
  }))),
370
- withTenant: (e, r) => Promise.resolve(r(p({
445
+ withTenant: (e, r) => Promise.resolve(r(m({
371
446
  ...t,
372
447
  tenantId: e
373
448
  }, n, {
374
- queued: m,
375
- nudges: h
449
+ queued: g,
450
+ nudges: _
376
451
  })))
377
452
  };
378
- return R.set(v, m), z.set(v, h), B.set(v, e.plugins ?? []), V.set(v, e.layers ?? []), L.set(v, (e) => n.transactional((n) => e(p(t, n, {
379
- queued: m,
380
- nudges: h
381
- })))), v;
453
+ return B.set(b, g), V.set(b, _), H.set(b, e.plugins ?? []), U.set(b, e.layers ?? []), z.set(b, (e) => n.transactional((n) => e(m(t, n, {
454
+ queued: g,
455
+ nudges: _
456
+ })))), b;
382
457
  };
383
- return p(e.subject ?? h(null));
384
- }, Ge = (e, t) => {
385
- let n = U(t);
386
- return (n === void 0 ? e : u.provide(e, n)).pipe(u.provide(le(t.store)), u.provideService(m, t.request.subject));
387
- }, Y = async (e, t, n, r) => {
458
+ return m(e.subject ?? h(null));
459
+ }, Ke = (e, t) => {
460
+ let n = G(t);
461
+ return (n === void 0 ? e : u.provide(e, n)).pipe(u.provide(ce(t.store)), u.provideService(m, t.request.subject));
462
+ }, qe = async (e, t, n, r) => {
388
463
  let i = e.input, a = await p.decodeUnknownPromise(i)(n), o = e.kind, s = async (e) => {
389
464
  let n = t(a, e);
390
- return u.isEffect(n) ? S(Ge(n, e)) : n;
465
+ return u.isEffect(n) ? C(Ke(n, e)) : n;
391
466
  }, c = async () => {
392
467
  let t = e.guards;
393
468
  if (t !== void 0 && t.length > 0) {
@@ -395,9 +470,9 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
395
470
  if (e !== null) throw e;
396
471
  }
397
472
  if (o !== "mutation") return s(r);
398
- let n = await me(async () => (W(r), K(r, async (e) => s(e))), { delay: () => Promise.resolve() });
399
- return await G(r), n;
400
- }, f = o === "mutation" || o === "query" || o === "action" ? o : void 0, m = f === void 0 ? void 0 : H(r, f);
473
+ let n = await me(async () => (K(r), J(r, async (e) => s(e))), { delay: () => Promise.resolve() });
474
+ return await q(r), n;
475
+ }, f = o === "mutation" || o === "query" || o === "action" ? o : void 0, m = f === void 0 ? void 0 : W(r, f);
401
476
  if (m === void 0 || f === void 0) return await c();
402
477
  let h = m(u.tryPromise({
403
478
  try: () => c(),
@@ -426,15 +501,15 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
426
501
  i = !1;
427
502
  }
428
503
  _e.skipIf(!i)(i ? e : `${e} [SKIPPED: needs ${t}]`, r);
429
- }, Ke = async (e, t, n) => {
504
+ }, Je = async (e, t, n) => {
430
505
  await Z(e, `${t.name} at ${t.host}:${t.port}`, () => X(t), n);
431
- }, qe = "test-tenant", Q = (e, t, n) => ({
506
+ }, Ye = "test-tenant", Q = (e, t, n) => ({
432
507
  type: e,
433
508
  id: t,
434
509
  tenantId: n.tenantId ?? "test-tenant",
435
510
  scopes: n.scopes ?? [],
436
511
  ...n.metadata === void 0 ? {} : { metadata: n.metadata }
437
- }), Je = (e, t = {}) => Q("user", e, t), Ye = (e, t = {}) => Q("apiKey", e, t), Xe = (e, t = {}) => Q("serviceAccount", e, t), Ze = (e = null) => h(e), Qe = (e = "job:test", t) => t === void 0 ? y(e) : y(e, t), $e = (e) => {
512
+ }), Xe = (e, t = {}) => Q("user", e, t), Ze = (e, t = {}) => Q("apiKey", e, t), Qe = (e, t = {}) => Q("serviceAccount", e, t), $e = (e = null) => h(e), et = (e = "job:test", t) => t === void 0 ? b(e) : b(e, t), tt = (e) => {
438
513
  let t = e.indexOf("?");
439
514
  return t === -1 ? {
440
515
  path: e,
@@ -443,17 +518,17 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
443
518
  path: e.slice(0, t),
444
519
  query: e.slice(t + 1)
445
520
  };
446
- }, et = (e, t) => {
521
+ }, nt = (e, t) => {
447
522
  let n = e.split("/").filter((e) => e.length > 0), r = t.split("/").filter((e) => e.length > 0);
448
523
  return n.length === r.length && n.every((e, t) => e.startsWith(":") || e === r[t]);
449
524
  }, $ = (e) => {
450
525
  let t = {};
451
526
  for (let [n, r] of Object.entries(e)) t[n.toLowerCase()] = r;
452
527
  return t;
453
- }, tt = (e) => e === void 0 ? /* @__PURE__ */ new Uint8Array() : new TextEncoder().encode(JSON.stringify(e)), nt = (e) => e === void 0 ? "" : typeof e == "string" ? e : new TextDecoder().decode(e), rt = (e) => {
528
+ }, rt = (e) => e === void 0 ? /* @__PURE__ */ new Uint8Array() : new TextEncoder().encode(JSON.stringify(e)), it = (e) => e === void 0 ? "" : typeof e == "string" ? e : new TextDecoder().decode(e), at = (e) => {
454
529
  let { ctx: t } = e, n = ve((e.publicApi ?? []).map((e) => ({
455
530
  descriptor: e.descriptor,
456
- invoke: (n, r) => t.withSubject(r.subject, (t) => Y(e.descriptor, e.handler, n, t))
531
+ invoke: (n, r) => t.withSubject(r.subject, (t) => qe(e.descriptor, e.handler, n, t))
457
532
  }))), r = [...e.restRoutes ?? [], ...n], i = _(e.strategies ?? [], {
458
533
  ...e.anonymousTenantRequired === void 0 ? {} : { anonymousTenantRequired: e.anonymousTenantRequired },
459
534
  getStore: () => t.store
@@ -469,7 +544,7 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
469
544
  pattern: r[t].path,
470
545
  route: e
471
546
  })), l = async (e, n, i = {}) => {
472
- let { path: a, query: s } = $e(n), l = c.filter((e) => et(e.pattern, a)).map((e) => e.route);
547
+ let { path: a, query: s } = tt(n), l = c.filter((e) => nt(e.pattern, a)).map((e) => e.route);
473
548
  if (l.length === 0) return {
474
549
  status: 404,
475
550
  headers: {},
@@ -488,11 +563,11 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
488
563
  ...$(o),
489
564
  ...$(i.headers ?? {})
490
565
  },
491
- rawBody: tt(i.body),
566
+ rawBody: rt(i.body),
492
567
  store: t.store
493
568
  }, d = await ye(l, u), f = $(d.headers ?? {});
494
569
  d.contentType !== void 0 && (f["content-type"] = d.contentType);
495
- let p = nt(d.body), m = (d.contentType ?? "").includes("json");
570
+ let p = it(d.body), m = (d.contentType ?? "").includes("json");
496
571
  return {
497
572
  status: d.status,
498
573
  headers: f,
@@ -526,77 +601,7 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
526
601
  };
527
602
  };
528
603
  return a(void 0, {});
529
- }, it = (e = {}) => {
530
- let t = e.tenantId ?? null, n = new ne({
531
- origin: e.origin ?? "test",
532
- ...e.ringSize === void 0 ? {} : { ringSize: e.ringSize }
533
- });
534
- return {
535
- publish: async (e, r, i) => {
536
- let a = await u.runPromise(u.either(fe({
537
- bus: n,
538
- tenantId: t
539
- }, e, r, i)));
540
- if (a._tag === "Left") {
541
- let t = a.left;
542
- throw Error(`testEventBus.publish(${e.name}) was rejected: ${t._tag}`, { cause: t });
543
- }
544
- return { n: a.right.n };
545
- },
546
- subscribe: (e, r, i) => {
547
- let a = [], o = [];
548
- return {
549
- get received() {
550
- return a.map((e) => e.payload);
551
- },
552
- get deliveries() {
553
- return a;
554
- },
555
- get missed() {
556
- return o;
557
- },
558
- get missedCount() {
559
- return o.reduce((e, t) => e + t.count, 0);
560
- },
561
- stop: n.subscribe({
562
- tenantId: i?.tenantId ?? t,
563
- event: e.name,
564
- key: r,
565
- listener: (e) => {
566
- if (e.kind === "gap") {
567
- o.push({
568
- count: e.missed,
569
- reason: e.reason
570
- });
571
- return;
572
- }
573
- a.push({
574
- payload: e.envelope.payload,
575
- origin: e.envelope.origin,
576
- n: e.envelope.n
577
- });
578
- },
579
- ...i?.resume === void 0 ? {} : { options: { resume: i.resume } }
580
- })
581
- };
582
- },
583
- skipSerials: (e, r, i, a) => {
584
- let o = a?.tenantId ?? t, s = {
585
- route: ee(o, e.name, r),
586
- event: e.name,
587
- origin: "test-gap",
588
- n: i + 1,
589
- emittedAt: Date.now(),
590
- payload: void 0
591
- };
592
- n.injectRemote(s);
593
- },
594
- bus: n,
595
- reset: () => {
596
- n.clear();
597
- }
598
- };
599
- }, at = (e = {}) => {
604
+ }, ot = (e = {}) => {
600
605
  let t = e.id ?? "test", n = e.store ?? new Proxy({}, { get: (e, t) => {
601
606
  throw Error(`makeSubscribeContext: this subscriber reached ctx.store.${String(t)} and the test passed no store. Pass \`{ store: makeTestContext().store }\` so the subscriber and the code under test share one — an empty stand-in would let a read of the wrong table pass.`);
602
607
  } });
@@ -606,7 +611,7 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
606
611
  store: n,
607
612
  ...e.publish === void 0 ? {} : { publish: e.publish }
608
613
  };
609
- }, ot = (e) => {
614
+ }, st = (e) => {
610
615
  let t = /* @__PURE__ */ new Map();
611
616
  for (let n of e) {
612
617
  let e = t.get(n.stepName);
@@ -632,13 +637,13 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
632
637
  });
633
638
  }
634
639
  return n.sort((e, t) => e._startedAt - t._startedAt), n.map(({ _startedAt: e, ...t }) => t);
635
- }, st = (e) => {
640
+ }, ct = (e) => {
636
641
  let t = e.workflows ?? [], n = /* @__PURE__ */ new Map(), r = 0;
637
642
  return {
638
643
  start: async (i, a) => {
639
644
  let o = t.find((e) => e.workflow.name === i);
640
645
  if (o === void 0) throw Error(`makeWorkflowRunner: no workflow named '${i}' — pass it in makeWorkflowRunner({ ctx, workflows: [{ workflow, execute }] }).`);
641
- let s = `wfrun_test_${++r}`, c = we(), l = o.workflow.toLayer(o.execute).pipe(f.provideMerge(Ce)), d = /* @__PURE__ */ new Date(), p = o.workflow.execute(a).pipe(u.locally(Se, s), u.provide(c.layer), u.provide(l), u.either), m = await u.runPromise(p), h = ot(c.readSteps()), g = /* @__PURE__ */ new Date(), _;
646
+ let s = `wfrun_test_${++r}`, c = we(), l = o.workflow.toLayer(o.execute).pipe(f.provideMerge(Ce)), d = /* @__PURE__ */ new Date(), p = o.workflow.execute(a).pipe(u.locally(Se, s), u.provide(c.layer), u.provide(l), u.either), m = await u.runPromise(p), h = st(c.readSteps()), g = /* @__PURE__ */ new Date(), _;
642
647
  if (m._tag === "Right") _ = {
643
648
  status: "succeeded",
644
649
  output: m.right,
@@ -678,6 +683,6 @@ var Te = new Set(e), T = 0, E = () => ++T, Ee = (e, t) => {
678
683
  },
679
684
  inspect: async (e) => n.get(e) ?? null
680
685
  };
681
- }, ct = 1;
686
+ }, lt = 1;
682
687
  //#endregion
683
- export { N as MockClock, F as MockLLM, P as MockWebhooks, ct as TESTING_PRESET_VERSION, qe as TEST_TENANT_ID, Ze as anonymous, Ye as apiKey, n as changeDelete, r as changeInsert, i as changeSoftDelete, a as changeUpdate, Ae as defineFactory, Z as describeIfAvailable, Ke as describeIfReachable, D as fixtureRow, Pe as frozenTime, Y as invoke, X as isTcpReachable, at as makeSubscribeContext, rt as makeTestApp, We as makeTestContext, st as makeWorkflowRunner, Ie as mockStore, E as nextSequence, Le as outboxNudgesOf, W as resetAfterCommit, H as rpcInterceptorFor, G as runAfterCommit, K as runInStoreTransaction, Xe as serviceAccount, U as serviceLayerFor, Qe as system, it as testEventBus, Je as user, Ne as withFrozenTime };
688
+ export { P as MockClock, L as MockLLM, F as MockWebhooks, lt as TESTING_PRESET_VERSION, Ye as TEST_TENANT_ID, $e as anonymous, Ze as apiKey, n as changeDelete, r as changeInsert, i as changeSoftDelete, a as changeUpdate, Ae as defineFactory, Z as describeIfAvailable, Je as describeIfReachable, O as fixtureRow, Pe as frozenTime, qe as invoke, X as isTcpReachable, ot as makeSubscribeContext, at as makeTestApp, Ge as makeTestContext, ct as makeWorkflowRunner, Ie as mockStore, D as nextSequence, Le as outboxNudgesOf, K as resetAfterCommit, W as rpcInterceptorFor, q as runAfterCommit, J as runInStoreTransaction, Qe as serviceAccount, G as serviceLayerFor, et as system, I as testEventBus, Xe as user, Ne as withFrozenTime };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/testing",
3
- "version": "0.39.1",
3
+ "version": "0.40.0",
4
4
  "description": "Test utilities for Voltro apps — deterministic clock, subject and row factories, a handler-level invoke and a request-level app harness, queued LLM responses, scoped subject/tenant runners, and a cross-dialect parity harness.",
5
5
  "keywords": [
6
6
  "voltro",
@@ -43,15 +43,15 @@
43
43
  "node": ">=24.0.0"
44
44
  },
45
45
  "dependencies": {
46
- "@voltro/database": "0.39.1",
47
- "@voltro/env": "0.39.1",
48
- "@voltro/logger": "0.39.1",
49
- "@voltro/protocol": "0.39.1",
50
- "@voltro/runtime": "0.39.1",
51
- "@voltro/workflow": "0.39.1"
46
+ "@voltro/database": "0.40.0",
47
+ "@voltro/env": "0.40.0",
48
+ "@voltro/logger": "0.40.0",
49
+ "@voltro/protocol": "0.40.0",
50
+ "@voltro/runtime": "0.40.0",
51
+ "@voltro/workflow": "0.40.0"
52
52
  },
53
53
  "peerDependencies": {
54
- "@voltro/client": "0.39.1",
54
+ "@voltro/client": "0.40.0",
55
55
  "effect": "^3.22.0",
56
56
  "react": "^19.0.0",
57
57
  "@effect/sql": "^0.52.0"