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

main
ts 53 lines 2.12 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 Provider from "alchemy/Provider";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: Cloudflare.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 // A freshly minted scoped token propagates eventually-consistently across
14 // Cloudflare's edge — retry the typed `Forbidden` blips on out-of-band calls.
15 const forbiddenRetrySchedule = Schedule.exponential("500 millis");
16
17 const retryForbidden = <A, E extends { _tag: string }, R>(effect: Effect.Effect<A, E, R>) =>
18 effect.pipe(
19 Effect.retry({
20 while: (e) => e._tag === "Forbidden",
21 schedule: forbiddenRetrySchedule,
22 times: 8,
23 }),
24 );
25
26 // `list()` fans out over account BYOIP IP prefixes (the read-only catalog
27 // endpoint, available regardless of the BYOIP entitlement) and pages the BGP
28 // prefixes under each. On an account with no onboarded BYOIP prefixes the
29 // result is naturally an empty `BgpPrefixAttributes[]` — the exact
30 // shape `read` produces. This exercises the distilled wiring live on every run
31 // without requiring the BYOIP contract/entitlement.
32 test.provider(
33 "list enumerates BGP prefixes across BYOIP prefixes",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const provider = yield* Provider.findProvider(Cloudflare.Addressing.BgpPrefix);
39 const all = yield* retryForbidden(provider.list());
40
41 expect(Array.isArray(all)).toBe(true);
42 for (const p of all) {
43 expect(typeof p.bgpPrefixId).toBe("string");
44 expect(typeof p.prefixId).toBe("string");
45 expect(typeof p.accountId).toBe("string");
46 expect(typeof p.cidr).toBe("string");
47 expect(typeof p.onDemand.advertised).toBe("boolean");
48 }
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 { tags: ["provider:cloudflare", "provider:cloudflare:addressing", "live"] },
53 );