Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

WorkflowRuntime.test.ts

535 lines24.7 KB

1import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { assert, it } from "@effect/vitest";
4import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
5import * as Context from "effect/Context";
6import * as Deferred from "effect/Deferred";
7import * as Effect from "effect/Effect";
8import * as Exit from "effect/Exit";
9import * as Fiber from "effect/Fiber";
10import * as FileSystem from "effect/FileSystem";
11import * as Layer from "effect/Layer";
12import * as Option from "effect/Option";
13import * as Queue from "effect/Queue";
14import * as Path from "effect/Path";
15import * as PlatformError from "effect/PlatformError";
16import * as Stream from "effect/Stream";
17import * as TestClock from "effect/testing/TestClock";
18import { ChildProcess, ChildProcessSpawner } from "effect/process";
19​
20import WorkflowsMigration from "../persistence/Migrations/110_Workflows.ts";
21import WorkflowSkippedRunsMigration from "../persistence/Migrations/113_WorkflowSkippedRuns.ts";
22import { type AgentResult, WorkflowAgents } from "./WorkflowAgents.ts";
23import * as WorkflowEngine from "./WorkflowEngine.ts";
24import * as WorkflowRuntime from "./WorkflowRuntime.ts";
25import { engineTag, type WorkflowDefinition } from "./workflow.ts";
26import * as Workflows from "./Workflows.ts";
27​
28/** Waits to be let go. */
29const hold = `T3.workflow("hold", { version: 1, payload: Schema.Struct({}), returns: Schema.String }, () =>
30 Effect.map(T3.wait("go", { returns: Schema.String }), (said) => Option.getOrElse(said, () => "nobody")),
31);
32`;
33const greet = (says: string) => `const { workflow } = T3;
34workflow("greet", { version: 1, payload: Schema.Struct({}), returns: Schema.String }, () =>
35 Effect.succeed(${JSON.stringify(says)}),
36);
37`;
38​
39/**
40 * A folder holding `hold.ts`, and the workflow runtime over it on a fresh database. `engine`
41 * stands in for the real one, which needs the clock to run for as long as it is up.
42 */
43const setup = Effect.fn("setup")(function* (
44 wrap: (fileSystem: FileSystem.FileSystem) => FileSystem.FileSystem = (fileSystem) => fileSystem,
45 engine?: (definitions: ReadonlyArray<WorkflowDefinition>) => Layer.Layer<Workflows.Workflows>,
46 agents?: WorkflowAgents["Service"],
47) {
48 const fileSystem = yield* FileSystem.FileSystem;
49 const path = yield* Path.Path;
50 const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-workflow-defs-" });
51 const directory = path.join(home, "workflows");
52 const at = (name: string) => path.join(directory, name);
53 yield* fileSystem.makeDirectory(directory);
54 yield* fileSystem.writeFileString(at("hold.ts"), hold);
55 const database = NodeSqliteClient.layer({ filename: path.join(home, "state.sqlite") });
56 yield* Effect.provide(Effect.andThen(WorkflowsMigration, WorkflowSkippedRunsMigration), database);
57 const made = WorkflowRuntime.make(
58 Effect.succeed(
59 (definitions: ReadonlyArray<WorkflowDefinition>) =>
60 engine?.(definitions) ??
61 WorkflowEngine.layer(definitions).pipe(
62 Layer.provide(
63 agents === undefined
64 ? Layer.mock(WorkflowAgents)({})
65 : Layer.succeed(WorkflowAgents, agents),
66 ),
67 Layer.provide(database),
68 Layer.provide(NodeCrypto.layer),
69 ),
70 ),
71 directory,
72 Effect.succeed(true),
73 ).pipe(Effect.provideService(FileSystem.FileSystem, wrap(fileSystem)));
74 return { fileSystem, at, directory, made, runtime: Layer.effectContext(made) };
75});
76​
77it.effect(
78 "every file in the folder defines workflows, and a saved file is verified before it runs",
79 () =>
80 Effect.gen(function* () {
81 const { fileSystem, at, runtime } = yield* setup();
82​
83 yield* Effect.gen(function* () {
84 const workflows = yield* Workflows.Workflows;
85 const definitions = yield* WorkflowRuntime.WorkflowDefinitions;
86 const held = yield* workflows.start("hold", {}, { idempotencyKey: "h" });
87 yield* workflows.waitFor(held.runId, (run) => run.status === "waiting");
88​
89 // A file that does not parse is not written, and says where it breaks.
90 const broken = yield* definitions.save("greet.ts", "T3.workflow(\n 'x',\n];\n");
91 assert.isFalse(broken.changed);
92 assert.deepStrictEqual(
93 broken.problems.map((problem) => [problem.file, problem.line]),
94 [["greet.ts", 3]],
95 );
96 // Nor is one that defines what another file already does, or drops what a run needs.
97 const twice = yield* definitions.save("again.ts", hold);
98 assert.include(
99 twice.problems[0]?.message ?? "",
100 "hold@1 is defined twice, in again.ts and hold.ts",
101 );
102 const dropped = yield* definitions.save("hold.ts", greet("hello"));
103 assert.include(
104 dropped.problems[0]?.message ?? "",
105 "hold@1 is no longer defined, and 1 of its runs",
106 );
107 // Nor one that exports something shaped like a workflow without what the engine walks.
108 const shaped = yield* definitions.save(
109 "shaped.ts",
110 'export default [{ name: "shaped", version: 1, body: () => Effect.void }];\n',
111 );
112 assert.include(shaped.problems[0]?.message ?? "", "is not a workflow");
113 // Nor one with an option nothing reads, or a time a schedule cannot fire at.
114 const misspelt = yield* definitions.save(
115 "misspelt.ts",
116 'T3.workflow("misspelt", { version: 1, payload: Schema.Struct({}), retries: 2 }, () => Effect.void);\n',
117 );
118 assert.include(misspelt.problems[0]?.message ?? "", "does not take `retries`");
119 const late = yield* definitions.save(
120 "late.ts",
121 'T3.workflow("late", { version: 1, payload: T3.Tick, triggers: [T3.daily("9am")] }, () => Effect.void);\n',
122 );
123 assert.include(late.problems[0]?.message ?? "", "24-hour time");
124 const banana = yield* definitions.save(
125 "banana.ts",
126 'T3.workflow("banana", { version: 1, payload: T3.Tick, triggers: [T3.every("banana")] }, () => Effect.void);\n',
127 );
128 assert.include(banana.problems[0]?.message ?? "", 'Write one such as "5 minutes"');
129 const twoHooks = yield* definitions.save(
130 "hooks.ts",
131 'T3.workflow("hooks", { version: 1, payload: T3.WebhookRequest, triggers: [T3.webhook("in"), T3.webhook("in")] }, () => Effect.void);\n',
132 );
133 assert.include(twoHooks.problems[0]?.message ?? "", 'two hooks named "in"');
134 assert.include((yield* definitions.remove("hold.ts")).problems[0]?.message ?? "", "hold@1");
135 assert.deepStrictEqual(
136 (yield* definitions.read).files.map((file) => file.name),
137 ["hold.ts"],
138 );
139 // The same change made outside the app is refused as a whole: the file still reads as the
140 // version that runs, until it is put back.
141 const told = (wanted: boolean) =>
142 workflows.watch.pipe(
143 Stream.filter((snapshot) => (snapshot.definition?.problem != null) === wanted),
144 Stream.runHead,
145 );
146 yield* fileSystem.writeFileString(at("hold.ts"), greet("hello"));
147 yield* told(true);
148 assert.deepStrictEqual(
149 (yield* definitions.read).files.map((file) => file.workflows),
150 [["hold@1"]],
151 );
152 // Only that file is held back: another file's change still runs, and the held one says why.
153 const other =
154 'T3.workflow("other", { version: 1, payload: Schema.Struct({}) }, () => Effect.void);\n';
155 // A file the folder's naming leaves out says so, instead of never running without a word.
156 yield* fileSystem.writeFileString(at("my flow.ts"), other);
157 assert.deepStrictEqual(yield* definitions.save("other.ts", other), {
158 changed: true,
159 problems: [],
160 });
161 yield* workflows.start("other", {}, { idempotencyKey: "o" });
162 assert.deepStrictEqual(
163 (yield* definitions.read).files.map((file) => [file.name, file.problems.length]),
164 [
165 ["hold.ts", 1],
166 ["other.ts", 0],
167 ],
168 );
169 assert.deepStrictEqual(
170 (yield* definitions.read).problems.map((problem) => problem.file),
171 ["my flow.ts"],
172 );
173 yield* fileSystem.remove(at("my flow.ts"));
174 assert.deepStrictEqual(yield* definitions.remove("other.ts"), {
175 changed: true,
176 problems: [],
177 });
178 yield* fileSystem.writeFileString(at("hold.ts"), hold);
179 yield* told(false);
180​
181 // A new file that passes is there from now on, and what it defines can be started.
182 const saved = { changed: true, problems: [] };
183 assert.deepStrictEqual(yield* definitions.save("greet.ts", greet("hello")), saved);
184 assert.equal(yield* fileSystem.readFileString(at("greet.ts")), greet("hello"));
185 const greeted = yield* workflows.start("greet", {}, { idempotencyKey: "g" });
186 const done = yield* workflows.waitFor(greeted.runId, (run) => run.status === "completed");
187 assert.equal(done.result, "hello");
188 // The run that was waiting came through the reload and can still be let go.
189 yield* workflows.signal({ runId: held.runId, wait: "go" }, "go on", { id: "s1" });
190 const freed = yield* workflows.waitFor(held.runId, (run) => run.status === "completed");
191 assert.equal(freed.result, "go on");
192​
193 // Someone breaks a file outside the app: its last good version keeps running, and the
194 // other files go on changing.
195 const problem = (wanted: boolean) =>
196 workflows.watch.pipe(
197 Stream.filter((snapshot) => (snapshot.definition?.problem != null) === wanted),
198 Stream.runHead,
199 );
200 yield* fileSystem.writeFileString(at("greet.ts"), "T3.workflow(");
201 yield* problem(true);
202 const read = yield* definitions.read;
203 assert.deepStrictEqual(
204 read.files.map((file) => [file.name, file.problems.length]),
205 [
206 ["greet.ts", 1],
207 ["hold.ts", 0],
208 ],
209 );
210 const still = yield* workflows.start("greet", {}, { idempotencyKey: "g2" });
211 assert.equal(
212 (yield* workflows.waitFor(still.runId, (run) => run.status === "completed")).result,
213 "hello",
214 );
215 // And fixes it, saying something else, this time as the file's one default export.
216 yield* fileSystem.writeFileString(
217 at("greet.ts"),
218 greet("hi").replace("\nworkflow(", "\nexport default workflow("),
219 );
220 yield* problem(false);
221 const fixed = yield* workflows.start("greet", {}, { idempotencyKey: "g3" });
222 assert.equal(
223 (yield* workflows.waitFor(fixed.runId, (run) => run.status === "completed")).result,
224 "hi",
225 );
226 // A file taken away takes its workflows with it.
227 assert.deepStrictEqual(yield* definitions.remove("greet.ts"), saved);
228 const gone = yield* workflows
229 .start("greet", {}, { idempotencyKey: "g4" })
230 .pipe(Effect.flip);
231 assert.equal(gone._tag, "WorkflowNotRegisteredError");
232 // With no file left, nothing runs, and the runs that ended can still be read.
233 assert.deepStrictEqual(yield* definitions.remove("hold.ts"), saved);
234 assert.equal((yield* workflows.get(held.runId)).run.status, "completed");
235 assert.includeMembers(
236 (yield* workflows.list()).map((run) => run.runId),
237 [held.runId, greeted.runId],
238 );
239 }).pipe(
240 Effect.provide(runtime),
241 Effect.scoped,
242 Effect.raceFirst(Effect.forever(TestClock.adjust("1 second"))),
243 );
244 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
245);
246​
247it.effect(
248 "a folder that cannot be listed keeps its workflows and is looked at again, and an engine that cannot start leaves the last one running",
249 () =>
250 Effect.gen(function* () {
251 let refuse = false;
252 // What each engine was built to run. One that registers `broken` does not come up.
253 const builds: Array<ReadonlyArray<string>> = [];
254 // No file events: only the runtime's own retry can pick up what changed.
255 const { at, fileSystem, runtime } = yield* setup(
256 (real) => ({
257 ...real,
258 exists: (target) =>
259 refuse
260 ? Effect.fail(
261 PlatformError.systemError({
262 _tag: "PermissionDenied",
263 module: "FileSystem",
264 method: "exists",
265 pathOrDescriptor: target,
266 }),
267 )
268 : real.exists(target),
269 watch: () => Stream.never,
270 }),
271 (definitions) =>
272 definitions.some((definition) => definition.name === "broken")
273 ? Layer.effect(Workflows.Workflows, Effect.die(new Error("broken took it down")))
274 : Layer.sync(Workflows.Workflows, () => {
275 builds.push(definitions.map(engineTag));
276 return Workflows.disabled;
277 }),
278 );
279​
280 yield* Effect.gen(function* () {
281 const workflows = yield* Workflows.Workflows;
282 const definitions = yield* WorkflowRuntime.WorkflowDefinitions;
283 const revision = Effect.map(
284 Stream.runHead(workflows.watch),
285 (snapshot) => Option.getOrThrow(snapshot).definition?.revision ?? 0,
286 );
287 refuse = true;
288 // Written, but the folder could not be listed, so it is not said to run.
289 const unlisted = yield* definitions.save("greet.ts", greet("hi"));
290 assert.isTrue(unlisted.changed);
291 assert.include(unlisted.problems[0]?.message ?? "", "could not be read");
292 // What was loaded stays, and greet is not taken in yet.
293 assert.deepStrictEqual(builds, [["hold@1"]]);
294 const before = yield* revision;
295 refuse = false;
296 yield* TestClock.adjust("30 seconds");
297 yield* workflows.watch.pipe(
298 Stream.filter((snapshot) => (snapshot.definition?.revision ?? 0) > before),
299 Stream.runHead,
300 );
301 assert.deepStrictEqual(builds.at(-1), ["greet@1", "hold@1"]);
302​
303 // A definition that passes the checks but takes the engine down at start changes nothing.
304 yield* fileSystem.writeFileString(
305 at("broken.ts"),
306 'T3.workflow("broken", { version: 1, payload: Schema.Struct({}) }, () => Effect.void);\n',
307 );
308 const fellBack = yield* definitions.save("greet.ts", greet("hello"));
309 assert.isTrue(fellBack.changed);
310 assert.include(fellBack.problems[0]?.message ?? "", "did not start");
311 assert.deepStrictEqual(builds.slice(1), [
312 ["greet@1", "hold@1"],
313 ["greet@1", "hold@1"],
314 ]);
315 assert.include(
316 (yield* Stream.runHead(workflows.watch)).pipe(Option.getOrThrow).definition?.problem ??
317 "",
318 "did not start",
319 );
320 }).pipe(Effect.provide(runtime), Effect.scoped);
321 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
322);
323​
324it.effect("a file that never finishes loading is given up on, and later files still load", () =>
325 Effect.gen(function* () {
326 const { at, fileSystem } = yield* setup();
327 yield* fileSystem.writeFileString(at("stuck.ts"), "await new Promise(() => {});\n");
328 yield* fileSystem.writeFileString(at("greet.ts"), greet("hi"));
329 const stuck = yield* WorkflowRuntime.loadDefinitions(at("stuck.ts"), 0, 50).pipe(Effect.flip);
330 assert.include(String(stuck.cause), "did not finish loading");
331 const loaded = yield* WorkflowRuntime.loadDefinitions(at("greet.ts"));
332 assert.deepStrictEqual(
333 loaded.map((definition) => definition.name),
334 ["greet"],
335 );
336 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
337);
338​
339it.effect("a file given up on registers nothing into the file that loads after it", () =>
340 Effect.gen(function* () {
341 const { at, fileSystem } = yield* setup();
342 yield* fileSystem.writeFileString(
343 at("slow.ts"),
344 'await new Promise((resolve) => { globalThis.t3TestResume = resolve; });\nT3.workflow("slow", { version: 1, payload: Schema.Struct({}) }, () => Effect.void);\n',
345 );
346 // The second file goes on loading until the first one's top level has run to its end.
347 yield* fileSystem.writeFileString(
348 at("next.ts"),
349 `${greet("hi")}globalThis.t3TestResume();\nawait new Promise((resolve) => setImmediate(resolve));\n`,
350 );
351 yield* WorkflowRuntime.loadDefinitions(at("slow.ts"), 0, 50).pipe(Effect.flip);
352 const loaded = yield* WorkflowRuntime.loadDefinitions(at("next.ts"));
353 assert.deepStrictEqual(
354 loaded.map((definition) => definition.name),
355 ["greet"],
356 );
357 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
358);
359​
360// Vitest's module runner loads a file its own way; only Node keeps a CommonJS file by its path.
361it.live("a file without imports or exports loads again after it changes", () =>
362 Effect.gen(function* () {
363 const { at, fileSystem } = yield* setup();
364 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
365 yield* fileSystem.writeFileString(at("greet.ts"), greet("hi"));
366 const twice = `
367 import * as NodeFS from "node:fs";
368 import * as NodeServices from "@effect/platform-node/NodeServices";
369 import * as Context from "effect/Context";
370import * as Effect from "effect/Effect";
371 import { loadDefinitions } from ${JSON.stringify(new URL("./WorkflowRuntime.ts", import.meta.url).href)};
372 const file = process.argv.at(-1);
373 const program = Effect.gen(function* () {
374 const first = yield* loadDefinitions(file, 1);
375 NodeFS.writeFileSync(file, NodeFS.readFileSync(file, "utf8").replace('"hi"', '"hello"'));
376 const second = yield* loadDefinitions(file, 2);
377 return [first.length, second.length];
378 });
379 console.log(JSON.stringify(await Effect.runPromise(Effect.provide(program, NodeServices.layer))));
380 `;
381 const child = yield* spawner.spawn(
382 ChildProcess.make(
383 process.execPath,
384 ["--input-type=module", "--eval", twice, at("greet.ts")],
385 { cwd: import.meta.dirname },
386 ),
387 );
388 const [stdout, stderr] = yield* Effect.all(
389 [
390 child.stdout.pipe(Stream.decodeText(), Stream.mkString),
391 child.stderr.pipe(Stream.decodeText(), Stream.mkString),
392 ],
393 { concurrency: "unbounded" },
394 );
395 assert.equal(stdout.trim(), "[1,1]", stderr);
396 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
397);
398​
399it.effect("a change held back by a run goes in once that run ends, with no further edit", () =>
400 Effect.gen(function* () {
401 // The folder's changes are told by hand, so the test does not hang on a watcher starting.
402 const changed = yield* Queue.unbounded<FileSystem.WatchEvent>();
403 const { fileSystem, at, runtime } = yield* setup((fileSystem) => ({
404 ...fileSystem,
405 watch: () => Stream.fromQueue(changed),
406 }));
407 yield* Effect.gen(function* () {
408 const workflows = yield* Workflows.Workflows;
409 const definitions = yield* WorkflowRuntime.WorkflowDefinitions;
410 const held = yield* workflows.start("hold", {}, { idempotencyKey: "h" });
411 yield* workflows.waitFor(held.runId, (run) => run.status === "waiting");
412 const problem = (wanted: boolean) =>
413 workflows.watch.pipe(
414 Stream.filter((snapshot) => (snapshot.definition?.problem != null) === wanted),
415 Stream.runHead,
416 );
417 yield* fileSystem.writeFileString(at("hold.ts"), greet("hello"));
418 yield* Queue.offer(changed, { _tag: "Update", path: at("hold.ts") });
419 yield* problem(true);
420 yield* workflows.signal({ runId: held.runId, wait: "go" }, "go on", { id: "s1" });
421 yield* workflows.waitFor(held.runId, (run) => run.status === "completed");
422 // Nothing is told of the folder now: the held change goes in on its own.
423 yield* problem(false);
424 assert.deepStrictEqual(
425 (yield* definitions.read).files.map((file) => file.workflows),
426 [["greet@1"]],
427 );
428 }).pipe(
429 Effect.provide(runtime),
430 Effect.scoped,
431 Effect.raceFirst(Effect.forever(TestClock.adjust("1 second"))),
432 );
433 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
434);
435​
436it.effect(
437 "a reload does not wait for an agent that is still at work, and its step ends with the turn",
438 () =>
439 Effect.gen(function* () {
440 const ended = yield* Deferred.make<AgentResult>();
441 const started = yield* Deferred.make<void>();
442 const { fileSystem, at, runtime } = yield* setup(undefined, undefined, {
443 start: (input) =>
444 Effect.as(Deferred.succeed(started, undefined), {
445 threadId: "thread",
446 turnId: input.key,
447 }),
448 result: () => Deferred.await(ended),
449 interrupt: () => Effect.succeed("stopped" as const),
450 });
451 yield* fileSystem.writeFileString(
452 at("helper.ts"),
453 `T3.workflow("helper", { version: 1, payload: Schema.Struct({}), returns: Schema.String }, () =>
454 Effect.map(T3.agent("work", { brief: "Do it.", project: "p" }), (done) => done.value),
455);
456`,
457 );
458 const ticking = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
459 Effect.raceFirst(effect, Effect.forever(TestClock.adjust("1 second")));
460 yield* Effect.gen(function* () {
461 const workflows = yield* Workflows.Workflows;
462 const definitions = yield* WorkflowRuntime.WorkflowDefinitions;
463 const helped = yield* ticking(
464 Effect.gen(function* () {
465 const run = yield* workflows.start("helper", {}, { idempotencyKey: "a" });
466 yield* Deferred.await(started);
467 yield* workflows.waitFor(run.runId, (row) => row.status === "waiting");
468 return run;
469 }),
470 );
471​
472 // The test clock stands still during the save, so an engine that waited for the agent's
473 // step to finish would never stop: the step is not given up on, and the turn does not end.
474 // The swap cannot be interrupted, so a stuck save is unblocked by ending the turn.
475 const saving = yield* Effect.forkChild(definitions.save("greet.ts", greet("hello")));
476 const saved = yield* Fiber.await(saving).pipe(
477 Effect.timeoutOption("10 seconds"),
478 TestClock.withLive,
479 );
480 if (Option.isNone(saved)) {
481 yield* Deferred.succeed(ended, { ending: "completed", detail: "", reply: "late" });
482 yield* ticking(Fiber.await(saving));
483 assert.fail("The reload waited for the agent's turn to end.");
484 }
485 assert.isTrue(Exit.isSuccess(saved.value) && saved.value.value.changed);
486 assert.equal((yield* workflows.get(helped.runId)).run.status, "waiting");
487​
488 // The turn ends after the reload, and the new engine carries its result into the run.
489 yield* Deferred.succeed(ended, { ending: "completed", detail: "", reply: "all done" });
490 const done = yield* ticking(
491 workflows.waitFor(helped.runId, (run) => run.status === "completed"),
492 );
493 assert.equal(done.result, "all done");
494 }).pipe(Effect.provide(runtime), Effect.scoped);
495 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
496);
497​
498it.effect(
499 "workflows are off until turned on, and a run left waiting when they are turned off goes on once they are on again",
500 () =>
501 Effect.gen(function* () {
502 const { fileSystem, at, directory, made } = yield* setup();
503 // Its top level counts the times it was loaded.
504 yield* fileSystem.writeFileString(
505 at("counted.ts"),
506 "globalThis.t3GatedLoads = (globalThis.t3GatedLoads ?? 0) + 1;\nexport default [];\n",
507 );
508 const loads = () => (globalThis as { t3GatedLoads?: number }).t3GatedLoads ?? 0;
509 yield* Effect.gen(function* () {
510 const { turn, context } = yield* WorkflowRuntime.gate(made, directory);
511 const workflows = Context.get(context, Workflows.Workflows);
512 const definitions = Context.get(context, WorkflowRuntime.WorkflowDefinitions);
513 const start = workflows.start("hold", {}, { idempotencyKey: "h" });
514​
515 assert.equal((yield* Effect.flip(start)).message, Workflows.OFF);
516 assert.equal((yield* Effect.flip(workflows.list())).message, Workflows.OFF);
517 assert.deepStrictEqual((yield* definitions.read).files, []);
518 assert.equal(loads(), 0);
519​
520 yield* turn(true);
521 assert.equal(loads(), 1);
522 const held = yield* start;
523 yield* workflows.waitFor(held.runId, (run) => run.status === "waiting");
524​
525 yield* turn(false);
526 const signal = workflows.signal({ runId: held.runId, wait: "go" }, "go on", { id: "s1" });
527 assert.equal((yield* Effect.flip(signal)).message, Workflows.OFF);
528​
529 yield* turn(true);
530 yield* signal;
531 const freed = yield* workflows.waitFor(held.runId, (run) => run.status === "completed");
532 assert.equal(freed.result, "go on");
533 }).pipe(Effect.scoped, Effect.raceFirst(Effect.forever(TestClock.adjust("1 second"))));
534 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
535);