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

main
ts 90 lines 3.15 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import { CloudflareEnvironment } from "@alchemy.run/cloudflare/CloudflareEnvironment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as magicTransit from "@distilled.cloud/cloudflare/magic-transit";
6 import * as Provider from "alchemy/Provider";
7 import * as Effect from "effect/Effect";
8 import { MinimumLogLevel } from "effect/References";
9
10 const { test } = Test.make({ providers: Cloudflare.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 // Magic WAN sites (and their WANs) are entitlement-gated. On the standard
15 // testing account every site call fails with the typed `MagicWanUnauthorized`
16 // error (Cloudflare code 1025) or `MagicWanNotEnabled`
17 // (code 1101, "forbidden: feature not enabled").
18 // The deploy+list lifecycle test below is gated behind an explicit opt-in env
19 // flag for entitled accounts; the read-only list probe always runs and asserts
20 // a well-typed array (empty on unentitled accounts).
21 const entitled = !!process.env.CLOUDFLARE_TEST_MAGIC_WAN;
22
23 test.provider(
24 "list returns a well-typed array of site WANs",
25 (stack) =>
26 Effect.gen(function* () {
27 yield* stack.destroy();
28
29 const provider = yield* Provider.findProvider(Cloudflare.MagicTransit.MagicSiteWan);
30 const all = yield* provider.list();
31
32 // Unentitled accounts surface MagicWanUnauthorized/MagicWanNotEnabled, which list()
33 // maps to []. Either way the result is a well-typed array, never a throw.
34 expect(Array.isArray(all)).toBe(true);
35 for (const wan of all) {
36 expect(typeof wan.wanId).toBe("string");
37 expect(typeof wan.siteId).toBe("string");
38 expect(typeof wan.accountId).toBe("string");
39 }
40
41 yield* stack.destroy();
42 }).pipe(logLevel),
43 {
44 tags: ["provider:cloudflare", "provider:cloudflare:magictransit", "live"],
45 timeout: 120_000,
46 },
47 );
48
49 test.provider.skipIf(!entitled)(
50 "list enumerates the deployed site WAN",
51 (stack) =>
52 Effect.gen(function* () {
53 const { accountId } = yield* yield* CloudflareEnvironment;
54
55 yield* stack.destroy();
56
57 const site = yield* stack.deploy(
58 Cloudflare.MagicTransit.MagicSite("Site", {
59 description: "alchemy magic site wan list test",
60 }),
61 );
62
63 const wan = yield* stack.deploy(
64 Cloudflare.MagicTransit.MagicSiteWan("Wan", {
65 siteId: site.siteId,
66 physport: 1,
67 priority: 10,
68 }),
69 );
70 expect(wan.wanId).toBeTruthy();
71
72 // Out-of-band sanity check via the distilled API.
73 const live = yield* magicTransit.listSiteWans({
74 accountId,
75 siteId: site.siteId,
76 });
77 expect(live.result.some((w) => w.id === wan.wanId)).toBe(true);
78
79 const provider = yield* Provider.findProvider(Cloudflare.MagicTransit.MagicSiteWan);
80 const all = yield* provider.list();
81
82 expect(all.some((w) => w.wanId === wan.wanId)).toBe(true);
83
84 yield* stack.destroy();
85 }).pipe(logLevel),
86 {
87 tags: ["provider:cloudflare", "provider:cloudflare:magictransit", "live"],
88 timeout: 180_000,
89 },
90 );