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 { CloudflareEnvironment } from "@alchemy.run/cloudflare/CloudflareEnvironment"; |
| 3 | import { readPrebuiltWorkerBundle } from "@alchemy.run/cloudflare/Workers/Sources/Prebuilt"; |
| 4 | import { describe, expect } from "@alchemy.run/test"; |
| 5 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as pathe from "pathe"; |
| 9 | import { expectUrlContains } from "../Utils/Http.ts"; |
| 10 | import { waitForWorkerToBeDeleted } from "../Utils/Worker.ts"; |
| 11 | |
| 12 | const { test } = Test.make({ providers: Cloudflare.providers() }); |
| 13 | |
| 14 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 15 | |
| 16 | const main = pathe.resolve(import.meta.dirname, "fixtures/prebuilt/worker.mjs"); |
| 17 | |
| 18 | describe.concurrent( |
| 19 | "Cloudflare.Worker with bundle: false", |
| 20 | { tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"] }, |
| 21 | () => { |
| 22 | test.provider( |
| 23 | "uploads a prebuilt module graph byte-for-byte", |
| 24 | (stack) => |
| 25 | Effect.gen(function* () { |
| 26 | const { accountId } = yield* yield* CloudflareEnvironment; |
| 27 | |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | // The bundle the provider must upload, computed from the source |
| 31 | // bytes on disk: entry first, additional modules named by their |
| 32 | // POSIX path relative to the entry's directory. |
| 33 | const expected = yield* readPrebuiltWorkerBundle({ main }); |
| 34 | expect(expected.files.map((file) => file.path)).toEqual([ |
| 35 | "worker.mjs", |
| 36 | "lib/format.mjs", |
| 37 | "lib/greeting.mjs", |
| 38 | "lib/notice.txt", |
| 39 | ]); |
| 40 | |
| 41 | const worker = yield* stack.deploy( |
| 42 | Effect.gen(function* () { |
| 43 | return yield* Cloudflare.Worker("PrebuiltWorker", { |
| 44 | main, |
| 45 | bundle: false, |
| 46 | workersDev: true, |
| 47 | compatibility: { |
| 48 | date: "2024-01-01", |
| 49 | }, |
| 50 | }); |
| 51 | }), |
| 52 | ); |
| 53 | |
| 54 | // The stored bundle hash equals the hash of the source bytes |
| 55 | // only when no rolldown step ran — any re-bundling would |
| 56 | // minify the files and change every content hash. |
| 57 | expect(worker.hash?.bundle).toEqual(expected.hash); |
| 58 | |
| 59 | // End-to-end: the response is assembled from values that flow |
| 60 | // through both nested ES modules and the nested text module, so |
| 61 | // it only renders if the module names survived the upload. |
| 62 | expect(worker.url).toBeDefined(); |
| 63 | yield* expectUrlContains( |
| 64 | worker.url!, |
| 65 | "prebuilt-modules-survived alchemy-prebuilt-notice-4d2a!", |
| 66 | ); |
| 67 | |
| 68 | // Re-deploy with no changes: the prebuilt hash must be stable. |
| 69 | const redeployed = yield* stack.deploy( |
| 70 | Effect.gen(function* () { |
| 71 | return yield* Cloudflare.Worker("PrebuiltWorker", { |
| 72 | main, |
| 73 | bundle: false, |
| 74 | workersDev: true, |
| 75 | compatibility: { |
| 76 | date: "2024-01-01", |
| 77 | }, |
| 78 | }); |
| 79 | }), |
| 80 | ); |
| 81 | expect(redeployed.hash?.bundle).toEqual(expected.hash); |
| 82 | |
| 83 | yield* stack.destroy(); |
| 84 | yield* waitForWorkerToBeDeleted(worker.workerName, accountId); |
| 85 | }).pipe(logLevel), |
| 86 | { timeout: 360_000 }, |
| 87 | ); |
| 88 | }, |
| 89 | ); |