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 * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Data from "effect/Data"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as HttpClient from "effect/http/HttpClient"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import Stack from "./fixtures/stack.ts"; |
| 9 | |
| 10 | const { test, beforeAll, afterAll, deploy, destroy } = Test.make({ |
| 11 | providers: Cloudflare.providers(), |
| 12 | }); |
| 13 | |
| 14 | class WorkerNotReady extends Data.TaggedError("WorkerNotReady")<{ |
| 15 | status: number; |
| 16 | body: string; |
| 17 | }> {} |
| 18 | |
| 19 | const readJson = (url: string) => |
| 20 | HttpClient.HttpClient.pipe( |
| 21 | Effect.flatMap((client) => client.get(url)), |
| 22 | Effect.flatMap((res) => |
| 23 | res.status === 200 |
| 24 | ? res.json |
| 25 | : res.text.pipe( |
| 26 | Effect.flatMap((body) => Effect.fail(new WorkerNotReady({ status: res.status, body }))), |
| 27 | ), |
| 28 | ), |
| 29 | ).pipe( |
| 30 | Effect.retry({ |
| 31 | while: (e): e is WorkerNotReady => e instanceof WorkerNotReady, |
| 32 | schedule: Schedule.max([Schedule.exponential("500 millis"), Schedule.recurs(20)]), |
| 33 | }), |
| 34 | ); |
| 35 | |
| 36 | const stack = beforeAll(deploy(Stack)); |
| 37 | afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack)); |
| 38 | |
| 39 | test( |
| 40 | "async worker renders a page title through Browser Rendering", |
| 41 | Effect.gen(function* () { |
| 42 | const { asyncWorkerUrl } = yield* stack; |
| 43 | const body = (yield* readJson(`${asyncWorkerUrl}/title`)) as { |
| 44 | mode: string; |
| 45 | title: string; |
| 46 | }; |
| 47 | |
| 48 | expect(body.mode).toBe("async"); |
| 49 | expect(body.title).toBe("Example Domain"); |
| 50 | }), |
| 51 | { |
| 52 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 53 | timeout: 180_000, |
| 54 | }, |
| 55 | ); |
| 56 | |
| 57 | test( |
| 58 | "effect worker exercises content via quickAction wrapper", |
| 59 | Effect.gen(function* () { |
| 60 | const { effectWorkerUrl } = yield* stack; |
| 61 | const body = (yield* readJson(`${effectWorkerUrl}/content`)) as { |
| 62 | title: string; |
| 63 | contentLength: number; |
| 64 | }; |
| 65 | |
| 66 | expect(body.title).toBe("Example Domain"); |
| 67 | expect(body.contentLength).toBeGreaterThan(0); |
| 68 | }), |
| 69 | { |
| 70 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 71 | timeout: 180_000, |
| 72 | }, |
| 73 | ); |
| 74 | |
| 75 | test( |
| 76 | "effect worker converts a page to markdown", |
| 77 | Effect.gen(function* () { |
| 78 | const { effectWorkerUrl } = yield* stack; |
| 79 | const body = (yield* readJson(`${effectWorkerUrl}/markdown`)) as { |
| 80 | markdownLength: number; |
| 81 | }; |
| 82 | |
| 83 | expect(body.markdownLength).toBeGreaterThan(0); |
| 84 | }), |
| 85 | { |
| 86 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 87 | timeout: 180_000, |
| 88 | }, |
| 89 | ); |
| 90 | |
| 91 | test( |
| 92 | "effect worker extracts links", |
| 93 | Effect.gen(function* () { |
| 94 | const { effectWorkerUrl } = yield* stack; |
| 95 | const body = (yield* readJson(`${effectWorkerUrl}/links`)) as { |
| 96 | linkCount: number; |
| 97 | }; |
| 98 | |
| 99 | expect(body.linkCount).toBeGreaterThan(0); |
| 100 | }), |
| 101 | { |
| 102 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 103 | timeout: 180_000, |
| 104 | }, |
| 105 | ); |
| 106 | |
| 107 | test( |
| 108 | "effect worker scrapes elements by selector", |
| 109 | Effect.gen(function* () { |
| 110 | const { effectWorkerUrl } = yield* stack; |
| 111 | const body = (yield* readJson(`${effectWorkerUrl}/scrape`)) as { |
| 112 | text: string | null; |
| 113 | }; |
| 114 | |
| 115 | expect(body.text).toBe("Learn more"); |
| 116 | }), |
| 117 | { |
| 118 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 119 | timeout: 180_000, |
| 120 | }, |
| 121 | ); |
| 122 | |
| 123 | test( |
| 124 | "effect worker takes a page snapshot", |
| 125 | Effect.gen(function* () { |
| 126 | const { effectWorkerUrl } = yield* stack; |
| 127 | const body = (yield* readJson(`${effectWorkerUrl}/snapshot`)) as { |
| 128 | title: string; |
| 129 | screenshotLength: number; |
| 130 | }; |
| 131 | |
| 132 | expect(body.title).toBe("Example Domain"); |
| 133 | expect(body.screenshotLength).toBeGreaterThan(0); |
| 134 | }), |
| 135 | { |
| 136 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 137 | timeout: 180_000, |
| 138 | }, |
| 139 | ); |
| 140 | |
| 141 | test( |
| 142 | "effect worker streams a screenshot", |
| 143 | Effect.gen(function* () { |
| 144 | const { effectWorkerUrl } = yield* stack; |
| 145 | const body = (yield* readJson(`${effectWorkerUrl}/screenshot`)) as { |
| 146 | bytes: number; |
| 147 | }; |
| 148 | |
| 149 | expect(body.bytes).toBeGreaterThan(0); |
| 150 | }), |
| 151 | { |
| 152 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 153 | timeout: 180_000, |
| 154 | }, |
| 155 | ); |
| 156 | |
| 157 | test( |
| 158 | "effect worker streams a PDF", |
| 159 | Effect.gen(function* () { |
| 160 | const { effectWorkerUrl } = yield* stack; |
| 161 | const body = (yield* readJson(`${effectWorkerUrl}/pdf`)) as { |
| 162 | bytes: number; |
| 163 | }; |
| 164 | |
| 165 | expect(body.bytes).toBeGreaterThan(0); |
| 166 | }), |
| 167 | { |
| 168 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 169 | timeout: 180_000, |
| 170 | }, |
| 171 | ); |
| 172 | |
| 173 | test( |
| 174 | "effect worker extracts JSON with AI", |
| 175 | Effect.gen(function* () { |
| 176 | const { effectWorkerUrl } = yield* stack; |
| 177 | const body = (yield* readJson(`${effectWorkerUrl}/json`)) as { |
| 178 | success: boolean; |
| 179 | }; |
| 180 | |
| 181 | expect(body.success).toBe(true); |
| 182 | }), |
| 183 | { |
| 184 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 185 | timeout: 180_000, |
| 186 | }, |
| 187 | ); |
| 188 | |
| 189 | test( |
| 190 | "effect worker calls the generic quickAction", |
| 191 | Effect.gen(function* () { |
| 192 | const { effectWorkerUrl } = yield* stack; |
| 193 | const body = (yield* readJson(`${effectWorkerUrl}/quickAction`)) as { |
| 194 | title: string; |
| 195 | }; |
| 196 | |
| 197 | expect(body.title).toBe("Example Domain"); |
| 198 | }), |
| 199 | { |
| 200 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 201 | timeout: 180_000, |
| 202 | }, |
| 203 | ); |
| 204 | |
| 205 | test( |
| 206 | "effect worker exposes the raw BrowserRun binding", |
| 207 | Effect.gen(function* () { |
| 208 | const { effectWorkerUrl } = yield* stack; |
| 209 | const body = (yield* readJson(`${effectWorkerUrl}/raw`)) as { |
| 210 | title: string; |
| 211 | }; |
| 212 | |
| 213 | expect(body.title).toBe("Example Domain"); |
| 214 | }), |
| 215 | { |
| 216 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 217 | timeout: 180_000, |
| 218 | }, |
| 219 | ); |