The best way to control Claude Code, Codex and more from any computer or phone

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