The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import { makeWorkerRuntimeContext } from "@alchemy.run/cloudflare/Workers/WorkerRuntimeContext"; |
| 2 | import { describe, expect, it } from "@alchemy.run/test"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | |
| 5 | describe( |
| 6 | "WorkerRuntimeContext", |
| 7 | { |
| 8 | tags: ["unit", "provider:cloudflare", "provider:cloudflare:worker", "local"], |
| 9 | }, |
| 10 | () => { |
| 11 | it("dispatches an event to every listener for that event type", async () => { |
| 12 | const ctx = makeWorkerRuntimeContext("test-worker"); |
| 13 | const observed: string[] = []; |
| 14 | |
| 15 | await Effect.runPromise( |
| 16 | Effect.gen(function* () { |
| 17 | yield* ctx.listen((event) => { |
| 18 | if (event.type !== "queue") return; |
| 19 | return Effect.sync(() => { |
| 20 | observed.push("first"); |
| 21 | }); |
| 22 | }); |
| 23 | yield* ctx.listen((event) => { |
| 24 | if (event.type !== "queue") return; |
| 25 | return Effect.sync(() => { |
| 26 | observed.push("second"); |
| 27 | }); |
| 28 | }); |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | const exports = await Effect.runPromise(ctx.exports); |
| 33 | const [program, services] = exports.default.queue( |
| 34 | { queue: "queue-a", messages: [] }, |
| 35 | {}, |
| 36 | {} as ExecutionContext, |
| 37 | ); |
| 38 | |
| 39 | await Effect.runPromise(program.pipe(Effect.provide(services))); |
| 40 | |
| 41 | expect(observed).toEqual(["first", "second"]); |
| 42 | }); |
| 43 | }, |
| 44 | ); |