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

main
ts 49 lines 1.77 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 { call, roundTrip, waitForPlatform } from "./fixtures/counter-client.ts";
7 import EuWorker from "./fixtures/eu-worker.ts";
8 import UnrestrictedWorker from "./fixtures/unrestricted-worker.ts";
9
10 const { test } = Test.make({
11 providers: Cloudflare.providers(),
12 });
13
14 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
15
16 /**
17 * `layerDurableObjects({ jurisdiction: "eu" })` keeps the model's objects in the
18 * EU namespace: switching the same Worker to the unrestricted platform finds
19 * none of them, and switching back finds them where they were left.
20 */
21 test.provider(
22 "a Domain model's Durable Objects live in its jurisdiction",
23 (stack) =>
24 Effect.gen(function* () {
25 yield* stack.destroy();
26 const deploy = (worker: typeof EuWorker | typeof UnrestrictedWorker) =>
27 stack.deploy(
28 Effect.gen(function* () {
29 return { worker: yield* worker };
30 }),
31 );
32
33 const { worker } = yield* deploy(EuWorker);
34 const url = worker.url!;
35 yield* waitForPlatform(url, "eu");
36 yield* roundTrip(url);
37
38 yield* deploy(UnrestrictedWorker);
39 yield* waitForPlatform(url, "unrestricted");
40 expect(yield* call(`${url}/state/c-1`)).toEqual({ total: 0 });
41
42 yield* deploy(EuWorker);
43 yield* waitForPlatform(url, "eu");
44 expect(yield* call(`${url}/state/c-1`)).toEqual({ total: 4 });
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 { timeout: 420_000, tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"] },
49 );