1import * as Cloudflare from "@/Cloudflare/index.ts";
2import * as Test from "@/Test/Alchemy";
3import { expect } from "alchemy-test";
4import * as Effect from "effect/Effect";
5import { MinimumLogLevel } from "effect/References";
6import * as pathe from "pathe";
7import { expectUrlContains } from "../Utils/Http.ts";
8
9const { test } = Test.make({
10 providers: Cloudflare.providers(),
11 dev: true,
12});
13
14const logLevel = Effect.provideService(
15 MinimumLogLevel,
16 process.env.DEBUG ? "Debug" : "Info",
17);
18
19const main = pathe.resolve(import.meta.dirname, "fixtures/python/worker.py");
20
21// `dev: true` selects the local provider: the Python entry and its sibling
22// modules are served by workerd (which embeds Pyodide) instead of being
23// uploaded to Cloudflare. The first start may download the Pyodide runtime
24// bundle, so the fetch retries generously.
25test.provider(
26 "serves a Python Worker from local workerd",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 const worker = yield* stack.deploy(
32 Effect.gen(function* () {
33 return yield* Cloudflare.Worker("PythonLocalWorker", {
34 main,
35 env: { PY_SUFFIX: "local" },
36 });
37 }),
38 );
39
40 expect(worker.url).toBeDefined();
41 yield* expectUrlContains(
42 worker.url!,
43 "alchemy-python-worker-7c1f suffix=local",
44 );
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 {
49 tags: ["provider:cloudflare", "provider:cloudflare:worker", "local"],
50 timeout: 240_000,
51 },
52);