@voltro/testing 0.85.0 → 0.87.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.
@@ -0,0 +1,269 @@
1
+ import { MockClock as e } from "./mockClock.js";
2
+ import { recordTestRawStore as t, registerTestFieldKeys as n } from "./fieldKeys.js";
3
+ import { MockWebhooks as r } from "./mockWebhooks.js";
4
+ import { testEventBus as i } from "./testEventBus.js";
5
+ import { MockLLM as a } from "./mockLLM.js";
6
+ import { allRegisteredTables as o, clearRelationsRegistry as s, registerRelations as c } from "@voltro/database";
7
+ import { Effect as l, Layer as u } from "effect";
8
+ import { anonymousSubject as d, composeRpcInterceptors as f, tenantScopedSubject as p } from "@voltro/protocol";
9
+ import { InMemoryDataStore as m, NO_ROW_FILTER as h, appValidation as g, applyRowFilterToDescriptor as _, clearSystemStoreHandle as v, getRowFilter as y, getSystemStoreHandle as b, installComputedQueryCacheCapture as x, makeAppAccess as S, makeConnectionState as ee, makeDataLoader as te, makeEventPublisher as ne, makeFieldCipher as C, makeOutboxFacade as w, makeSchemaRegistry as T, queryCachePolicy as E, recordingStore as D, resolveRowFilterScopeFor as O, resolveTransactionSubject as k, runProvidedEffect as A, setFieldCipher as j, setSystemStoreHandle as M, wrapStoreWithMixinBehaviour as N } from "@voltro/runtime";
10
+ import { installEnvSnapshot as re } from "@voltro/env";
11
+ import { Cache as ie, layerMemory as ae } from "@voltro/cache";
12
+ //#region src/testContext.ts
13
+ var P = (e) => e, F = "00000000000000000000000000000000", I = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakMap(), R = (e, t) => {
14
+ let n = L.get(e);
15
+ if (n === void 0) throw Error("withRpcConnection requires a context created by makeTestContext");
16
+ return n(t);
17
+ }, z = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), H = (e) => V.get(e) ?? [], U = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), G = (e) => W.get(e), K = (e, t, n) => {
18
+ U.set(e, {
19
+ publicApi: t,
20
+ ...n === void 0 ? {} : { remoteAddr: n }
21
+ });
22
+ }, q = (e) => U.get(e), J = /* @__PURE__ */ new WeakMap(), oe = (e, t) => {
23
+ let n = V.get(e) ?? [], r = t === "mutation" ? "interceptMutation" : t === "query" ? "interceptQuery" : "interceptAction", i = [];
24
+ for (let e of n) {
25
+ let t = e[r];
26
+ typeof t == "function" && i.push(t);
27
+ }
28
+ return f(i);
29
+ }, se = (e) => {
30
+ let t = (V.get(e) ?? []).map((e) => e.services).filter((e) => e !== void 0), n = J.get(e) ?? [], r = [...t, ...n];
31
+ if (r.length !== 0) return u.mergeAll(...r);
32
+ }, ce = (e) => {
33
+ let t = z.get(e);
34
+ t !== void 0 && (t.length = 0);
35
+ }, Y = async (e) => {
36
+ let t = z.get(e);
37
+ if (t === void 0 || t.length === 0) return;
38
+ let n = [...t];
39
+ t.length = 0;
40
+ for (let e of n) await e();
41
+ }, X = (e) => B.get(e) ?? [], Z = async (e, t) => {
42
+ let n = I.get(e);
43
+ return n === void 0 ? e.store.transactional(async (n) => t({
44
+ ...e,
45
+ store: n
46
+ })) : n(t);
47
+ }, le = (e) => {
48
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = (n) => {
49
+ let r = t.get(n);
50
+ return r === void 0 ? !1 : r.expiresAt !== null && r.expiresAt <= e() ? (t.delete(n), !1) : !0;
51
+ }, i = (r, i, a, o) => {
52
+ if (t.set(r, {
53
+ value: i,
54
+ expiresAt: a === void 0 ? null : e() + a
55
+ }), o) for (let e of o) {
56
+ let t = n.get(e) ?? /* @__PURE__ */ new Set();
57
+ t.add(r), n.set(e, t);
58
+ }
59
+ };
60
+ return {
61
+ get: async (e) => r(e) ? t.get(e).value : void 0,
62
+ set: async (e, t, n) => {
63
+ i(e, t, n?.ttlMs);
64
+ },
65
+ setWithTags: async (e, t, n) => {
66
+ i(e, t, n.ttlMs, n.tags);
67
+ },
68
+ remove: async (e) => t.delete(e),
69
+ has: async (e) => r(e),
70
+ clear: async () => {
71
+ t.clear(), n.clear();
72
+ },
73
+ invalidateTag: async (e) => {
74
+ let r = n.get(e);
75
+ if (r === void 0) return 0;
76
+ let i = 0;
77
+ for (let e of r) t.delete(e) && i++;
78
+ return n.delete(e), i;
79
+ },
80
+ wrap: async (e, n, a) => {
81
+ if (r(e)) return t.get(e).value;
82
+ let o = await a();
83
+ return i(e, o, n.ttlMs, n.tags), o;
84
+ }
85
+ };
86
+ }, ue = (e) => {
87
+ let t = /* @__PURE__ */ new Map(), n = (n) => {
88
+ let r = t.get(n);
89
+ return r === void 0 ? !1 : r.expiresAt !== null && r.expiresAt <= e() ? (t.delete(n), !1) : !0;
90
+ };
91
+ return {
92
+ get: async (e) => n(e) ? t.get(e).value : void 0,
93
+ getOrElse: async (e, r) => n(e) ? t.get(e).value : r(),
94
+ set: async (n, r, i) => {
95
+ t.set(n, {
96
+ value: r,
97
+ expiresAt: i?.ttlMs === void 0 ? null : e() + i.ttlMs
98
+ });
99
+ },
100
+ delete: async (e) => {
101
+ let r = n(e);
102
+ return t.delete(e), r;
103
+ },
104
+ has: async (e) => n(e),
105
+ list: async (e) => {
106
+ let r = [];
107
+ for (let i of t.keys()) n(i) && (e === "" || i.startsWith(e)) && r.push(i);
108
+ return r;
109
+ },
110
+ clear: async () => {
111
+ t.clear();
112
+ }
113
+ };
114
+ }, de = async (e, t) => {
115
+ let n = b();
116
+ M(e);
117
+ try {
118
+ return await t();
119
+ } finally {
120
+ n === void 0 ? v() : M(n);
121
+ }
122
+ }, Q = /* @__PURE__ */ new Set(), fe = (e) => {
123
+ Q.has(e) || (Q.add(e), console.warn(e));
124
+ }, pe = (e, t, n) => {
125
+ let r = me, i;
126
+ return () => {
127
+ let a = t ?? y();
128
+ return t !== void 0 && y() !== void 0 && t !== y() && fe("[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 = de(n, () => A(O(a, e, (e) => {
129
+ console.error("[voltro:testing] row filter failed to load — reads refused for this subject", e);
130
+ })))), i;
131
+ };
132
+ }, me = Symbol("unresolved"), $ = (e, t) => new Proxy(e, { get: (e, n) => {
133
+ if (n === "query") return async (n) => e.query(_(await t(), n));
134
+ let r = Reflect.get(e, n, e);
135
+ return typeof r == "function" ? r.bind(e) : r;
136
+ } }), he = (u = {}) => {
137
+ if (re({
138
+ ...process.env,
139
+ ...u.env ?? {}
140
+ }), u.fieldEncryptionKey !== void 0 && u.fieldKeys !== void 0) throw Error("makeTestContext: pass `fieldEncryptionKey` or `fieldKeys`, not both — one is a keyring of one key");
141
+ if (u.fieldEncryptionKey !== void 0 && j(C(u.fieldEncryptionKey)), u.fieldKeys !== void 0 && n(u.fieldKeys), u.relations !== void 0) {
142
+ s();
143
+ for (let e of u.relations) c(e);
144
+ }
145
+ let f = u.tables ?? o(), _ = T(f), v = new m(u.store ?? {});
146
+ for (let e of u.plugins ?? []) e.bindDataStore?.(v);
147
+ let y = {
148
+ dataStore: v,
149
+ schemaRegistry: _
150
+ };
151
+ M(y);
152
+ let b = new e(u.clockStart);
153
+ x();
154
+ let O = l.runSync(ie.make.pipe(l.provide(ae({ now: () => b.now() }))));
155
+ v.onChange((e) => {
156
+ l.runSync(O.invalidateTag(e.table).pipe(l.ignore));
157
+ });
158
+ let A = [], P = {
159
+ wrapDynamic: (e, t, n, r) => O.wrapDynamic(e, t, n, r),
160
+ policyFor: E,
161
+ codeIdentity: "test",
162
+ maxEntryBytes: 1048576,
163
+ notice: (e, t, n) => {
164
+ A.push(n);
165
+ }
166
+ }, R = new r(), H = i(), U = new a(u.llmResponses ?? []), G = le(() => b.now()), K = ue(() => b.now()), q = (e, n, r = v, i, a = !1) => {
167
+ let o = {
168
+ subject: e,
169
+ traceId: F,
170
+ ...n === void 0 ? {} : { connection: n }
171
+ }, s = i?.queued ?? [], c = i?.nudges ?? [], l = ne({
172
+ bus: H.bus,
173
+ tenantId: e.tenantId ?? null,
174
+ ...r === v ? {} : { deferToCommit: (e) => {
175
+ s.push(async () => {
176
+ e();
177
+ });
178
+ } }
179
+ }), d = te({ store: r }), f = a ? async () => h : pe(e, u.rowFilter, y), m = {
180
+ apis: u.apis ?? Object.freeze({}),
181
+ transaction: async (t, i) => {
182
+ let o = k(e, i?.tenantId, r !== v);
183
+ if (o !== e) return q(o, n, v, void 0, !0).transaction(t);
184
+ if (r !== v) return t(m);
185
+ let s, l = await r.transactional(async (r) => {
186
+ let i = q(e, n, r, {
187
+ queued: [],
188
+ nudges: []
189
+ }, a), o = await t(i);
190
+ return s = i, o;
191
+ });
192
+ return s !== void 0 && (await Y(s), c.push(...X(s))), l;
193
+ },
194
+ clock: b,
195
+ webhooks: R,
196
+ events: l,
197
+ eventBus: H,
198
+ llm: U,
199
+ ...u.ai === void 0 ? {} : { ai: u.ai },
200
+ request: o,
201
+ ...n === void 0 ? {} : { connectionState: ee(n, r === v ? void 0 : (e) => {
202
+ s.push(e);
203
+ }) },
204
+ validation: g,
205
+ access: S(e),
206
+ cache: G,
207
+ kv: K,
208
+ store: N(D($(r, f)), {
209
+ subject: e,
210
+ schemaRegistry: _,
211
+ rowFilter: h
212
+ }),
213
+ storeForTenant: (t) => N($(r, f), {
214
+ subject: p(e, t),
215
+ schemaRegistry: _,
216
+ rowFilter: h
217
+ }),
218
+ outbox: w({
219
+ store: r,
220
+ subject: e,
221
+ traceId: F,
222
+ nudge: () => {
223
+ c.push(F);
224
+ },
225
+ afterCommit: (e) => {
226
+ s.push(e);
227
+ }
228
+ }),
229
+ load: d.load,
230
+ loadMany: d.loadMany,
231
+ withSubject: (e, t) => Promise.resolve(t(q(e, n, r, {
232
+ queued: s,
233
+ nudges: c
234
+ }))),
235
+ withTenant: (t, i) => Promise.resolve(i(q({
236
+ ...e,
237
+ tenantId: t
238
+ }, n, r, {
239
+ queued: s,
240
+ nudges: c
241
+ }))),
242
+ asSubject: (e) => q(e, n, r, {
243
+ queued: s,
244
+ nudges: c
245
+ }),
246
+ asTenant: (t) => q({
247
+ ...e,
248
+ tenantId: t
249
+ }, n, r, {
250
+ queued: s,
251
+ nudges: c
252
+ })
253
+ };
254
+ return z.set(m, s), L.set(m, (t) => q(e, t, r, {
255
+ queued: s,
256
+ nudges: c
257
+ })), B.set(m, c), V.set(m, u.plugins ?? []), J.set(m, u.layers ?? []), W.set(m, {
258
+ deps: P,
259
+ rowFilter: async () => u.rowFilter === void 0 ? void 0 : f(),
260
+ notices: A
261
+ }), I.set(m, (t) => r.transactional((r) => t(q(e, n, r, {
262
+ queued: s,
263
+ nudges: c
264
+ })))), t(m, v), m;
265
+ };
266
+ return q(u.subject ?? d(null), u.connection);
267
+ };
268
+ //#endregion
269
+ export { he as makeTestContext, K as markRestInvocation, P as mockStore, X as outboxNudgesOf, H as pluginsOf, G as queryCacheOf, ce as resetAfterCommit, q as restInvocationOf, oe as rpcInterceptorFor, Y as runAfterCommit, Z as runInStoreTransaction, se as serviceLayerFor, R as withRpcConnection };
@@ -0,0 +1,73 @@
1
+ import { Effect as e, Result as t } from "effect";
2
+ import { eventRoute as n } from "@voltro/protocol";
3
+ import { EventBus as r, publishEvent as i } from "@voltro/runtime";
4
+ //#region src/testEventBus.ts
5
+ var a = (a = {}) => {
6
+ let o = a.tenantId ?? null, s = new r({
7
+ origin: a.origin ?? "test",
8
+ ...a.ringSize === void 0 ? {} : { ringSize: a.ringSize }
9
+ });
10
+ return {
11
+ publish: async (n, r, a) => {
12
+ let c = await e.runPromise(e.result(i({
13
+ bus: s,
14
+ tenantId: o
15
+ }, n, r, a)));
16
+ if (t.isFailure(c)) {
17
+ let e = c.failure;
18
+ throw Error(`testEventBus.publish(${n.name}) was rejected: ${e._tag}`, { cause: e });
19
+ }
20
+ return { n: c.success.n };
21
+ },
22
+ subscribe: (e, t, n) => {
23
+ let r = [], i = [];
24
+ return {
25
+ get received() {
26
+ return r.map((e) => e.payload);
27
+ },
28
+ get deliveries() {
29
+ return r;
30
+ },
31
+ get missed() {
32
+ return i;
33
+ },
34
+ get missedCount() {
35
+ return i.reduce((e, t) => e + t.count, 0);
36
+ },
37
+ stop: s.subscribe({
38
+ tenantId: n?.tenantId ?? o,
39
+ event: e.name,
40
+ key: t,
41
+ listener: (e) => {
42
+ e.kind === "gap" ? i.push({
43
+ count: e.missed,
44
+ reason: e.reason
45
+ }) : r.push({
46
+ payload: e.envelope.payload,
47
+ origin: e.envelope.origin,
48
+ n: e.envelope.n
49
+ });
50
+ },
51
+ ...n?.resume === void 0 ? {} : { options: { resume: n.resume } }
52
+ })
53
+ };
54
+ },
55
+ skipSerials: (e, t, r, i) => {
56
+ let a = i?.tenantId ?? o, c = {
57
+ route: n(a, e.name, t),
58
+ event: e.name,
59
+ origin: "test-gap",
60
+ n: r + 1,
61
+ emittedAt: Date.now(),
62
+ payload: void 0
63
+ };
64
+ s.injectRemote(c);
65
+ },
66
+ bus: s,
67
+ reset: () => {
68
+ s.clear();
69
+ }
70
+ };
71
+ };
72
+ //#endregion
73
+ export { a as testEventBus };
@@ -0,0 +1,121 @@
1
+ import { markRestInvocation as e, pluginsOf as t } from "./testContext.js";
2
+ import { invoke as n } from "./invoke.js";
3
+ import { Effect as r } from "effect";
4
+ import { composeAuthStrategies as i, composeReplayAuthorityBindings as a } from "@voltro/protocol";
5
+ import { resolveRequestClientAddress as o, resolveTrustedProxies as s } from "@voltro/runtime";
6
+ import { collectPublicApiRoutes as c, dispatchSharedPath as l, restRoutesToHttpRoutes as u } from "@voltro/protocol/rest";
7
+ //#region src/testRequest.ts
8
+ var d = "127.0.0.1", f = (e) => {
9
+ let t = e.indexOf("?");
10
+ return t === -1 ? {
11
+ path: e,
12
+ query: ""
13
+ } : {
14
+ path: e.slice(0, t),
15
+ query: e.slice(t + 1)
16
+ };
17
+ }, p = (e, t) => {
18
+ let n = e.split("/").filter((e) => e.length > 0), r = t.split("/").filter((e) => e.length > 0);
19
+ return n.length === r.length && n.every((e, t) => e.startsWith(":") || e === r[t]);
20
+ }, m = (e) => {
21
+ let t = {};
22
+ for (let [n, r] of Object.entries(e)) t[n.toLowerCase()] = r;
23
+ return t;
24
+ }, h = (e) => e === void 0 ? /* @__PURE__ */ new Uint8Array() : new TextEncoder().encode(JSON.stringify(e)), g = (e) => e === void 0 ? "" : typeof e == "string" ? e : new TextDecoder().decode(e), _ = (_) => {
25
+ let v = s(_.security?.trustedProxies, process.env, _.security?.clientAddressHeader), { ctx: y } = _, b = c((_.publicApi ?? []).map((t) => ({
26
+ descriptor: t.descriptor,
27
+ invoke: (r, i) => y.withSubject(i.subject, (a) => (t.descriptor.publicApi !== void 0 && e(a, t.descriptor.publicApi, i.remoteAddr), n(t.descriptor, t.handler, r, a)))
28
+ })), {
29
+ pluginErrors: t(y).flatMap((e) => e.errorSchemas ?? []),
30
+ ..._.publicApiProfile === void 0 ? {} : { profile: _.publicApiProfile }
31
+ }), x = [..._.restRoutes ?? [], ...b], S = i(_.strategies ?? [], {
32
+ anonymous: _.anonymous ?? { headerOrTenant: "acme" },
33
+ getStore: () => y.store
34
+ }), C = (e, n) => {
35
+ let i = a(t(y)), s = {
36
+ store: y.store,
37
+ traceId: () => y.request.traceId,
38
+ ...i === void 0 ? {} : { bindReplayAuthority: i },
39
+ ...t(y).some((e) => e.restRateLimit !== void 0) ? { rateLimit: (e, n, i) => r.forEach(t(y), (t) => t.restRateLimit?.(e, n, i) ?? r.void, { discard: !0 }) } : {},
40
+ buildContext: (e) => y.asSubject(e),
41
+ resolveSubject: e === void 0 ? async (e) => (await S({
42
+ headers: e,
43
+ clientId: -1
44
+ })).subject : () => e,
45
+ ..._.idempotency === void 0 ? {} : { idempotency: _.idempotency }
46
+ }, c = u(x, s).map((e, t) => ({
47
+ pattern: x[t].path,
48
+ route: e
49
+ })), b = async (e, t, r = {}) => {
50
+ let { path: i, query: a } = f(t), s = c.filter((e) => p(e.pattern, i)).map((e) => e.route);
51
+ if (s.length === 0) return {
52
+ status: 404,
53
+ headers: {},
54
+ text: "",
55
+ body: {
56
+ error: "No route mounted for this path",
57
+ mounted: x.map((e) => e.path)
58
+ },
59
+ stream: !1
60
+ };
61
+ let u = {
62
+ ...m(n),
63
+ ...m(r.headers ?? {})
64
+ }, _ = o({
65
+ socketAddress: r.remoteAddr ?? d,
66
+ headers: u,
67
+ config: v
68
+ }), b = {
69
+ method: e.toUpperCase(),
70
+ path: i,
71
+ query: a,
72
+ headers: u,
73
+ rawBody: h(r.body),
74
+ store: y.store,
75
+ ..._ === void 0 ? {} : { remoteAddr: _ }
76
+ }, S = await l(s, b), C = {};
77
+ for (let [e, t] of Object.entries(S.headers ?? {})) C[e.toLowerCase()] = t;
78
+ S.contentType !== void 0 && (C["content-type"] = S.contentType);
79
+ let w = typeof S.body == "string" ? new TextEncoder().encode(S.body) : S.body ?? /* @__PURE__ */ new Uint8Array();
80
+ if (S.byteStream !== void 0) {
81
+ let e = S.byteStream.stream, t = typeof e == "function" ? e() : e;
82
+ w = new Uint8Array(await new Response(t).arrayBuffer());
83
+ }
84
+ let T = g(w), E = (S.contentType ?? "").includes("json");
85
+ return {
86
+ status: S.status,
87
+ headers: C,
88
+ text: T,
89
+ body: E && T !== "" ? JSON.parse(T) : void 0,
90
+ bytes: w,
91
+ stream: S.stream !== void 0 || S.byteStream !== void 0
92
+ };
93
+ };
94
+ return {
95
+ actingAs: (e) => C(e, n),
96
+ withHeaders: (t) => C(e, {
97
+ ...n,
98
+ ...t
99
+ }),
100
+ get: (e, t) => b("GET", e, t ?? {}),
101
+ delete: (e, t) => b("DELETE", e, t ?? {}),
102
+ post: (e, t, n) => b("POST", e, {
103
+ ...n ?? {},
104
+ body: t
105
+ }),
106
+ put: (e, t, n) => b("PUT", e, {
107
+ ...n ?? {},
108
+ body: t
109
+ }),
110
+ patch: (e, t, n) => b("PATCH", e, {
111
+ ...n ?? {},
112
+ body: t
113
+ }),
114
+ request: (e, t, n) => b(e, t, n ?? {}),
115
+ paths: x.map((e) => e.path)
116
+ };
117
+ };
118
+ return C(void 0, {});
119
+ };
120
+ //#endregion
121
+ export { _ as makeTestApp };
@@ -0,0 +1,26 @@
1
+ import { Layer as e } from "effect";
2
+ import { layerConfiguredConnections as t } from "@voltro/kv/connection";
3
+ //#region src/withConnections.ts
4
+ var n = (n, r = {}) => {
5
+ let i = r.connections ?? {}, a = { ...i.redis };
6
+ for (let [e, t] of Object.entries(n)) {
7
+ if (!/^redis:[A-Za-z][A-Za-z0-9_-]*$/.test(e)) throw Error("Connection test overrides require redis:name references");
8
+ let n = e.slice(6);
9
+ if (i.redis !== void 0 && !Object.hasOwn(i.redis, n)) throw Error("Connection test override must name a declared app entry");
10
+ if (t._tag !== "MemoryRedisConnection") throw Error("Connection test overrides require memory() entries");
11
+ a[n] = t;
12
+ }
13
+ let o = {
14
+ ...i,
15
+ redis: a,
16
+ ...i.nats === void 0 ? {} : { nats: { ...i.nats } },
17
+ ...i.defaults === void 0 ? {} : { defaults: { ...i.defaults } },
18
+ ...i.bindings === void 0 ? {} : { bindings: Object.fromEntries(Object.entries(i.bindings).map(([e, t]) => [e, { ...t }])) }
19
+ };
20
+ return t({
21
+ connections: o,
22
+ ...r.connectAnalytics === void 0 ? {} : { connectAnalytics: r.connectAnalytics }
23
+ }).pipe(e.orDie);
24
+ };
25
+ //#endregion
26
+ export { n as withConnections };
@@ -0,0 +1,85 @@
1
+ import { Effect as e, Layer as t, Result as n } from "effect";
2
+ import { getFieldCipher as r, makeEffectStoreLayer as i, makeFieldCipher as a } from "@voltro/runtime";
3
+ import { randomBytes as o } from "node:crypto";
4
+ import { CurrentWorkflowRunId as s, failureMessage as c, getWorkflowJournalCipher as l, inMemoryWorkflowEngineLayer as u, makeInMemoryRecorder as d, setWorkflowJournalCipher as f } from "@voltro/workflow";
5
+ //#region src/workflowRunner.ts
6
+ var p = (e) => {
7
+ let t = /* @__PURE__ */ new Map();
8
+ for (let n of e) {
9
+ let e = t.get(n.stepName);
10
+ e === void 0 ? t.set(n.stepName, [n]) : e.push(n);
11
+ }
12
+ let n = [];
13
+ for (let [e, r] of t) {
14
+ r.sort((e, t) => e.attempt - t.attempt);
15
+ let t = r[r.length - 1], i = t.errorTag !== null || t.errorMessage !== null ? {
16
+ tag: t.errorTag,
17
+ message: t.errorMessage ?? ""
18
+ } : null;
19
+ n.push({
20
+ name: e,
21
+ attempt: t.attempt,
22
+ attempts: r.length,
23
+ status: t.status,
24
+ input: t.input,
25
+ output: t.output,
26
+ error: i,
27
+ durationMs: t.durationMs,
28
+ _startedAt: r[0].startedAt.getTime()
29
+ });
30
+ }
31
+ return n.sort((e, t) => e._startedAt - t._startedAt), n.map(({ _startedAt: e, ...t }) => t);
32
+ }, m = () => {
33
+ if (l() !== void 0) return;
34
+ let e = a(o(32).toString("hex"));
35
+ f(() => r() ?? e);
36
+ }, h = (r) => {
37
+ m();
38
+ let a = r.workflows ?? [], o = /* @__PURE__ */ new Map(), l = 0;
39
+ return {
40
+ start: async (f, m) => {
41
+ let h = a.find((e) => e.workflow.name === f);
42
+ if (h === void 0) throw Error(`makeWorkflowRunner: no workflow named '${f}' — pass it in makeWorkflowRunner({ ctx, workflows: [{ workflow, execute }] }).`);
43
+ let g = `wfrun_test_${++l}`, _ = d(), v = h.workflow.toLayer(h.execute).pipe(t.provideMerge(u)), y = /* @__PURE__ */ new Date(), b = h.workflow.execute(m).pipe(e.provideService(s, g), e.provide(_.layer), e.provide(v)), x = (r.ctx.store === void 0 ? b : e.provide(b, i(r.ctx.store))).pipe(e.result), S = await e.runPromise(x), C = p(_.readSteps()), w = /* @__PURE__ */ new Date(), T;
44
+ if (n.isSuccess(S)) T = {
45
+ status: "succeeded",
46
+ output: S.success,
47
+ error: null,
48
+ steps: C,
49
+ runId: g
50
+ };
51
+ else {
52
+ let e = S.failure;
53
+ T = {
54
+ status: "failed",
55
+ output: null,
56
+ error: {
57
+ tag: e && typeof e == "object" && "_tag" in e ? String(e._tag) : null,
58
+ message: c(S.failure)
59
+ },
60
+ steps: C,
61
+ runId: g
62
+ };
63
+ }
64
+ return o.set(g, {
65
+ id: g,
66
+ executionId: g,
67
+ name: f,
68
+ status: T.status,
69
+ input: m,
70
+ output: T.output,
71
+ subject: r.ctx.request.subject,
72
+ source: "test-runner",
73
+ steps: C,
74
+ startedAt: y,
75
+ finishedAt: w,
76
+ traceId: null,
77
+ parentExecutionId: null,
78
+ parentClosePolicy: null
79
+ }), T;
80
+ },
81
+ inspect: async (e) => o.get(e) ?? null
82
+ };
83
+ };
84
+ //#endregion
85
+ export { h as makeWorkflowRunner };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/testing",
3
- "version": "0.85.0",
3
+ "version": "0.87.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,6 +43,11 @@
43
43
  "import": "./dist/crdt.js",
44
44
  "default": "./dist/crdt.js"
45
45
  },
46
+ "./system": {
47
+ "types": "./dist/system.d.ts",
48
+ "import": "./dist/system.js",
49
+ "default": "./dist/system.js"
50
+ },
46
51
  "./package.json": "./package.json"
47
52
  },
48
53
  "main": "./dist/index.js",
@@ -53,16 +58,18 @@
53
58
  "node": ">=24.0.0"
54
59
  },
55
60
  "dependencies": {
56
- "@voltro/database": "0.85.0",
57
- "@voltro/env": "0.85.0",
58
- "@voltro/local-first": "0.85.0",
59
- "@voltro/logger": "0.85.0",
60
- "@voltro/protocol": "0.85.0",
61
- "@voltro/runtime": "0.85.0",
62
- "@voltro/workflow": "0.85.0"
61
+ "@voltro/cache": "0.87.0",
62
+ "@voltro/database": "0.87.0",
63
+ "@voltro/env": "0.87.0",
64
+ "@voltro/kv": "0.87.0",
65
+ "@voltro/local-first": "0.87.0",
66
+ "@voltro/logger": "0.87.0",
67
+ "@voltro/protocol": "0.87.0",
68
+ "@voltro/runtime": "0.87.0",
69
+ "@voltro/workflow": "0.87.0"
63
70
  },
64
71
  "peerDependencies": {
65
- "@voltro/client": "0.85.0",
72
+ "@voltro/client": "0.87.0",
66
73
  "effect": "4.0.1",
67
74
  "react": "^19.0.0",
68
75
  "react-dom": "^19.0.0",