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

main
ts 87 lines 3.26 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 import { testName } from "../../names.ts";
10
11 const { test } = Test.make({ providers: Cloudflare.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 // Magic WAN sites (and their LANs) are entitlement-gated. On the standard
16 // testing account every Magic Transit call fails with the typed
17 // `MagicWanUnauthorized` error (Cloudflare code 1025) or `MagicWanNotEnabled`
18 // (code 1101, "forbidden: feature not enabled"). `list()` catches both tags and
19 // returns `[]`, so the read-only list assertion below always runs; the live
20 // deploy+enumerate case is gated behind an explicit opt-in env flag for
21 // entitled accounts.
22 const entitled = !!process.env.CLOUDFLARE_TEST_MAGIC_WAN;
23
24 test.provider(
25 "list returns a well-typed array (empty on unentitled accounts)",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const provider = yield* Provider.findProvider(Cloudflare.MagicTransit.MagicSiteLan);
31 const all = yield* provider.list();
32
33 // Either the exhaustively-paginated LANs (entitled) or [] (unentitled).
34 expect(Array.isArray(all)).toBe(true);
35
36 yield* stack.destroy();
37 }).pipe(logLevel),
38 {
39 tags: ["provider:cloudflare", "provider:cloudflare:magictransit", "live"],
40 timeout: 120_000,
41 },
42 );
43
44 test.provider.skipIf(!entitled)(
45 "list enumerates the deployed Magic WAN site LANs",
46 (stack) =>
47 Effect.gen(function* () {
48 const { accountId } = yield* yield* CloudflareEnvironment;
49
50 yield* stack.destroy();
51
52 const deployed = yield* stack.deploy(
53 Effect.gen(function* () {
54 const site = yield* Cloudflare.MagicTransit.MagicSite("Site", {
55 description: "alchemy magic site list test",
56 });
57 const lan = yield* Cloudflare.MagicTransit.MagicSiteLan("ListLan", {
58 siteId: site.siteId,
59 physport: 2,
60 name: testName("alchemy-site-lan-list"),
61 vlanTag: 30,
62 staticAddressing: { address: "192.168.30.1/24" },
63 });
64 return { site, lan };
65 }),
66 );
67
68 expect(deployed.lan.lanId).toBeTruthy();
69
70 const provider = yield* Provider.findProvider(Cloudflare.MagicTransit.MagicSiteLan);
71 const all = yield* provider.list();
72
73 // The deployed LAN is present in the exhaustively-paginated result,
74 // hydrated into the same Attributes shape `read` produces.
75 const found = all.find((l) => l.lanId === deployed.lan.lanId);
76 expect(found).toBeDefined();
77 expect(found?.siteId).toEqual(deployed.site.siteId);
78 expect(found?.accountId).toEqual(accountId);
79 expect(found?.name).toEqual(testName("alchemy-site-lan-list"));
80
81 yield* stack.destroy();
82 }).pipe(logLevel),
83 {
84 tags: ["provider:cloudflare", "provider:cloudflare:magictransit", "live"],
85 timeout: 180_000,
86 },
87 );