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

main
ts 105 lines 4.15 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import { CloudflareEnvironment } from "@alchemy.run/cloudflare/CloudflareEnvironment";
3 import { findZoneByName } from "@alchemy.run/cloudflare/Zone/lookup";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import { adopt } from "alchemy/AdoptPolicy";
7 import * as Provider from "alchemy/Provider";
8 import * as Effect from "effect/Effect";
9 import { MinimumLogLevel } from "effect/References";
10 import { testName } from "../../names.ts";
11
12 const { test } = Test.make({ providers: Cloudflare.providers() });
13
14 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
15
16 const zoneName = process.env.CLOUDFLARE_TEST_DNS_ZONE_NAME ?? "alchemy-test-2.us";
17
18 const resolveZone = Effect.gen(function* () {
19 const { accountId } = yield* yield* CloudflareEnvironment;
20 const zone = yield* findZoneByName({ accountId, name: zoneName });
21 if (!zone) {
22 return yield* Effect.die(new Error(`zone "${zoneName}" not found in account`));
23 }
24 return zone;
25 });
26
27 // Cloudflare has restricted Web3 gateways for new customers; on accounts
28 // without the entitlement, the per-zone hostname list answers `Forbidden`,
29 // so the content-list deploy+presence test is gated behind a Web3-entitled
30 // account flag. The read-only list assertion below runs unconditionally.
31 const web3Entitled = !!process.env.CLOUDFLARE_TEST_WEB3;
32
33 // Read-only: `list()` enumerates every zone via `listAllZones`, lists each
34 // zone's universal-path Web3 hostnames, and reads each one's content list.
35 // On a non-entitled account each per-zone hostname list answers `Forbidden`
36 // and is skipped, so the result is a well-typed (possibly empty) array. This
37 // always runs and proves the enumeration shape.
38 test.provider(
39 "list returns a well-typed array of web3 content lists",
40 (stack) =>
41 Effect.gen(function* () {
42 const provider = yield* Provider.findProvider(Cloudflare.Web3.HostnameContentList);
43 const all = yield* provider.list();
44
45 expect(Array.isArray(all)).toBe(true);
46 for (const item of all) {
47 expect(typeof item.zoneId).toBe("string");
48 expect(typeof item.hostnameId).toBe("string");
49 expect(item.action).toBe("block");
50 expect(Array.isArray(item.entries)).toBe(true);
51 }
52
53 // Keep the destroy bookend so the harness state stays clean.
54 yield* stack.destroy();
55 }).pipe(logLevel),
56 { tags: ["provider:cloudflare", "provider:cloudflare:web3", "live"] },
57 );
58
59 // Deploy a real universal-path Web3 hostname + content list and assert
60 // `list()` surfaces it. Gated behind a Web3-entitled account
61 // (`CLOUDFLARE_TEST_WEB3=1`); on the default (non-entitled) testing account
62 // the hostname list rejects with the typed `Forbidden` error.
63 test.provider.skipIf(!web3Entitled)(
64 "list surfaces a deployed web3 content list (entitled account)",
65 (stack) =>
66 Effect.gen(function* () {
67 const zone = yield* resolveZone;
68 const name = `${testName("alchemy-web3-cl-list")}.${zone.name}`;
69
70 yield* stack.destroy();
71
72 const deployed = yield* stack.deploy(
73 Effect.gen(function* () {
74 const gateway = yield* Cloudflare.Web3.Hostname("ListGateway", {
75 zoneId: zone.id,
76 name,
77 target: "ipfs_universal_path",
78 }).pipe(adopt(true));
79 const contentList = yield* Cloudflare.Web3.HostnameContentList("ListBlocklist", {
80 zoneId: zone.id,
81 hostnameId: gateway.hostnameId,
82 entries: [
83 {
84 type: "cid",
85 content: "QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco",
86 description: "blocked CID",
87 },
88 ],
89 });
90 return { gateway, contentList };
91 }),
92 );
93
94 const provider = yield* Provider.findProvider(Cloudflare.Web3.HostnameContentList);
95 const all = yield* provider.list();
96
97 expect(all.some((cl) => cl.hostnameId === deployed.contentList.hostnameId)).toBe(true);
98
99 yield* stack.destroy();
100 }).pipe(logLevel),
101 {
102 tags: ["provider:cloudflare", "provider:cloudflare:web3", "provider:cloudflare:zone", "live"],
103 timeout: 120_000,
104 },
105 );