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

main
ts 110 lines 3.64 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as compute from "@distilled.cloud/gcp/compute_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const runLifecycle = !!process.env.GCP_TEST_BYOIP && !process.env.FAST;
15
16 const parentPrefix = process.env.GCP_TEST_PAP_PARENT ?? "";
17 const ipCidrRange = process.env.GCP_TEST_PDP_RANGE ?? "203.0.113.0/26";
18 const region = "us-central1";
19
20 const waitUntilGone = (project: string, regionName: string, publicDelegatedPrefix: string) =>
21 compute
22 .getPublicDelegatedPrefixes({
23 project,
24 region: regionName,
25 publicDelegatedPrefix,
26 })
27 .pipe(
28 Effect.as("found" as const),
29 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
30 Effect.repeat({
31 schedule: Schedule.spaced("2 seconds"),
32 until: (status) => status === "gone",
33 times: 10,
34 }),
35 );
36
37 test.provider(
38 "insertPublicDelegatedPrefixes with a malformed parentPrefix fails with BadRequest",
39 () =>
40 Effect.gen(function* () {
41 const { project } = yield* GcpEnvironment.current;
42 const error = yield* Effect.flip(
43 compute.insertPublicDelegatedPrefixes({
44 project,
45 region,
46 body: {
47 name: "alchemy-pdp-probe",
48 description: "alchemy entitlement probe",
49 parentPrefix: parentPrefix || "does-not-exist",
50 ipCidrRange,
51 },
52 }),
53 );
54 expect(error._tag).toEqual("BadRequest");
55 }).pipe(logLevel),
56 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 60_000 },
57 );
58
59 test.provider.skipIf(!runLifecycle || !parentPrefix)(
60 "create, update, and delete a regional public delegated prefix",
61 (stack) =>
62 Effect.gen(function* () {
63 yield* stack.destroy();
64
65 const created = yield* stack.deploy(
66 Effect.gen(function* () {
67 return yield* GCP.Compute.PublicDelegatedPrefix("Delegate", {
68 region,
69 parentPrefix,
70 ipCidrRange,
71 description: "delegated range",
72 });
73 }),
74 );
75
76 expect(created.prefixName).toEqual(expect.any(String));
77 expect(created.region).toEqual(region);
78 expect(created.ipCidrRange).toEqual(ipCidrRange);
79 expect(created.description).toEqual("delegated range");
80
81 const fetched = yield* compute.getPublicDelegatedPrefixes({
82 project: created.project,
83 region,
84 publicDelegatedPrefix: created.prefixName,
85 });
86 expect(fetched.name).toEqual(created.prefixName);
87 expect(fetched.description).toContain("[alchemy ");
88
89 const updated = yield* stack.deploy(
90 Effect.gen(function* () {
91 return yield* GCP.Compute.PublicDelegatedPrefix("Delegate", {
92 prefixName: created.prefixName,
93 region,
94 parentPrefix,
95 ipCidrRange,
96 description: "updated range",
97 });
98 }),
99 );
100
101 expect(updated.prefixName).toEqual(created.prefixName);
102 expect(updated.description).toEqual("updated range");
103
104 yield* stack.destroy();
105
106 const gone = yield* waitUntilGone(created.project, region, created.prefixName);
107 expect(gone).toEqual("gone");
108 }).pipe(logLevel),
109 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
110 );