| 1 | import * as Cloudflare from "@/Cloudflare/index.ts"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import { expect } from "alchemy-test"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import { MinimumLogLevel } from "effect/References"; |
| 6 | import * as pathe from "pathe"; |
| 7 | import { expectUrlContains } from "../Utils/Http.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ |
| 10 | providers: Cloudflare.providers(), |
| 11 | dev: true, |
| 12 | }); |
| 13 | |
| 14 | const logLevel = Effect.provideService( |
| 15 | MinimumLogLevel, |
| 16 | process.env.DEBUG ? "Debug" : "Info", |
| 17 | ); |
| 18 | |
| 19 | const main = pathe.resolve(import.meta.dirname, "fixtures/prebuilt/worker.mjs"); |
| 20 | |
| 21 | // `dev: true` selects the local provider. A `bundle: false` Worker must be |
| 22 | // served byte-for-byte in local dev exactly like the deploy path: the entry |
| 23 | // plus its rule-matched siblings (nested ES modules AND the nested text |
| 24 | // module) are handed to workerd as-is. |
| 25 | // |
| 26 | // Regression: the local provider used to run every non-Python `main` |
| 27 | // through the rolldown watcher, re-bundling the prebuilt artifact. That |
| 28 | // broke the byte-for-byte contract outright — this fixture's `.txt` module |
| 29 | // import isn't even bundleable — so local dev of `bundle: false` workers |
| 30 | // failed while deploy worked. The prebuilt source now fs-watches and |
| 31 | // re-reads the module graph instead of bundling. |
| 32 | test.provider( |
| 33 | "serves a prebuilt (bundle: false) Worker byte-for-byte from local workerd", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | yield* stack.destroy(); |
| 37 | |
| 38 | const worker = yield* stack.deploy( |
| 39 | Effect.gen(function* () { |
| 40 | return yield* Cloudflare.Worker("PrebuiltLocalWorker", { |
| 41 | main, |
| 42 | bundle: false, |
| 43 | compatibility: { |
| 44 | date: "2024-01-01", |
| 45 | }, |
| 46 | }); |
| 47 | }), |
| 48 | ); |
| 49 | |
| 50 | expect(worker.url).toBeDefined(); |
| 51 | // The response is assembled across both nested ES modules and the |
| 52 | // nested text module — it can only be produced when the full module |
| 53 | // graph reached workerd unbundled. |
| 54 | yield* expectUrlContains( |
| 55 | worker.url!, |
| 56 | "prebuilt-modules-survived alchemy-prebuilt-notice-4d2a!", |
| 57 | ); |
| 58 | |
| 59 | yield* stack.destroy(); |
| 60 | }).pipe(logLevel), |
| 61 | { |
| 62 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "local"], |
| 63 | timeout: 120_000, |
| 64 | }, |
| 65 | ); |