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

main
ts 53 lines 2.1 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 across account BYOIP prefixes (`listPrefixes`) and lists
27 // each prefix's service bindings (`listPrefixServiceBindings`). Both endpoints
28 // are available regardless of the BYOIP entitlement — on an account with no
29 // onboarded prefixes the result is an empty, well-typed
30 // `ServiceBindingAttributes[]` (the exact shape `read` produces).
31 test.provider(
32 "list enumerates service bindings across prefixes (read-only)",
33 (stack) =>
34 Effect.gen(function* () {
35 yield* stack.destroy();
36
37 const provider = yield* Provider.findProvider(Cloudflare.Addressing.ServiceBinding);
38 const all = yield* retryForbidden(provider.list());
39
40 expect(Array.isArray(all)).toBe(true);
41 for (const b of all) {
42 expect(typeof b.bindingId).toBe("string");
43 expect(typeof b.prefixId).toBe("string");
44 expect(typeof b.accountId).toBe("string");
45 expect(typeof b.cidr).toBe("string");
46 expect(typeof b.serviceId).toBe("string");
47 expect(typeof b.provisioning).toBe("object");
48 }
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 { tags: ["provider:cloudflare", "provider:cloudflare:addressing", "live"] },
53 );