@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 95 lines 3.58 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import { Action } from "alchemy/Action";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Stream from "effect/Stream";
8 import { awaitDrained, produce } from "./fixtures/queue-sink-client.ts";
9 import QueueSinkHttpWorker from "./fixtures/queue-sink-http-worker.ts";
10 import { type Click, SourceQueue } from "./fixtures/queue-sink-shared.ts";
11 import QueueSinkWorker from "./fixtures/queue-sink-worker.ts";
12
13 const { test } = Test.make({ providers: Cloudflare.providers() });
14
15 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
16
17 /**
18 * `Cloudflare.Queues.QueueSink` end to end against real Cloudflare Queues:
19 * the fixture drains 250 clicks (one stream chunk, split into 100/100/50
20 * `sendBatch` calls) into a source queue, a `consumeQueueMessages` handler
21 * transforms each batch and drains it into a result queue through a second
22 * `QueueSink`, and the result consumer records every index in a DO.
23 *
24 * A second run sends five ~100 KB messages, which only fit Cloudflare's
25 * 256 KB batch limit when the sink splits them by size. Two more runs feed
26 * the same pipeline through the other layers: `QueueSinkHttp` from a second
27 * Worker, and `QueueSinkLocal` from an Action during deploy.
28 */
29 test.provider.skipIf(!!process.env.FAST)(
30 "QueueSink drains a stream through source → transform → sink",
31 (stack) =>
32 Effect.gen(function* () {
33 yield* stack.destroy();
34
35 const { url, httpUrl } = yield* stack.deploy(
36 Effect.gen(function* () {
37 const source = yield* SourceQueue;
38 const worker = yield* QueueSinkWorker;
39 const httpWorker = yield* QueueSinkHttpWorker;
40
41 const Seed = Action(
42 "Seed",
43 Effect.gen(function* () {
44 const sink = yield* Cloudflare.Queues.QueueSink(source);
45 return Effect.fn(function* () {
46 yield* Stream.range(0, 149).pipe(
47 Stream.map((index): Click => ({ run: "action", index })),
48 Stream.run(sink),
49 );
50 });
51 }).pipe(Effect.provide(Cloudflare.Queues.QueueSinkLocal)),
52 );
53 yield* Seed({});
54
55 return {
56 url: worker.url.as<string>(),
57 httpUrl: httpWorker.url.as<string>(),
58 };
59 }),
60 );
61 expect(url).toBeTypeOf("string");
62 expect(httpUrl).toBeTypeOf("string");
63
64 yield* produce(url, { run: "count", count: 250 });
65 yield* produce(url, { run: "large", count: 5, padding: 100_000 });
66 yield* produce(httpUrl, { run: "http", count: 150 });
67
68 const [count, large, http, action] = yield* Effect.all(
69 [
70 awaitDrained(url, "count", 250),
71 awaitDrained(url, "large", 5),
72 awaitDrained(url, "http", 150),
73 awaitDrained(url, "action", 150),
74 ],
75 { concurrency: "unbounded" },
76 );
77
78 // At-least-once delivery: assert distinct indices, not message count.
79 expect(count).toEqual({ distinct: 250, transformed: true });
80 expect(large).toEqual({ distinct: 5, transformed: true });
81 expect(http).toEqual({ distinct: 150, transformed: true });
82 expect(action).toEqual({ distinct: 150, transformed: true });
83
84 yield* stack.destroy();
85 }).pipe(logLevel),
86 {
87 tags: [
88 "provider:cloudflare",
89 "provider:cloudflare:queue",
90 "provider:cloudflare:worker",
91 "live",
92 ],
93 timeout: 200_000,
94 },
95 );