@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 129 lines 4.63 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 alloydb from "@distilled.cloud/gcp/alloydb_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 // AlloyDB clusters and instances take well over 5 minutes to provision.
15 const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST;
16
17 const waitUntilGone = (name: string) =>
18 alloydb.getProjectsLocationsClusters({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("2 seconds"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider(
29 "getProjectsLocationsClusters on a missing cluster fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 alloydb.getProjectsLocationsClusters({
38 name: `projects/${project}/locations/us-central1/clusters/alchemy-alloydb-missing`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 const page = yield* alloydb.listProjectsLocationsClusters({
44 parent: `projects/${project}/locations/-`,
45 pageSize: 10,
46 });
47 expect((page.clusters ?? []).map((item) => item.name)).not.toContain(
48 `projects/${project}/locations/us-central1/clusters/alchemy-alloydb-missing`,
49 );
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 { tags: ["provider:gcp", "provider:gcp:alloydb", "live"], timeout: 90_000 },
54 );
55
56 test.provider.skipIf(!runLifecycle)(
57 "create, update, and delete an alloydb cluster",
58 (stack) =>
59 Effect.gen(function* () {
60 yield* stack.destroy();
61
62 const created = yield* stack.deploy(
63 Effect.gen(function* () {
64 return yield* GCP.AlloyDB.Cluster("AppDb", {
65 location: "us-central1",
66 pscConfig: { pscEnabled: true },
67 displayName: "alchemy-test-cluster",
68 labels: { env: "test" },
69 initialUser: { user: "postgres", password: "AlchemyTest1" },
70 automatedBackupPolicy: { enabled: false },
71 continuousBackupConfig: { enabled: false },
72 });
73 }),
74 );
75
76 expect(created.name).toContain("/clusters/");
77 expect(created.clusterId).toEqual(expect.any(String));
78 expect(created.location).toEqual("us-central1");
79 expect(created.displayName).toEqual("alchemy-test-cluster");
80 expect(created.labels).toMatchObject({ env: "test" });
81 expect(created.pscConfig?.pscEnabled).toEqual(true);
82 expect(["READY", "EMPTY"]).toContain(created.state);
83
84 const fetched = yield* alloydb.getProjectsLocationsClusters({
85 name: created.name,
86 });
87 expect(fetched.name).toEqual(created.name);
88 expect(fetched.labels?.env).toEqual("test");
89 // GCP omits displayName from cluster reads, so only the resource
90 // attributes (asserted above) carry it.
91 expect(fetched.pscConfig?.pscEnabled).toEqual(true);
92
93 const updated = yield* stack.deploy(
94 Effect.gen(function* () {
95 return yield* GCP.AlloyDB.Cluster("AppDb", {
96 clusterId: created.clusterId,
97 location: "us-central1",
98 pscConfig: { pscEnabled: true },
99 displayName: "alchemy-prod-cluster",
100 labels: { env: "prod", role: "db" },
101 automatedBackupPolicy: { enabled: false },
102 continuousBackupConfig: { enabled: false },
103 });
104 }),
105 );
106
107 expect(updated.name).toEqual(created.name);
108 expect(updated.displayName).toEqual("alchemy-prod-cluster");
109 expect(updated.labels).toMatchObject({ env: "prod", role: "db" });
110
111 const refetched = yield* alloydb.getProjectsLocationsClusters({
112 name: created.name,
113 });
114 // GCP omits displayName from cluster reads, so only the resource
115 // attributes (asserted above) carry it.
116 expect(refetched.labels?.env).toEqual("prod");
117 expect(refetched.labels?.role).toEqual("db");
118
119 yield* stack.destroy();
120
121 const gone = yield* waitUntilGone(created.name);
122 expect(gone).toEqual("gone");
123 }).pipe(logLevel),
124 {
125 tags: ["provider:gcp", "provider:gcp:alloydb", "live"],
126 timeout: 3_600_000,
127 retry: 0,
128 },
129 );