@voltro/testing 0.85.0 → 0.86.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 +666 -0
- package/THIRD-PARTY-NOTICES.md +5 -33
- package/dist/client.js +73 -98
- package/dist/dialect.js +244 -145
- package/dist/factory.js +65 -0
- package/dist/fixtureRow.js +30 -0
- package/dist/formBindingHarness.js +46 -0
- package/dist/hydrateFixtureRows.js +22 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +19 -933
- package/dist/invoke.js +44 -0
- package/dist/mockClock.js +78 -0
- package/dist/mockLLM.js +19 -0
- package/dist/mockWebhooks.js +26 -0
- package/dist/platform.js +1 -5
- package/dist/reachable.js +27 -0
- package/dist/serviceApiMock.js +53 -0
- package/dist/subject.js +11 -0
- package/dist/subscribeContext.js +16 -0
- package/dist/testApps.js +111 -0
- package/dist/testContext.js +248 -0
- package/dist/testEventBus.js +73 -0
- package/dist/testRequest.js +119 -0
- package/dist/workflowRunner.js +85 -0
- package/package.json +9 -9
|
@@ -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,119 @@
|
|
|
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 } from "@voltro/protocol";
|
|
5
|
+
import { resolveRequestClientAddress as a, resolveTrustedProxies as o } from "@voltro/runtime";
|
|
6
|
+
import { collectPublicApiRoutes as s, dispatchSharedPath as c, restRoutesToHttpRoutes as l } from "@voltro/protocol/rest";
|
|
7
|
+
//#region src/testRequest.ts
|
|
8
|
+
var u = "127.0.0.1", d = (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
|
+
}, f = (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
|
+
}, p = (e) => {
|
|
21
|
+
let t = {};
|
|
22
|
+
for (let [n, r] of Object.entries(e)) t[n.toLowerCase()] = r;
|
|
23
|
+
return t;
|
|
24
|
+
}, m = (e) => e === void 0 ? /* @__PURE__ */ new Uint8Array() : new TextEncoder().encode(JSON.stringify(e)), h = (e) => e === void 0 ? "" : typeof e == "string" ? e : new TextDecoder().decode(e), g = (g) => {
|
|
25
|
+
let _ = o(g.security?.trustedProxies, process.env, g.security?.clientAddressHeader), { ctx: v } = g, y = s((g.publicApi ?? []).map((t) => ({
|
|
26
|
+
descriptor: t.descriptor,
|
|
27
|
+
invoke: (r, i) => v.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(v).flatMap((e) => e.errorSchemas ?? []),
|
|
30
|
+
...g.publicApiProfile === void 0 ? {} : { profile: g.publicApiProfile }
|
|
31
|
+
}), b = [...g.restRoutes ?? [], ...y], x = i(g.strategies ?? [], {
|
|
32
|
+
anonymous: g.anonymous ?? { headerOrTenant: "acme" },
|
|
33
|
+
getStore: () => v.store
|
|
34
|
+
}), S = (e, n) => {
|
|
35
|
+
let i = {
|
|
36
|
+
store: v.store,
|
|
37
|
+
...t(v).some((e) => e.restRateLimit !== void 0) ? { rateLimit: (e, n, i) => r.forEach(t(v), (t) => t.restRateLimit?.(e, n, i) ?? r.void, { discard: !0 }) } : {},
|
|
38
|
+
buildContext: () => v,
|
|
39
|
+
resolveSubject: e === void 0 ? async (e) => (await x({
|
|
40
|
+
headers: e,
|
|
41
|
+
clientId: -1
|
|
42
|
+
})).subject : () => e,
|
|
43
|
+
...g.idempotency === void 0 ? {} : { idempotency: g.idempotency }
|
|
44
|
+
}, o = l(b, i).map((e, t) => ({
|
|
45
|
+
pattern: b[t].path,
|
|
46
|
+
route: e
|
|
47
|
+
})), s = async (e, t, r = {}) => {
|
|
48
|
+
let { path: i, query: s } = d(t), l = o.filter((e) => f(e.pattern, i)).map((e) => e.route);
|
|
49
|
+
if (l.length === 0) return {
|
|
50
|
+
status: 404,
|
|
51
|
+
headers: {},
|
|
52
|
+
text: "",
|
|
53
|
+
body: {
|
|
54
|
+
error: "No route mounted for this path",
|
|
55
|
+
mounted: b.map((e) => e.path)
|
|
56
|
+
},
|
|
57
|
+
stream: !1
|
|
58
|
+
};
|
|
59
|
+
let g = {
|
|
60
|
+
...p(n),
|
|
61
|
+
...p(r.headers ?? {})
|
|
62
|
+
}, y = a({
|
|
63
|
+
socketAddress: r.remoteAddr ?? u,
|
|
64
|
+
headers: g,
|
|
65
|
+
config: _
|
|
66
|
+
}), x = {
|
|
67
|
+
method: e.toUpperCase(),
|
|
68
|
+
path: i,
|
|
69
|
+
query: s,
|
|
70
|
+
headers: g,
|
|
71
|
+
rawBody: m(r.body),
|
|
72
|
+
store: v.store,
|
|
73
|
+
...y === void 0 ? {} : { remoteAddr: y }
|
|
74
|
+
}, S = await c(l, x), C = {};
|
|
75
|
+
for (let [e, t] of Object.entries(S.headers ?? {})) C[e.toLowerCase()] = t;
|
|
76
|
+
S.contentType !== void 0 && (C["content-type"] = S.contentType);
|
|
77
|
+
let w = typeof S.body == "string" ? new TextEncoder().encode(S.body) : S.body ?? /* @__PURE__ */ new Uint8Array();
|
|
78
|
+
if (S.byteStream !== void 0) {
|
|
79
|
+
let e = S.byteStream.stream, t = typeof e == "function" ? e() : e;
|
|
80
|
+
w = new Uint8Array(await new Response(t).arrayBuffer());
|
|
81
|
+
}
|
|
82
|
+
let T = h(w), E = (S.contentType ?? "").includes("json");
|
|
83
|
+
return {
|
|
84
|
+
status: S.status,
|
|
85
|
+
headers: C,
|
|
86
|
+
text: T,
|
|
87
|
+
body: E && T !== "" ? JSON.parse(T) : void 0,
|
|
88
|
+
bytes: w,
|
|
89
|
+
stream: S.stream !== void 0 || S.byteStream !== void 0
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
actingAs: (e) => S(e, n),
|
|
94
|
+
withHeaders: (t) => S(e, {
|
|
95
|
+
...n,
|
|
96
|
+
...t
|
|
97
|
+
}),
|
|
98
|
+
get: (e, t) => s("GET", e, t ?? {}),
|
|
99
|
+
delete: (e, t) => s("DELETE", e, t ?? {}),
|
|
100
|
+
post: (e, t, n) => s("POST", e, {
|
|
101
|
+
...n ?? {},
|
|
102
|
+
body: t
|
|
103
|
+
}),
|
|
104
|
+
put: (e, t, n) => s("PUT", e, {
|
|
105
|
+
...n ?? {},
|
|
106
|
+
body: t
|
|
107
|
+
}),
|
|
108
|
+
patch: (e, t, n) => s("PATCH", e, {
|
|
109
|
+
...n ?? {},
|
|
110
|
+
body: t
|
|
111
|
+
}),
|
|
112
|
+
request: (e, t, n) => s(e, t, n ?? {}),
|
|
113
|
+
paths: b.map((e) => e.path)
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
return S(void 0, {});
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
export { g as makeTestApp };
|
|
@@ -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.
|
|
3
|
+
"version": "0.86.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",
|
|
@@ -53,16 +53,16 @@
|
|
|
53
53
|
"node": ">=24.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@voltro/database": "0.
|
|
57
|
-
"@voltro/env": "0.
|
|
58
|
-
"@voltro/local-first": "0.
|
|
59
|
-
"@voltro/logger": "0.
|
|
60
|
-
"@voltro/protocol": "0.
|
|
61
|
-
"@voltro/runtime": "0.
|
|
62
|
-
"@voltro/workflow": "0.
|
|
56
|
+
"@voltro/database": "0.86.0",
|
|
57
|
+
"@voltro/env": "0.86.0",
|
|
58
|
+
"@voltro/local-first": "0.86.0",
|
|
59
|
+
"@voltro/logger": "0.86.0",
|
|
60
|
+
"@voltro/protocol": "0.86.0",
|
|
61
|
+
"@voltro/runtime": "0.86.0",
|
|
62
|
+
"@voltro/workflow": "0.86.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@voltro/client": "0.
|
|
65
|
+
"@voltro/client": "0.86.0",
|
|
66
66
|
"effect": "4.0.1",
|
|
67
67
|
"react": "^19.0.0",
|
|
68
68
|
"react-dom": "^19.0.0",
|