@niwa-labs/workflow 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +13 -2
- package/package.json +55 -4
- package/src/actions.ts +408 -0
- package/src/agent.ts +211 -0
- package/src/ask.ts +84 -0
- package/src/bridge.ts +710 -0
- package/src/catalogue.ts +74 -0
- package/src/check.ts +880 -0
- package/src/child.ts +1378 -0
- package/src/cockpit/actions.ts +128 -0
- package/src/cockpit/catalogue-actions.ts +97 -0
- package/src/cockpit/dashboard.tsx +134 -0
- package/src/cockpit/groups.ts +45 -0
- package/src/cockpit/index.tsx +50 -0
- package/src/cockpit/launch.tsx +136 -0
- package/src/cockpit/plan.ts +101 -0
- package/src/cockpit/run-commands.tsx +102 -0
- package/src/cockpit/run-page.tsx +140 -0
- package/src/cockpit/run-summary.ts +16 -0
- package/src/cockpit/runs.tsx +73 -0
- package/src/cockpit/statistics.tsx +176 -0
- package/src/cockpit/track.tsx +159 -0
- package/src/cockpit/workflows.tsx +383 -0
- package/src/describe-cache.ts +122 -0
- package/src/describe.ts +174 -0
- package/src/guide.ts +213 -0
- package/src/index.ts +2813 -0
- package/src/inspect.ts +235 -0
- package/src/installation.ts +90 -0
- package/src/language.ts +217 -0
- package/src/records-entry.ts +63 -0
- package/src/records.ts +574 -0
- package/src/registry.ts +250 -0
- package/src/revise.ts +89 -0
- package/src/runner.ts +339 -0
- package/src/script-types.ts +549 -0
- package/src/stats.ts +460 -0
- package/src/status.ts +512 -0
- package/src/store.ts +259 -0
- package/src/subscriptions.ts +102 -0
- package/src/waiting.ts +61 -0
- package/test/cockpit-actions.test.ts +20 -0
- package/test/cockpit-groups.test.ts +42 -0
- package/test/cockpit-plan.test.ts +118 -0
- package/test/fixtures/branches-host.ts +58 -0
- package/test/fixtures/branches-script.js +23 -0
- package/test/fixtures/bridge-host.ts +23 -0
- package/test/fixtures/bridge-keys-script.js +15 -0
- package/test/fixtures/bridge-wait-script.js +8 -0
- package/test/fixtures/cancel-host.ts +58 -0
- package/test/fixtures/cancel-script.js +12 -0
- package/test/fixtures/crash-host.ts +61 -0
- package/test/fixtures/crash-script.js +14 -0
- package/test/fixtures/ping-records.ts +20 -0
- package/test/fixtures/revision-host.ts +57 -0
- package/test/fixtures/revision-script.js +11 -0
- package/test/fixtures/running-host.ts +61 -0
- package/test/fixtures/running-script.js +12 -0
- package/test/fixtures/with-data/flow.ts +2 -0
- package/test/fixtures/with-data/table.json +1 -0
- package/test/git-repo.ts +45 -0
- package/test/git-worktree.test.ts +413 -0
- package/test/question-format.test.ts +279 -0
- package/test/workflow-agent-caps.test.ts +91 -0
- package/test/workflow-agent-lifetime.test.ts +93 -0
- package/test/workflow-agent-options.test.ts +216 -0
- package/test/workflow-agent-schema.test.ts +386 -0
- package/test/workflow-agent-typings.test.ts +241 -0
- package/test/workflow-ask-resume.test.ts +145 -0
- package/test/workflow-branch-keys.test.ts +133 -0
- package/test/workflow-bridge-inproc.test.ts +230 -0
- package/test/workflow-bridge.test.ts +141 -0
- package/test/workflow-builtin-candidate.test.ts +230 -0
- package/test/workflow-builtin.test.ts +197 -0
- package/test/workflow-cancel-agent.test.ts +144 -0
- package/test/workflow-cancel.test.ts +166 -0
- package/test/workflow-chain.test.ts +84 -0
- package/test/workflow-check-options.test.ts +144 -0
- package/test/workflow-check-uses.test.ts +148 -0
- package/test/workflow-check.test.ts +282 -0
- package/test/workflow-contract.test.ts +295 -0
- package/test/workflow-crash-resume.test.ts +141 -0
- package/test/workflow-deadline.test.ts +102 -0
- package/test/workflow-describe-cache.test.ts +240 -0
- package/test/workflow-directory.test.ts +73 -0
- package/test/workflow-emits.test.ts +261 -0
- package/test/workflow-group-keys.test.ts +72 -0
- package/test/workflow-harnesses.test.ts +262 -0
- package/test/workflow-inspect.test.ts +152 -0
- package/test/workflow-language-types.test.ts +148 -0
- package/test/workflow-manifest.test.ts +93 -0
- package/test/workflow-manual-pause.test.ts +116 -0
- package/test/workflow-owners.test.ts +154 -0
- package/test/workflow-pause.test.ts +200 -0
- package/test/workflow-phases.test.ts +445 -0
- package/test/workflow-plugin-entries.test.ts +59 -0
- package/test/workflow-record-refs.test.ts +310 -0
- package/test/workflow-replay.test.ts +206 -0
- package/test/workflow-resume-once.test.ts +188 -0
- package/test/workflow-revision.test.ts +216 -0
- package/test/workflow-scope.test.ts +505 -0
- package/test/workflow-script-defaults.test.ts +119 -0
- package/test/workflow-script-error.test.ts +228 -0
- package/test/workflow-script-libraries.test.ts +88 -0
- package/test/workflow-script-packages.test.ts +119 -0
- package/test/workflow-stdout.test.ts +89 -0
- package/test/workflow-stop.test.ts +299 -0
- package/test/workflow-store.test.ts +220 -0
- package/test/workflow-visible.test.ts +136 -0
- package/test/workflow-wait-version.test.ts +54 -0
- package/test/workflow-wait.test.ts +224 -0
- package/test/workflow-waiting-agent.test.ts +64 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
// Scopes: groups of branches that never outlive their block.
|
|
2
|
+
//
|
|
3
|
+
// The host keeps a group: the branches that joined it, their outcomes in the order it committed
|
|
4
|
+
// them, and how it closed. Leaving the block waits for the branches or cancels them, a block that
|
|
5
|
+
// throws cancels them, a cancel goes down into the scopes inside except a shield, and a deadline
|
|
6
|
+
// cancels the scope on the clock of the host. The host is in this process and its clock is the
|
|
7
|
+
// test's, so a deadline is moved to and not waited for.
|
|
8
|
+
|
|
9
|
+
import { afterEach, expect, test } from "bun:test";
|
|
10
|
+
import { writeFile } from "node:fs/promises";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
15
|
+
import { action } from "@niwa-labs/core";
|
|
16
|
+
import type { ActionName, StoredRecord } from "@niwa-labs/core";
|
|
17
|
+
import { plugin } from "@niwa-labs/plugin";
|
|
18
|
+
import { createNiwa, eventually, requests, stub, tempHome, testClock, timers } from "@niwa-labs/testing";
|
|
19
|
+
import type { Host, TestClock } from "@niwa-labs/testing";
|
|
20
|
+
|
|
21
|
+
import { workflow } from "../src/index.ts";
|
|
22
|
+
|
|
23
|
+
const START = 1_700_000_000_000;
|
|
24
|
+
const MINUTE = 60_000;
|
|
25
|
+
|
|
26
|
+
const homes: Array<{ cleanup(): Promise<void> }> = [];
|
|
27
|
+
const hosts: Host[] = [];
|
|
28
|
+
|
|
29
|
+
afterEach(async () => {
|
|
30
|
+
for (const host of hosts.splice(0)) await host.close().catch(() => {});
|
|
31
|
+
for (const home of homes.splice(0)) await home.cleanup();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/** What the actions of the test saw: the calls by name, the most at once, and the calls that were aborted. */
|
|
35
|
+
interface Seen {
|
|
36
|
+
calls: string[];
|
|
37
|
+
active: number;
|
|
38
|
+
most: number;
|
|
39
|
+
aborted: string[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The plugin of the test: `scope.work` takes a while and counts how many run at once, `scope.hang` runs until it is aborted. */
|
|
43
|
+
function work(seen: Seen) {
|
|
44
|
+
return plugin("scope", (api) => {
|
|
45
|
+
api.action(
|
|
46
|
+
action("scope.work", {
|
|
47
|
+
description: "Works for a few milliseconds.",
|
|
48
|
+
input: z.object({ name: z.string(), ms: z.number().optional() }),
|
|
49
|
+
output: z.object({ name: z.string() }),
|
|
50
|
+
recovery: "repeat",
|
|
51
|
+
effect: "write",
|
|
52
|
+
run: async ({ name, ms }) => {
|
|
53
|
+
seen.calls.push(name);
|
|
54
|
+
seen.active += 1;
|
|
55
|
+
seen.most = Math.max(seen.most, seen.active);
|
|
56
|
+
await Bun.sleep(ms ?? 5);
|
|
57
|
+
seen.active -= 1;
|
|
58
|
+
return { name };
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
api.action(
|
|
63
|
+
action("scope.fail", {
|
|
64
|
+
description: "Fails.",
|
|
65
|
+
input: z.object({ name: z.string() }),
|
|
66
|
+
output: z.object({ name: z.string() }),
|
|
67
|
+
recovery: "repeat",
|
|
68
|
+
effect: "write",
|
|
69
|
+
run: async ({ name }) => {
|
|
70
|
+
seen.calls.push(name);
|
|
71
|
+
throw new Error("the work failed");
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
api.action(
|
|
76
|
+
action("scope.hang", {
|
|
77
|
+
description: "Runs until it is aborted.",
|
|
78
|
+
input: z.object({ name: z.string() }),
|
|
79
|
+
output: z.object({ name: z.string() }),
|
|
80
|
+
recovery: "do-not-repeat",
|
|
81
|
+
effect: "write",
|
|
82
|
+
run: ({ name }, ctx) =>
|
|
83
|
+
new Promise((_resolve, reject) => {
|
|
84
|
+
seen.calls.push(name);
|
|
85
|
+
ctx.signal?.addEventListener("abort", () => {
|
|
86
|
+
seen.aborted.push(name);
|
|
87
|
+
reject(new Error("aborted"));
|
|
88
|
+
});
|
|
89
|
+
}),
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function hostOn(path: string, clock: TestClock, seen: Seen): Promise<Host> {
|
|
96
|
+
const niwa = createNiwa({ home: path, clock });
|
|
97
|
+
niwa.use(requests());
|
|
98
|
+
niwa.use(timers([]));
|
|
99
|
+
niwa.use(stub(path));
|
|
100
|
+
niwa.use(work(seen));
|
|
101
|
+
niwa.use(workflow());
|
|
102
|
+
await niwa.serve();
|
|
103
|
+
hosts.push(niwa);
|
|
104
|
+
return niwa;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const ofType = (records: readonly StoredRecord[], type: string): StoredRecord[] => records.filter((row) => row.type === type);
|
|
108
|
+
|
|
109
|
+
/** A host and a home, and the way to run a script on them and read how it ended. */
|
|
110
|
+
async function setup() {
|
|
111
|
+
const home = await tempHome();
|
|
112
|
+
homes.push(home);
|
|
113
|
+
const clock = testClock(START);
|
|
114
|
+
const seen: Seen = { calls: [], active: 0, most: 0, aborted: [] };
|
|
115
|
+
const niwa = await hostOn(home.path, clock, seen);
|
|
116
|
+
const records = (): Promise<StoredRecord[]> => niwa.records.read();
|
|
117
|
+
let scripts = 0;
|
|
118
|
+
return {
|
|
119
|
+
niwa,
|
|
120
|
+
clock,
|
|
121
|
+
seen,
|
|
122
|
+
records,
|
|
123
|
+
start: async (source: string, extra: Record<string, unknown> = {}): Promise<string> => {
|
|
124
|
+
const file = join(home.path, `script-${String((scripts += 1))}.js`);
|
|
125
|
+
await writeFile(file, source);
|
|
126
|
+
const started = (await niwa.call("workflow.start" as ActionName, { file, ...extra } as never)) as { run: string };
|
|
127
|
+
return started.run;
|
|
128
|
+
},
|
|
129
|
+
ended: async (run: string): Promise<{ status: string; result?: unknown; error?: { message: string } }> => {
|
|
130
|
+
await eventually(
|
|
131
|
+
async () =>
|
|
132
|
+
ofType(await records(), "workflow.run.finished").some((row) => (row.data as { run: string }).run === run) ||
|
|
133
|
+
ofType(await records(), "workflow.run.paused").some((row) => (row.data as { run: string }).run === run),
|
|
134
|
+
15_000,
|
|
135
|
+
"the run should end",
|
|
136
|
+
);
|
|
137
|
+
const all = await records();
|
|
138
|
+
const finished = ofType(all, "workflow.run.finished").find((row) => (row.data as { run: string }).run === run);
|
|
139
|
+
if (finished !== undefined) return (finished.data as { outcome: { status: string; result?: unknown } }).outcome;
|
|
140
|
+
const paused = ofType(all, "workflow.run.paused").find((row) => (row.data as { run: string }).run === run);
|
|
141
|
+
return { status: "paused", error: { message: (paused?.data as { reason: string }).reason } };
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
test("a scope gives the outcomes of its branches in the order the host committed them, and the host keeps the group", async () => {
|
|
147
|
+
const t = await setup();
|
|
148
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
149
|
+
return await scope("probe", undefined, async (s) => {
|
|
150
|
+
s.start("slow", () => niwa.scope.work({ name: "slow", ms: 60 }));
|
|
151
|
+
s.start("fast", () => niwa.scope.work({ name: "fast", ms: 1 }));
|
|
152
|
+
s.start("bad", async () => { throw new Error("no good"); });
|
|
153
|
+
const order = [];
|
|
154
|
+
for (let got = await s.next(); got !== null; got = await s.next()) order.push([got.key, got.result.ok]);
|
|
155
|
+
return { order, rest: await s.rest(), path: s.path };
|
|
156
|
+
});
|
|
157
|
+
});`);
|
|
158
|
+
const outcome = await t.ended(run);
|
|
159
|
+
expect(outcome.status).toBe("done");
|
|
160
|
+
const result = outcome.result as { order: Array<[string, boolean]>; rest: Record<string, unknown>; path: string[] };
|
|
161
|
+
expect(result.order.map(([key]) => key).sort()).toEqual(["bad", "fast", "slow"]);
|
|
162
|
+
expect(result.order.at(-1)).toEqual(["slow", true]);
|
|
163
|
+
expect(result.rest).toEqual({
|
|
164
|
+
slow: { ok: true, value: { name: "slow" } },
|
|
165
|
+
fast: { ok: true, value: { name: "fast" } },
|
|
166
|
+
bad: { ok: false, error: { name: "Error", message: "no good" } },
|
|
167
|
+
});
|
|
168
|
+
expect(result.path).toEqual(["probe"]);
|
|
169
|
+
|
|
170
|
+
const all = await t.records();
|
|
171
|
+
expect(ofType(all, "workflow.scope.opened").map((row) => row.data)).toEqual([{ run, scope: "@probe", onExit: "wait" }]);
|
|
172
|
+
expect(ofType(all, "workflow.scope.branched").map((row) => (row.data as { key: string }).key)).toEqual(["slow", "fast", "bad"]);
|
|
173
|
+
// The order of the commits is the order next() gave: the place of each outcome is written with it.
|
|
174
|
+
const settled = ofType(all, "workflow.scope.settled").map((row) => row.data as { key: string; order: number; outcome: string });
|
|
175
|
+
expect(settled.map(({ key, order }) => [key, order])).toEqual(result.order.map(([key], index) => [key, index]));
|
|
176
|
+
expect(settled.find((one) => one.key === "bad")?.outcome).toBe("failed");
|
|
177
|
+
expect(ofType(all, "workflow.scope.closed").map((row) => row.data)).toEqual([{ run, scope: "@probe", outcome: "done" }]);
|
|
178
|
+
// Each branch joined the group before its first step: the record is written before the intent of its call.
|
|
179
|
+
const joined = all.findIndex((row) => row.type === "workflow.scope.branched" && (row.data as { key: string }).key === "slow");
|
|
180
|
+
const called = all.findIndex((row) => row.type === "niwa.step.intent" && (row.data as { key: string }).key === "@probe.slow.call-1");
|
|
181
|
+
expect(joined).toBeGreaterThanOrEqual(0);
|
|
182
|
+
expect(joined).toBeLessThan(called);
|
|
183
|
+
}, 30_000);
|
|
184
|
+
|
|
185
|
+
test("leaving a scope with onExit cancel cancels the branches left: their steps end as cancelled and their work is aborted", async () => {
|
|
186
|
+
const t = await setup();
|
|
187
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
188
|
+
return await scope("first", { onExit: "cancel" }, async (s) => {
|
|
189
|
+
s.start("quick", () => niwa.scope.work({ name: "quick" }));
|
|
190
|
+
const hung = s.start("hung", () => niwa.scope.hang({ name: "hung" }));
|
|
191
|
+
const first = await s.next();
|
|
192
|
+
return { first: first.key, hung: hung };
|
|
193
|
+
}).then(async (out) => ({ first: out.first, hung: await out.hung.settled() }));
|
|
194
|
+
});`);
|
|
195
|
+
const outcome = await t.ended(run);
|
|
196
|
+
expect(outcome.status).toBe("done");
|
|
197
|
+
expect(outcome.result).toEqual({ first: "quick", hung: { ok: false, error: { name: "Cancelled", message: "the scope was left" } } });
|
|
198
|
+
expect(t.seen.aborted).toEqual(["hung"]);
|
|
199
|
+
const all = await t.records();
|
|
200
|
+
const hungOutcome = ofType(all, "niwa.step.outcome").find((row) => (row.data as { key: string }).key === "@first.hung.call-1");
|
|
201
|
+
expect((hungOutcome?.data as { outcome: unknown }).outcome).toEqual({ status: "cancelled", reason: "the scope was left" });
|
|
202
|
+
expect(ofType(all, "workflow.scope.settled").find((row) => (row.data as { key: string }).key === "hung")?.data).toMatchObject({ outcome: "cancelled" });
|
|
203
|
+
}, 30_000);
|
|
204
|
+
|
|
205
|
+
test("a block that throws cancels its branches, and the error comes out of the scope once they ended", async () => {
|
|
206
|
+
const t = await setup();
|
|
207
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
208
|
+
try {
|
|
209
|
+
await scope("fails", undefined, async (s) => {
|
|
210
|
+
s.start("hung", () => niwa.scope.hang({ name: "hung" }));
|
|
211
|
+
await niwa.scope.work({ name: "block" });
|
|
212
|
+
throw new Error("the block gave up");
|
|
213
|
+
});
|
|
214
|
+
return "not reached";
|
|
215
|
+
} catch (error) {
|
|
216
|
+
return error.message;
|
|
217
|
+
}
|
|
218
|
+
});`);
|
|
219
|
+
const outcome = await t.ended(run);
|
|
220
|
+
expect(outcome).toMatchObject({ status: "done", result: "the block gave up" });
|
|
221
|
+
expect(t.seen.aborted).toEqual(["hung"]);
|
|
222
|
+
}, 30_000);
|
|
223
|
+
|
|
224
|
+
test("a cancel goes down into the scopes inside a branch, and a shield is waited for instead", async () => {
|
|
225
|
+
const t = await setup();
|
|
226
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
227
|
+
return await scope("outer", undefined, async (s) => {
|
|
228
|
+
s.start("deep", () => scope("inner", undefined, async (inner) => {
|
|
229
|
+
inner.start("hung", () => niwa.scope.hang({ name: "inner-hung" }));
|
|
230
|
+
return await inner.rest();
|
|
231
|
+
}));
|
|
232
|
+
s.start("guarded", () => scope("safe", { shield: true }, async () => {
|
|
233
|
+
await niwa.scope.work({ name: "shielded", ms: 40 });
|
|
234
|
+
return "finished under the shield";
|
|
235
|
+
}));
|
|
236
|
+
await niwa.scope.work({ name: "block" });
|
|
237
|
+
await s.cancel("enough");
|
|
238
|
+
return await s.rest();
|
|
239
|
+
});
|
|
240
|
+
});`);
|
|
241
|
+
const outcome = await t.ended(run);
|
|
242
|
+
expect(outcome.status).toBe("done");
|
|
243
|
+
const rest = outcome.result as Record<string, { ok: boolean; value?: unknown; error?: { name: string } }>;
|
|
244
|
+
// The inner scope's branch was cancelled with its outer branch; the inner block gave its rest back.
|
|
245
|
+
expect(rest.deep).toEqual({ ok: true, value: { hung: { ok: false, error: { name: "Cancelled", message: "enough" } } } });
|
|
246
|
+
// The shielded block went on to its end.
|
|
247
|
+
expect(rest.guarded).toEqual({ ok: true, value: "finished under the shield" });
|
|
248
|
+
expect(t.seen.aborted).toEqual(["inner-hung"]);
|
|
249
|
+
expect(t.seen.calls).toContain("shielded");
|
|
250
|
+
}, 30_000);
|
|
251
|
+
|
|
252
|
+
test("a deadline cancels the scope on the clock of the host: skip gives undefined, fail throws DeadlineExceeded", async () => {
|
|
253
|
+
const t = await setup();
|
|
254
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
255
|
+
const skipped = await moveOnAfter("slow", "5m", () => niwa.scope.hang({ name: "slow" }));
|
|
256
|
+
let failed = "no error";
|
|
257
|
+
try {
|
|
258
|
+
await failAfter("slower", "1m", () => niwa.scope.hang({ name: "slower" }));
|
|
259
|
+
} catch (error) {
|
|
260
|
+
failed = error.name;
|
|
261
|
+
}
|
|
262
|
+
return { skipped: skipped ?? "undefined", failed };
|
|
263
|
+
});`);
|
|
264
|
+
await eventually(() => t.seen.calls.includes("slow"), 10_000, "the first block should start");
|
|
265
|
+
await t.clock.advance(5 * MINUTE - 1);
|
|
266
|
+
expect(t.seen.aborted).toEqual([]);
|
|
267
|
+
await t.clock.advance(1);
|
|
268
|
+
await eventually(() => t.seen.calls.includes("slower"), 10_000, "the second block should start");
|
|
269
|
+
await t.clock.advance(MINUTE);
|
|
270
|
+
const outcome = await t.ended(run);
|
|
271
|
+
expect(outcome).toEqual({ status: "done", result: { skipped: "undefined", failed: "DeadlineExceeded" } });
|
|
272
|
+
expect(t.seen.aborted).toEqual(["slow", "slower"]);
|
|
273
|
+
const closed = ofType(await t.records(), "workflow.scope.closed").map((row) => (row.data as { outcome: string }).outcome);
|
|
274
|
+
expect(closed).toEqual(["deadline", "deadline"]);
|
|
275
|
+
}, 30_000);
|
|
276
|
+
|
|
277
|
+
test("a scope runs no more branches at once than its limit, and a start caps every scope of the run from outside", async () => {
|
|
278
|
+
const t = await setup();
|
|
279
|
+
const script = `export default workflow({ output: z.json() }, async () => {
|
|
280
|
+
return await parallel({ a: () => niwa.scope.work({ name: "a", ms: 20 }), b: () => niwa.scope.work({ name: "b", ms: 20 }),
|
|
281
|
+
c: () => niwa.scope.work({ name: "c", ms: 20 }), d: () => niwa.scope.work({ name: "d", ms: 20 }) }, { concurrency: 3 });
|
|
282
|
+
});`;
|
|
283
|
+
const first = await t.start(script);
|
|
284
|
+
expect(await t.ended(first)).toEqual({
|
|
285
|
+
status: "done",
|
|
286
|
+
result: { a: { name: "a" }, b: { name: "b" }, c: { name: "c" }, d: { name: "d" } },
|
|
287
|
+
});
|
|
288
|
+
expect(t.seen.most).toBe(3);
|
|
289
|
+
t.seen.most = 0;
|
|
290
|
+
const second = await t.start(script, { concurrency: 1 });
|
|
291
|
+
expect((await t.ended(second)).status).toBe("done");
|
|
292
|
+
expect(t.seen.most).toBe(1);
|
|
293
|
+
}, 30_000);
|
|
294
|
+
|
|
295
|
+
test("the keys of branches and the names of scopes are refused before any step when they are empty, repeated or hold a mark", async () => {
|
|
296
|
+
const t = await setup();
|
|
297
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
298
|
+
const refused = [];
|
|
299
|
+
for (const key of ["", "a.b", "a~b", "a:b", "call-1"]) {
|
|
300
|
+
try { await scope("k" + refused.length, undefined, async (s) => { s.start(key, () => 1); }); refused.push("taken"); }
|
|
301
|
+
catch (error) { refused.push("refused"); }
|
|
302
|
+
}
|
|
303
|
+
try { await scope("twice", undefined, async (s) => { s.start("x", () => 1); s.start("x", () => 2); }); refused.push("taken"); }
|
|
304
|
+
catch (error) { refused.push("refused"); }
|
|
305
|
+
try { await scope("a.b", undefined, async () => 1); refused.push("taken"); } catch (error) { refused.push("refused"); }
|
|
306
|
+
return refused;
|
|
307
|
+
});`);
|
|
308
|
+
expect(await t.ended(run)).toEqual({ status: "done", result: Array(7).fill("refused") });
|
|
309
|
+
expect(t.seen.calls).toEqual([]);
|
|
310
|
+
}, 30_000);
|
|
311
|
+
|
|
312
|
+
test("a stream gives the outcomes one at a time and closing it cancels the rest; race gives the first branch that succeeds", async () => {
|
|
313
|
+
const t = await setup();
|
|
314
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
315
|
+
const probes = stream("probe", { fast: () => niwa.scope.work({ name: "fast", ms: 1 }), stuck: () => niwa.scope.hang({ name: "stuck" }) });
|
|
316
|
+
const first = await probes.next();
|
|
317
|
+
await probes.close();
|
|
318
|
+
const won = await race("pick", { broken: async () => { throw new Error("broken"); }, good: () => niwa.scope.work({ name: "good" }), hung: () => niwa.scope.hang({ name: "hung" }) });
|
|
319
|
+
return { first: first.key, won };
|
|
320
|
+
});`);
|
|
321
|
+
expect(await t.ended(run)).toEqual({ status: "done", result: { first: "fast", won: { key: "good", value: { name: "good" } } } });
|
|
322
|
+
expect(t.seen.aborted.sort()).toEqual(["hung", "stuck"]);
|
|
323
|
+
}, 30_000);
|
|
324
|
+
|
|
325
|
+
test("a branch that sleeps suspends the run while the block waits in next(), and the run goes on after the wake", async () => {
|
|
326
|
+
const t = await setup();
|
|
327
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
328
|
+
return await scope("nap", undefined, async (s) => {
|
|
329
|
+
s.start("sleeper", async () => { await sleep("10m"); return "woke"; });
|
|
330
|
+
s.start("quick", () => niwa.scope.work({ name: "quick" }));
|
|
331
|
+
const first = await s.next();
|
|
332
|
+
const second = await s.next();
|
|
333
|
+
return Object.fromEntries([first, second].map((got) => [got.key, got.result.value]));
|
|
334
|
+
});
|
|
335
|
+
});`);
|
|
336
|
+
await eventually(
|
|
337
|
+
async () => ofType(await t.records(), "niwa.invocation.state").some((row) => (row.data as { state: string }).state === "waiting"),
|
|
338
|
+
10_000,
|
|
339
|
+
"the run should wait for the sleep",
|
|
340
|
+
);
|
|
341
|
+
await t.clock.advance(10 * MINUTE);
|
|
342
|
+
expect(await t.ended(run)).toEqual({ status: "done", result: { quick: { name: "quick" }, sleeper: "woke" } });
|
|
343
|
+
expect(t.seen.calls).toEqual(["quick"]);
|
|
344
|
+
}, 30_000);
|
|
345
|
+
|
|
346
|
+
test("after a wake the outcomes come in the order the script read them before, whichever branch ends first now", async () => {
|
|
347
|
+
const t = await setup();
|
|
348
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
349
|
+
return await scope("order", undefined, async (s) => {
|
|
350
|
+
s.start("slow", () => niwa.scope.work({ name: "slow", ms: 300 }));
|
|
351
|
+
// On the replay both calls answer from the journal at once: the pause makes "fast" end after "slow" there.
|
|
352
|
+
s.start("fast", async () => { const done = await niwa.scope.work({ name: "fast", ms: 1 }); await new Promise((r) => setTimeout(r, 100)); return done; });
|
|
353
|
+
const first = await s.next();
|
|
354
|
+
await sleep("1m");
|
|
355
|
+
const second = await s.next();
|
|
356
|
+
return [first.key, second.key];
|
|
357
|
+
});
|
|
358
|
+
});`);
|
|
359
|
+
await eventually(
|
|
360
|
+
async () => ofType(await t.records(), "niwa.invocation.state").some((row) => (row.data as { state: string }).state === "waiting"),
|
|
361
|
+
10_000,
|
|
362
|
+
"the run should wait for the sleep",
|
|
363
|
+
);
|
|
364
|
+
await t.clock.advance(MINUTE);
|
|
365
|
+
expect(await t.ended(run)).toEqual({ status: "done", result: ["fast", "slow"] });
|
|
366
|
+
const settled = ofType(await t.records(), "workflow.scope.settled").map((row) => row.data as { key: string; order: number });
|
|
367
|
+
expect(new Set(settled.map(({ key, order }) => `${key}:${String(order)}`))).toEqual(new Set(["fast:0", "slow:1"]));
|
|
368
|
+
}, 30_000);
|
|
369
|
+
|
|
370
|
+
test("a step of a branch that does not complete pauses the run: it is not an outcome of the branch, and nothing is cancelled for good", async () => {
|
|
371
|
+
const t = await setup();
|
|
372
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
373
|
+
return await scope("mixed", undefined, async (s) => {
|
|
374
|
+
s.start("broken", () => niwa.scope.fail({ name: "broken" }));
|
|
375
|
+
s.start("hung", () => niwa.scope.hang({ name: "hung" }));
|
|
376
|
+
return await s.rest();
|
|
377
|
+
});
|
|
378
|
+
});`);
|
|
379
|
+
const outcome = await t.ended(run);
|
|
380
|
+
expect(outcome.status).toBe("paused");
|
|
381
|
+
const all = await t.records();
|
|
382
|
+
expect(ofType(all, "workflow.run.finished")).toEqual([]);
|
|
383
|
+
expect((ofType(all, "workflow.run.paused")[0]?.data as { choices: string[] }).choices).toEqual(["retry", "skip", "cancel"]);
|
|
384
|
+
expect(ofType(all, "niwa.step.cancelled")).toEqual([]);
|
|
385
|
+
expect(ofType(all, "workflow.scope.settled")).toEqual([]);
|
|
386
|
+
}, 30_000);
|
|
387
|
+
|
|
388
|
+
test("a branch that waits does not stop the others: they go on and record their steps before the run waits", async () => {
|
|
389
|
+
const t = await setup();
|
|
390
|
+
await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
391
|
+
return await scope("apart", undefined, async (s) => {
|
|
392
|
+
s.start("waits", () => wait("stub.finished", { filter: { id: "never" } }));
|
|
393
|
+
s.start("works", async () => { await niwa.scope.work({ name: "first", ms: 50 }); return niwa.scope.work({ name: "second" }); });
|
|
394
|
+
return await s.rest();
|
|
395
|
+
});
|
|
396
|
+
});`);
|
|
397
|
+
await eventually(() => t.seen.calls.includes("second"), 10_000, "the working branch should go on");
|
|
398
|
+
await eventually(
|
|
399
|
+
async () => ofType(await t.records(), "niwa.invocation.state").at(-1)?.data !== undefined &&
|
|
400
|
+
(ofType(await t.records(), "niwa.invocation.state").at(-1)?.data as { state: string }).state === "waiting",
|
|
401
|
+
10_000,
|
|
402
|
+
"the run should wait",
|
|
403
|
+
);
|
|
404
|
+
expect(ofType(await t.records(), "workflow.scope.settled").map((row) => (row.data as { key: string }).key)).toEqual(["works"]);
|
|
405
|
+
}, 30_000);
|
|
406
|
+
|
|
407
|
+
test("workflow.inspect lists the steps of scopes and of keyed parallel branches, with the branch each one is in", async () => {
|
|
408
|
+
const t = await setup();
|
|
409
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
410
|
+
await scope("probe", undefined, async (s) => {
|
|
411
|
+
s.start("slow", () => niwa.scope.work({ name: "slow" }));
|
|
412
|
+
await niwa.scope.work({ name: "block" });
|
|
413
|
+
});
|
|
414
|
+
await parallel({ left: () => niwa.scope.work({ name: "left" }) });
|
|
415
|
+
return null;
|
|
416
|
+
});`);
|
|
417
|
+
expect((await t.ended(run)).status).toBe("done");
|
|
418
|
+
const inspected = (await t.niwa.call("workflow.inspect" as ActionName, { run } as never)) as { steps: Array<{ key: string; branch?: string }> };
|
|
419
|
+
expect(inspected.steps.map((step) => [step.key, step.branch]).sort()).toEqual([
|
|
420
|
+
["@probe.call-1", "@probe"],
|
|
421
|
+
["@probe.slow.call-1", "@probe.slow"],
|
|
422
|
+
["p1.left.call-1", "p1.left"],
|
|
423
|
+
]);
|
|
424
|
+
}, 30_000);
|
|
425
|
+
|
|
426
|
+
test("a race of two waits ends when the first record arrives, and the wait that lost is cancelled", async () => {
|
|
427
|
+
const t = await setup();
|
|
428
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
429
|
+
const won = await race("either", {
|
|
430
|
+
a: async () => { await wait("stub.finished", { filter: { id: "a" } }); return "a"; },
|
|
431
|
+
b: async () => { await wait("stub.finished", { filter: { id: "b" } }); return "b"; },
|
|
432
|
+
});
|
|
433
|
+
return won;
|
|
434
|
+
});`);
|
|
435
|
+
await eventually(
|
|
436
|
+
async () => ofType(await t.records(), "niwa.invocation.state").at(-1)?.data !== undefined &&
|
|
437
|
+
(ofType(await t.records(), "niwa.invocation.state").at(-1)?.data as { state: string }).state === "waiting",
|
|
438
|
+
10_000,
|
|
439
|
+
"the run should wait for both records",
|
|
440
|
+
);
|
|
441
|
+
await t.niwa.call("stub.finish" as ActionName, { id: "b" } as never);
|
|
442
|
+
expect(await t.ended(run)).toEqual({ status: "done", result: { key: "b", value: "b" } });
|
|
443
|
+
const settled = ofType(await t.records(), "workflow.scope.settled").map((row) => row.data as { key: string; outcome: string });
|
|
444
|
+
expect(settled.map(({ key, outcome }) => `${key}:${outcome}`).sort()).toEqual(["a:cancelled", "b:done"]);
|
|
445
|
+
}, 30_000);
|
|
446
|
+
|
|
447
|
+
test("next() over a stream of waits gives the first record to arrive, and closing the stream cancels the wait left", async () => {
|
|
448
|
+
const t = await setup();
|
|
449
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
450
|
+
const either = stream("either", {
|
|
451
|
+
a: () => wait("stub.finished", { filter: { id: "a" } }),
|
|
452
|
+
b: () => wait("stub.finished", { filter: { id: "b" }, timeout: "1h" }),
|
|
453
|
+
});
|
|
454
|
+
const first = await either.next();
|
|
455
|
+
await either.close();
|
|
456
|
+
return first.key;
|
|
457
|
+
});`);
|
|
458
|
+
await eventually(
|
|
459
|
+
async () => (ofType(await t.records(), "niwa.invocation.state").at(-1)?.data as { state: string } | undefined)?.state === "waiting",
|
|
460
|
+
10_000,
|
|
461
|
+
"the run should wait for both records",
|
|
462
|
+
);
|
|
463
|
+
await t.niwa.call("stub.finish" as ActionName, { id: "a" } as never);
|
|
464
|
+
expect(await t.ended(run)).toEqual({ status: "done", result: "a" });
|
|
465
|
+
const settled = ofType(await t.records(), "workflow.scope.settled").map((row) => row.data as { key: string; outcome: string });
|
|
466
|
+
expect(settled.map(({ key, outcome }) => `${key}:${outcome}`).sort()).toEqual(["a:done", "b:cancelled"]);
|
|
467
|
+
}, 30_000);
|
|
468
|
+
|
|
469
|
+
test("the cancel of the branches left is the same on the replay, whichever of them ended before the block left", async () => {
|
|
470
|
+
const t = await setup();
|
|
471
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
472
|
+
return await race("either", {
|
|
473
|
+
a: async () => { await wait("stub.finished", { filter: { id: "a" } }); for (let n = 0; n < 3; n += 1) await now(); return "a"; },
|
|
474
|
+
// On the replay the cancel reaches b at its first step and c only after ten: b ends before the winner does, c after.
|
|
475
|
+
b: () => wait("stub.finished", { filter: { id: "b" } }),
|
|
476
|
+
c: async () => { for (let n = 0; n < 10; n += 1) await now(); return wait("stub.finished", { filter: { id: "c" } }); },
|
|
477
|
+
});
|
|
478
|
+
});`);
|
|
479
|
+
await eventually(
|
|
480
|
+
async () => ofType(await t.records(), "niwa.step.intent").filter((row) => (row.data as { action: string }).action === "niwa.wait").length === 3,
|
|
481
|
+
10_000,
|
|
482
|
+
"the run should wait for the three records",
|
|
483
|
+
);
|
|
484
|
+
await t.niwa.call("stub.finish" as ActionName, { id: "a" } as never);
|
|
485
|
+
expect(await t.ended(run)).toEqual({ status: "done", result: { key: "a", value: "a" } });
|
|
486
|
+
const settled = ofType(await t.records(), "workflow.scope.settled").map((row) => row.data as { key: string; outcome: string });
|
|
487
|
+
expect(settled.map(({ key, outcome }) => `${key}:${outcome}`).sort()).toEqual(["a:done", "b:cancelled", "c:cancelled"]);
|
|
488
|
+
}, 30_000);
|
|
489
|
+
|
|
490
|
+
test("a branch that runs its own code after a wait is not stopped while another branch waits", async () => {
|
|
491
|
+
const t = await setup();
|
|
492
|
+
const run = await t.start(`export default workflow({ output: z.json() }, async () => {
|
|
493
|
+
return await race("either", {
|
|
494
|
+
a: async () => { await wait("stub.finished", { filter: { id: "a" } }); await new Promise((r) => setTimeout(r, 300)); return "a"; },
|
|
495
|
+
b: () => wait("stub.finished", { filter: { id: "b" } }),
|
|
496
|
+
});
|
|
497
|
+
});`);
|
|
498
|
+
await eventually(
|
|
499
|
+
async () => ofType(await t.records(), "niwa.step.intent").filter((row) => (row.data as { action: string }).action === "niwa.wait").length === 2,
|
|
500
|
+
10_000,
|
|
501
|
+
"the run should wait for both records",
|
|
502
|
+
);
|
|
503
|
+
await t.niwa.call("stub.finish" as ActionName, { id: "a" } as never);
|
|
504
|
+
expect(await t.ended(run)).toEqual({ status: "done", result: { key: "a", value: "a" } });
|
|
505
|
+
}, 30_000);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// What a script may do with no setup of the composition and nothing in `uses`: emit its own
|
|
2
|
+
// `wf.*` records, and ask the owner, who is told that the run asks.
|
|
3
|
+
|
|
4
|
+
import { afterEach, expect, test } from "bun:test";
|
|
5
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
import { actionName, grant, principalOf, seq, owner } from "@niwa-labs/core";
|
|
9
|
+
import type { StoredRecord } from "@niwa-labs/core";
|
|
10
|
+
import { connect, createNiwa, requests, eventually, tempHome } from "@niwa-labs/testing";
|
|
11
|
+
import type { Host, NiwaApi } from "@niwa-labs/testing";
|
|
12
|
+
import { workflow } from "../src/index.ts";
|
|
13
|
+
|
|
14
|
+
const START = actionName("workflow.start");
|
|
15
|
+
|
|
16
|
+
const homes: Array<{ cleanup(): Promise<void> }> = [];
|
|
17
|
+
const hosts: Host[] = [];
|
|
18
|
+
const clients: NiwaApi[] = [];
|
|
19
|
+
|
|
20
|
+
afterEach(async () => {
|
|
21
|
+
for (const client of clients.splice(0)) await client.close().catch(() => {});
|
|
22
|
+
for (const host of hosts.splice(0)) await host.close().catch(() => {});
|
|
23
|
+
for (const home of homes.splice(0)) await home.cleanup();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/** A host whose every caller speaks as the owner, a workflow with no `emits`, and a caller that may only start runs. */
|
|
27
|
+
async function served(): Promise<{ host: Host; caller: NiwaApi; home: string }> {
|
|
28
|
+
const home = await tempHome();
|
|
29
|
+
homes.push(home);
|
|
30
|
+
const host = createNiwa({ home: home.path });
|
|
31
|
+
const bind = () => owner;
|
|
32
|
+
host.use(requests({ bind }), workflow());
|
|
33
|
+
await host.serve();
|
|
34
|
+
hosts.push(host);
|
|
35
|
+
const secret = host.issueToken(principalOf("session", "starter"), { grant: grant(["workflow.start", "workflow.check"]) });
|
|
36
|
+
const caller = await connect({ home: home.path, id: "session:starter", token: secret });
|
|
37
|
+
clients.push(caller);
|
|
38
|
+
return { host, caller, home: home.path };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function scriptIn(home: string, lines: readonly string[]): Promise<string> {
|
|
42
|
+
await mkdir(home, { recursive: true });
|
|
43
|
+
const file = join(home, "script.js");
|
|
44
|
+
await writeFile(file, lines.join("\n"));
|
|
45
|
+
return file;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const ofType = async (host: Host, type: string): Promise<StoredRecord[]> =>
|
|
49
|
+
(await host.records.read()).filter((row) => row.type === type);
|
|
50
|
+
|
|
51
|
+
test("a script emits the wf.* records it declares and asks the owner with nothing in uses and no emits in the composition", async () => {
|
|
52
|
+
const { host, caller, home } = await served();
|
|
53
|
+
const file = await scriptIn(home, [
|
|
54
|
+
'const Note = record("note", z.object({ text: z.string() }));',
|
|
55
|
+
'export default workflow({ name: "free", emits: [Note], output: z.json() }, async () => {',
|
|
56
|
+
' await emit(Note, { text: "hi" });',
|
|
57
|
+
' return await ask.confirm("go on?");',
|
|
58
|
+
'});',
|
|
59
|
+
]);
|
|
60
|
+
const { run } = (await caller.call(START, { file })) as { run: string };
|
|
61
|
+
|
|
62
|
+
await eventually(async () => (await ofType(host, "request.created")).length === 1, 10_000, "the run should ask");
|
|
63
|
+
const note = (await ofType(host, "wf.free.note"))[0];
|
|
64
|
+
expect(note?.data).toEqual({ text: "hi" });
|
|
65
|
+
// The question says who asks: the run, not whoever the host binds its callers to.
|
|
66
|
+
const asked = (await ofType(host, "request.created"))[0]?.data as { from?: unknown; to: unknown };
|
|
67
|
+
expect(asked.from).toEqual({ kind: "client", id: `run:${run}` });
|
|
68
|
+
expect(asked.to).toEqual({ kind: "owner" });
|
|
69
|
+
}, 30_000);
|
|
70
|
+
|
|
71
|
+
test("a script emits only the records it lists in emits (one the check cannot see is refused when it runs), with data its schema holds", async () => {
|
|
72
|
+
const { host, caller, home } = await served();
|
|
73
|
+
const paused = async (lines: readonly string[]): Promise<string> => {
|
|
74
|
+
const file = await scriptIn(home, lines);
|
|
75
|
+
const { run } = (await caller.call(START, { file })) as { run: string };
|
|
76
|
+
await eventually(async () => (await ofType(host, "workflow.run.paused")).some((row) => (row.data as { run: string }).run === run), 10_000, "the run should pause");
|
|
77
|
+
return (await ofType(host, "workflow.run.paused")).map((row) => row.data as { run: string; reason: string }).find((data) => data.run === run)?.reason ?? "";
|
|
78
|
+
};
|
|
79
|
+
// The name is bound to another record after the declaration was read: the text matches, the record does not.
|
|
80
|
+
expect(
|
|
81
|
+
await paused([
|
|
82
|
+
'let Done = record("done", z.object({ run: z.string() }));',
|
|
83
|
+
'export default workflow({ name: "mine", emits: [Done] }, async () => {',
|
|
84
|
+
' Done = record("spoof", z.object({ run: z.string() }));',
|
|
85
|
+
' await emit(Done, { run: "x" });',
|
|
86
|
+
"});",
|
|
87
|
+
]),
|
|
88
|
+
).toContain("lists in workflow({ emits })");
|
|
89
|
+
// A plain JS script is not type-checked: the data the schema refuses is refused when it runs.
|
|
90
|
+
expect(
|
|
91
|
+
await paused([
|
|
92
|
+
'const Done = record("done", z.object({ run: z.string() }));',
|
|
93
|
+
'export default workflow({ name: "mine", emits: [Done] }, async () => {',
|
|
94
|
+
" await emit(Done, { run: 3 });",
|
|
95
|
+
"});",
|
|
96
|
+
]),
|
|
97
|
+
).toContain("expected string");
|
|
98
|
+
expect((await ofType(host, "wf.mine.done")).length + (await ofType(host, "wf.mine.spoof")).length).toBe(0);
|
|
99
|
+
}, 30_000);
|
|
100
|
+
|
|
101
|
+
test("workflow.check reports an emit of a record the script does not list, and emits in a script with no name", async () => {
|
|
102
|
+
const { caller, home } = await served();
|
|
103
|
+
const check = async (lines: readonly string[]) =>
|
|
104
|
+
(await caller.call(actionName("workflow.check"), { file: await scriptIn(home, lines) })) as { ok: boolean; errors: Array<{ code: string; line: number; message: string }> };
|
|
105
|
+
const unlisted = await check([
|
|
106
|
+
'const Ok = record("ok", z.object({}));',
|
|
107
|
+
'const Spoof = record("spoof", z.object({}));',
|
|
108
|
+
'export default workflow({ name: "mine", emits: [Ok] }, async () => {',
|
|
109
|
+
" await emit(Ok, {});",
|
|
110
|
+
" await emit(Spoof, {});",
|
|
111
|
+
"});",
|
|
112
|
+
]);
|
|
113
|
+
expect(unlisted.ok).toBe(false);
|
|
114
|
+
expect(unlisted.errors).toHaveLength(1);
|
|
115
|
+
expect(unlisted.errors[0]).toMatchObject({ code: "emit", line: 5 });
|
|
116
|
+
expect(unlisted.errors[0]?.message).toContain("lists in workflow({ emits })");
|
|
117
|
+
const nameless = await check(['const Ok = record("ok", z.object({}));', "export default workflow({ emits: [Ok] }, async () => {", " await emit(Ok, {});", "});"]);
|
|
118
|
+
expect(nameless.errors).toMatchObject([{ code: "emit", line: 2, message: expect.stringContaining("declares a name") }]);
|
|
119
|
+
}, 30_000);
|