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

main
ts 133 lines 4.85 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as compute from "@distilled.cloud/gcp/compute_v1";
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: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const region = "us-central1";
14
15 // A regional pd-balanced disk bills SSD quota for both replicas, so keep it
16 // at the 10 GB minimum: the regional SSD_TOTAL_GB quota on a fresh project is
17 // 250 GB and is shared with every other concurrent Compute test.
18
19 const waitUntilGone = (project: string, instantSnapshot: string) =>
20 compute.getRegionInstantSnapshots({ project, region, instantSnapshot }).pipe(
21 Effect.as("found" as const),
22 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
23 Effect.repeat({
24 schedule: Schedule.spaced("1 second"),
25 until: (status) => status === "gone",
26 times: 10,
27 }),
28 );
29
30 test.provider.skipIf(!!process.env.FAST)(
31 "create, update labels, replace, and delete a regional instant snapshot",
32 (stack) =>
33 Effect.gen(function* () {
34 yield* stack.destroy();
35
36 const created = yield* stack.deploy(
37 Effect.gen(function* () {
38 const disk = yield* GCP.Compute.RegionDisk("Data", {
39 region,
40 replicaZones: ["us-central1-a", "us-central1-b"],
41 type: "pd-balanced",
42 sizeGb: 10,
43 });
44 const snapshot = yield* GCP.Compute.RegionInstantSnapshot("Checkpoint", {
45 region,
46 sourceDisk: disk.selfLink.as<string>(),
47 description: "first checkpoint",
48 labels: { env: "test" },
49 });
50 return { disk, snapshot };
51 }),
52 );
53
54 expect(created.snapshot.instantSnapshotName).toEqual(expect.any(String));
55 expect(created.snapshot.region).toEqual(region);
56 expect(created.snapshot.status).toEqual("READY");
57 expect(created.snapshot.labels).toMatchObject({ env: "test" });
58 expect(created.snapshot.description).toEqual("first checkpoint");
59
60 const fetched = yield* compute.getRegionInstantSnapshots({
61 project: created.snapshot.project,
62 region,
63 instantSnapshot: created.snapshot.instantSnapshotName,
64 });
65 expect(fetched.name).toEqual(created.snapshot.instantSnapshotName);
66 expect(fetched.labels?.env).toEqual("test");
67 expect(fetched.status).toEqual("READY");
68
69 const updated = yield* stack.deploy(
70 Effect.gen(function* () {
71 const disk = yield* GCP.Compute.RegionDisk("Data", {
72 diskName: created.disk.diskName,
73 region,
74 replicaZones: ["us-central1-a", "us-central1-b"],
75 type: "pd-balanced",
76 sizeGb: 10,
77 });
78 const snapshot = yield* GCP.Compute.RegionInstantSnapshot("Checkpoint", {
79 instantSnapshotName: created.snapshot.instantSnapshotName,
80 region,
81 sourceDisk: disk.selfLink.as<string>(),
82 description: "first checkpoint",
83 labels: { env: "prod", role: "data" },
84 });
85 return { disk, snapshot };
86 }),
87 );
88
89 expect(updated.snapshot.instantSnapshotName).toEqual(created.snapshot.instantSnapshotName);
90 expect(updated.snapshot.labels).toMatchObject({
91 env: "prod",
92 role: "data",
93 });
94
95 const nextName = `r${created.snapshot.instantSnapshotName}`.slice(0, 63).replace(/-+$/, "x");
96 const replaced = yield* stack.deploy(
97 Effect.gen(function* () {
98 const disk = yield* GCP.Compute.RegionDisk("Data", {
99 diskName: created.disk.diskName,
100 region,
101 replicaZones: ["us-central1-a", "us-central1-b"],
102 type: "pd-balanced",
103 sizeGb: 10,
104 });
105 const snapshot = yield* GCP.Compute.RegionInstantSnapshot("Checkpoint", {
106 instantSnapshotName: nextName,
107 region,
108 sourceDisk: disk.selfLink.as<string>(),
109 description: "replaced checkpoint",
110 });
111 return { disk, snapshot };
112 }),
113 );
114
115 expect(replaced.snapshot.instantSnapshotName).toEqual(nextName);
116 expect(replaced.snapshot.description).toEqual("replaced checkpoint");
117
118 const oldGone = yield* waitUntilGone(
119 created.snapshot.project,
120 created.snapshot.instantSnapshotName,
121 );
122 expect(oldGone).toEqual("gone");
123
124 yield* stack.destroy();
125
126 const gone = yield* waitUntilGone(
127 replaced.snapshot.project,
128 replaced.snapshot.instantSnapshotName,
129 );
130 expect(gone).toEqual("gone");
131 }).pipe(logLevel),
132 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 180_000 },
133 );