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

main
ts 135 lines 4.55 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 bigtable from "@distilled.cloud/gcp/bigtableadmin_v2";
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.FAST;
15
16 const waitUntilGone = (name: string) =>
17 bigtable.getProjectsInstancesClusters({ name }).pipe(
18 Effect.as("found" as const),
19 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("2 seconds"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 );
26
27 test.provider(
28 "getProjectsInstancesClusters on a missing cluster fails with NotFound",
29 (stack) =>
30 Effect.gen(function* () {
31 const { project } = yield* GcpEnvironment.current;
32
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 bigtable.getProjectsInstancesClusters({
37 name: `projects/${project}/instances/alchemy-bt-missing/clusters/missing`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41
42 const page = yield* bigtable.listProjectsInstancesClusters({
43 parent: `projects/${project}/instances/-`,
44 });
45 expect((page.clusters ?? []).map((item) => item.name)).not.toContain(
46 `projects/${project}/instances/alchemy-bt-missing/clusters/missing`,
47 );
48
49 yield* stack.destroy();
50 }).pipe(logLevel),
51 { tags: ["provider:gcp", "provider:gcp:bigtable", "live"], timeout: 90_000 },
52 );
53
54 test.provider.skipIf(!runLifecycle)(
55 "create, update, and delete a bigtable cluster",
56 (stack) =>
57 Effect.gen(function* () {
58 yield* stack.destroy();
59
60 const created = yield* stack.deploy(
61 Effect.gen(function* () {
62 const instance = yield* GCP.Bigtable.Instance("Data", {
63 displayName: "alchemy-test-bt-cluster",
64 type: "PRODUCTION",
65 clusters: {
66 cluster: {
67 location: "us-central1-b",
68 serveNodes: 1,
69 defaultStorageType: "HDD",
70 },
71 },
72 });
73 const replica = yield* GCP.Bigtable.Cluster("Replica", {
74 instance: instance.name,
75 location: "us-central1-c",
76 serveNodes: 1,
77 defaultStorageType: "HDD",
78 });
79 return { instance, replica };
80 }),
81 );
82
83 expect(created.replica.name).toContain("/clusters/");
84 expect(created.replica.clusterId).toEqual(expect.any(String));
85 expect(created.replica.instance).toEqual(created.instance.name);
86 expect(created.replica.location).toEqual("us-central1-c");
87 expect(created.replica.serveNodes).toEqual(1);
88 expect(created.replica.state).toEqual("READY");
89
90 const fetched = yield* bigtable.getProjectsInstancesClusters({
91 name: created.replica.name,
92 });
93 expect(fetched.name).toEqual(created.replica.name);
94 expect(fetched.serveNodes).toEqual(1);
95
96 const updated = yield* stack.deploy(
97 Effect.gen(function* () {
98 const instance = yield* GCP.Bigtable.Instance("Data", {
99 instanceId: created.instance.instanceId,
100 displayName: "alchemy-test-bt-cluster",
101 type: "PRODUCTION",
102 clusters: {
103 cluster: {
104 location: "us-central1-b",
105 serveNodes: 1,
106 defaultStorageType: "HDD",
107 },
108 },
109 });
110 const replica = yield* GCP.Bigtable.Cluster("Replica", {
111 instance: instance.name,
112 clusterId: created.replica.clusterId,
113 location: "us-central1-c",
114 serveNodes: 2,
115 defaultStorageType: "HDD",
116 });
117 return { instance, replica };
118 }),
119 );
120
121 expect(updated.replica.name).toEqual(created.replica.name);
122 expect(updated.replica.serveNodes).toEqual(2);
123
124 const refetched = yield* bigtable.getProjectsInstancesClusters({
125 name: created.replica.name,
126 });
127 expect(refetched.serveNodes).toEqual(2);
128
129 yield* stack.destroy();
130
131 const gone = yield* waitUntilGone(created.replica.name);
132 expect(gone).toEqual("gone");
133 }).pipe(logLevel),
134 { tags: ["provider:gcp", "provider:gcp:bigtable", "live"], timeout: 120_000 },
135 );