@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 147 lines 5.07 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 // Lifecycles provision a Bigtable instance; skipped with --fast.
15 const runLifecycle = !process.env.FAST;
16
17 const waitUntilGone = (name: string) =>
18 bigtable.getProjectsInstancesTablesAuthorizedViews({ 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 "getProjectsInstancesTablesAuthorizedViews on a missing instance fails with NotFound",
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 bigtable.getProjectsInstancesTablesAuthorizedViews({
38 name: `projects/${project}/instances/alchemybtmissing/tables/missing/authorizedViews/missing`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 yield* stack.destroy();
44 }).pipe(logLevel),
45 { tags: ["provider:gcp", "provider:gcp:bigtable", "live"], timeout: 90_000 },
46 );
47
48 test.provider.skipIf(!runLifecycle)(
49 "create, update, and delete a bigtable authorized view",
50 (stack) =>
51 Effect.gen(function* () {
52 yield* stack.destroy();
53
54 const created = yield* stack.deploy(
55 Effect.gen(function* () {
56 const instance = yield* GCP.Bigtable.Instance("Data", {
57 displayName: "alchemy-test-bt-authview",
58 type: "PRODUCTION",
59 clusters: {
60 cluster: {
61 location: "us-central1-b",
62 serveNodes: 1,
63 defaultStorageType: "HDD",
64 },
65 },
66 });
67 const table = yield* GCP.Bigtable.Table("Users", {
68 instance: instance.name,
69 columnFamilies: { cf: { gcRule: { maxNumVersions: 1 } } },
70 });
71 const view = yield* GCP.Bigtable.InstancesTablesAuthorizedView("Public", {
72 instance: instance.name,
73 table: table.name,
74 subsetView: {
75 rowPrefixes: [""],
76 familySubsets: {
77 cf: { qualifierPrefixes: [""] },
78 },
79 },
80 });
81 return { instance, table, view };
82 }),
83 );
84
85 expect(created.view.name).toContain("/authorizedViews/");
86 expect(created.view.authorizedViewId).toEqual(expect.any(String));
87 expect(created.view.table).toEqual(created.table.name);
88 expect(created.view.deletionProtection).toEqual(false);
89 expect(created.view.subsetView?.familySubsets?.cf).toBeDefined();
90
91 const fetched = yield* bigtable.getProjectsInstancesTablesAuthorizedViews({
92 name: created.view.name,
93 view: "FULL",
94 });
95 expect(fetched.name).toEqual(created.view.name);
96
97 const updated = yield* stack.deploy(
98 Effect.gen(function* () {
99 const instance = yield* GCP.Bigtable.Instance("Data", {
100 instanceId: created.instance.instanceId,
101 displayName: "alchemy-test-bt-authview",
102 type: "PRODUCTION",
103 clusters: {
104 cluster: {
105 location: "us-central1-b",
106 serveNodes: 1,
107 defaultStorageType: "HDD",
108 },
109 },
110 });
111 const table = yield* GCP.Bigtable.Table("Users", {
112 instance: instance.name,
113 tableId: created.table.tableId,
114 columnFamilies: { cf: { gcRule: { maxNumVersions: 1 } } },
115 });
116 const view = yield* GCP.Bigtable.InstancesTablesAuthorizedView("Public", {
117 instance: instance.name,
118 table: table.name,
119 authorizedViewId: created.view.authorizedViewId,
120 subsetView: {
121 rowPrefixes: [""],
122 familySubsets: {
123 cf: { qualifierPrefixes: [""] },
124 },
125 },
126 deletionProtection: true,
127 });
128 return { instance, table, view };
129 }),
130 );
131
132 expect(updated.view.name).toEqual(created.view.name);
133 expect(updated.view.deletionProtection).toEqual(true);
134
135 const refetched = yield* bigtable.getProjectsInstancesTablesAuthorizedViews({
136 name: created.view.name,
137 view: "FULL",
138 });
139 expect(refetched.deletionProtection).toEqual(true);
140
141 yield* stack.destroy();
142
143 const gone = yield* waitUntilGone(created.view.name);
144 expect(gone).toEqual("gone");
145 }).pipe(logLevel),
146 { tags: ["provider:gcp", "provider:gcp:bigtable", "live"], timeout: 120_000 },
147 );