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

WorkflowRuntime.test.ts

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