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

main
ts 129 lines 4.34 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.getProjectsInstancesTables({ name, view: "NAME_ONLY" }).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 "getProjectsInstancesTables on a missing instance fails with a typed tag",
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.getProjectsInstancesTables({
37 name: `projects/${project}/instances/alchemybtmissing/tables/missing`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41
42 yield* stack.destroy();
43 }).pipe(logLevel),
44 { tags: ["provider:gcp", "provider:gcp:bigtable", "live"], timeout: 90_000 },
45 );
46
47 test.provider.skipIf(!runLifecycle)(
48 "create, update, and delete a bigtable table",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const created = yield* stack.deploy(
54 Effect.gen(function* () {
55 const instance = yield* GCP.Bigtable.Instance("Data", {
56 displayName: "alchemy-test-bt-table",
57 type: "PRODUCTION",
58 clusters: {
59 cluster: {
60 location: "us-central1-b",
61 serveNodes: 1,
62 defaultStorageType: "HDD",
63 },
64 },
65 });
66 const table = yield* GCP.Bigtable.Table("Users", {
67 instance: instance.name,
68 columnFamilies: {
69 cf: { gcRule: { maxNumVersions: 3 } },
70 },
71 });
72 return { instance, table };
73 }),
74 );
75
76 expect(created.table.name).toContain("/tables/");
77 expect(created.table.tableId).toEqual(expect.any(String));
78 expect(created.table.instance).toEqual(created.instance.name);
79 expect(created.table.columnFamilies.cf?.gcRule?.maxNumVersions).toEqual(3);
80 expect(created.table.deletionProtection).toEqual(false);
81
82 const fetched = yield* bigtable.getProjectsInstancesTables({
83 name: created.table.name,
84 view: "SCHEMA_VIEW",
85 });
86 expect(fetched.name).toEqual(created.table.name);
87 expect(fetched.columnFamilies?.cf?.gcRule?.maxNumVersions).toEqual(3);
88
89 const updated = yield* stack.deploy(
90 Effect.gen(function* () {
91 const instance = yield* GCP.Bigtable.Instance("Data", {
92 instanceId: created.instance.instanceId,
93 displayName: "alchemy-test-bt-table",
94 type: "PRODUCTION",
95 clusters: {
96 cluster: {
97 location: "us-central1-b",
98 serveNodes: 1,
99 defaultStorageType: "HDD",
100 },
101 },
102 });
103 const table = yield* GCP.Bigtable.Table("Users", {
104 instance: instance.name,
105 tableId: created.table.tableId,
106 columnFamilies: {
107 cf: { gcRule: { maxNumVersions: 5 } },
108 },
109 });
110 return { instance, table };
111 }),
112 );
113
114 expect(updated.table.name).toEqual(created.table.name);
115 expect(updated.table.columnFamilies.cf?.gcRule?.maxNumVersions).toEqual(5);
116
117 const refetched = yield* bigtable.getProjectsInstancesTables({
118 name: created.table.name,
119 view: "SCHEMA_VIEW",
120 });
121 expect(refetched.columnFamilies?.cf?.gcRule?.maxNumVersions).toEqual(5);
122
123 yield* stack.destroy();
124
125 const gone = yield* waitUntilGone(created.table.name);
126 expect(gone).toEqual("gone");
127 }).pipe(logLevel),
128 { tags: ["provider:gcp", "provider:gcp:bigtable", "live"], timeout: 120_000 },
129 );