@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 93 lines 3.59 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, creation fails with the typed
29 // `Web3HostnameNotEntitled` error (Cloudflare code 10000-class "Web3
30 // gateways are not enabled"). The deploy+presence test is therefore gated
31 // behind a Web3-entitled account flag; the read-only list assertion below
32 // runs unconditionally.
33 const web3Entitled = !!process.env.CLOUDFLARE_TEST_WEB3;
34
35 // Read-only: `list()` enumerates Web3 hostnames across every zone via
36 // `listAllZones`. On a non-entitled account each per-zone list answers
37 // `Forbidden` and is skipped, so the result is a well-typed (possibly
38 // empty) array. This always runs and proves the enumeration shape.
39 test.provider(
40 "list returns a well-typed array of web3 hostnames",
41 (stack) =>
42 Effect.gen(function* () {
43 const provider = yield* Provider.findProvider(Cloudflare.Web3.Hostname);
44 const all = yield* provider.list();
45
46 expect(Array.isArray(all)).toBe(true);
47 for (const item of all) {
48 expect(typeof item.hostnameId).toBe("string");
49 expect(typeof item.zoneId).toBe("string");
50 expect(typeof item.name).toBe("string");
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 Web3 hostname and assert `list()` surfaces it. Gated behind
60 // a Web3-entitled account (`CLOUDFLARE_TEST_WEB3=1`); on the default
61 // (non-entitled) testing account creation fails with the typed
62 // `Web3HostnameNotEntitled` error.
63 test.provider.skipIf(!web3Entitled)(
64 "list surfaces a deployed web3 hostname (entitled account)",
65 (stack) =>
66 Effect.gen(function* () {
67 const zone = yield* resolveZone;
68 const name = `${testName("alchemy-web3-list")}.${zone.name}`;
69
70 yield* stack.destroy();
71
72 const hostname = yield* stack.deploy(
73 Effect.gen(function* () {
74 return yield* Cloudflare.Web3.Hostname("ListHostname", {
75 zoneId: zone.id,
76 name,
77 target: "ipfs_universal_path",
78 }).pipe(adopt(true));
79 }),
80 );
81
82 const provider = yield* Provider.findProvider(Cloudflare.Web3.Hostname);
83 const all = yield* provider.list();
84
85 expect(all.some((h) => h.hostnameId === hostname.hostnameId)).toBe(true);
86
87 yield* stack.destroy();
88 }).pipe(logLevel),
89 {
90 tags: ["provider:cloudflare", "provider:cloudflare:web3", "provider:cloudflare:zone", "live"],
91 timeout: 120_000,
92 },
93 );