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
| 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 Output from "alchemy/Output"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { MinimumLogLevel } from "effect/References"; |
| 9 | import * as Schedule from "effect/Schedule"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | // Lifecycles provision a Bigtable instance; skipped with --fast. |
| 16 | const runLifecycle = !process.env.FAST; |
| 17 | |
| 18 | const waitUntilGone = (name: string) => |
| 19 | bigtable.getProjectsInstancesMaterializedViews({ name }).pipe( |
| 20 | Effect.as("found" as const), |
| 21 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 22 | Effect.repeat({ |
| 23 | schedule: Schedule.spaced("2 seconds"), |
| 24 | until: (status) => status === "gone", |
| 25 | times: 10, |
| 26 | }), |
| 27 | ); |
| 28 | |
| 29 | test.provider( |
| 30 | "getProjectsInstancesMaterializedViews on a missing instance fails with NotFound", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | const { project } = yield* GcpEnvironment.current; |
| 34 | |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const error = yield* Effect.flip( |
| 38 | bigtable.getProjectsInstancesMaterializedViews({ |
| 39 | name: `projects/${project}/instances/alchemybtmissing/materializedViews/missing`, |
| 40 | }), |
| 41 | ); |
| 42 | expect(error._tag).toEqual("NotFound"); |
| 43 | |
| 44 | yield* stack.destroy(); |
| 45 | }).pipe(logLevel), |
| 46 | { tags: ["provider:gcp", "provider:gcp:bigtable", "live"], timeout: 90_000 }, |
| 47 | ); |
| 48 | |
| 49 | test.provider.skipIf(!runLifecycle)( |
| 50 | "create, update, and delete a bigtable materialized view", |
| 51 | (stack) => |
| 52 | Effect.gen(function* () { |
| 53 | yield* stack.destroy(); |
| 54 | |
| 55 | const created = yield* stack.deploy( |
| 56 | Effect.gen(function* () { |
| 57 | const instance = yield* GCP.Bigtable.Instance("Data", { |
| 58 | displayName: "alchemy-test-bt-mview", |
| 59 | type: "PRODUCTION", |
| 60 | clusters: { |
| 61 | cluster: { |
| 62 | location: "us-central1-b", |
| 63 | serveNodes: 1, |
| 64 | defaultStorageType: "HDD", |
| 65 | }, |
| 66 | }, |
| 67 | }); |
| 68 | const table = yield* GCP.Bigtable.Table("Events", { |
| 69 | instance: instance.name, |
| 70 | tableId: "events", |
| 71 | columnFamilies: { cf: { gcRule: { maxNumVersions: 1 } } }, |
| 72 | }); |
| 73 | const view = yield* GCP.Bigtable.InstancesMaterializedView("Counts", { |
| 74 | instance: instance.name, |
| 75 | query: Output.interpolate`SELECT '*' AS _key, COUNT(*) AS row_count FROM \`${table.tableId}\` GROUP BY _key`, |
| 76 | }); |
| 77 | return { instance, table, view }; |
| 78 | }), |
| 79 | ); |
| 80 | |
| 81 | expect(created.view.name).toContain("/materializedViews/"); |
| 82 | expect(created.view.materializedViewId).toEqual(expect.any(String)); |
| 83 | expect(created.view.instance).toEqual(created.instance.name); |
| 84 | expect(created.view.query).toContain("events"); |
| 85 | expect(created.view.deletionProtection).toEqual(false); |
| 86 | |
| 87 | const fetched = yield* bigtable.getProjectsInstancesMaterializedViews({ |
| 88 | name: created.view.name, |
| 89 | }); |
| 90 | expect(fetched.name).toEqual(created.view.name); |
| 91 | |
| 92 | const updated = yield* stack.deploy( |
| 93 | Effect.gen(function* () { |
| 94 | const instance = yield* GCP.Bigtable.Instance("Data", { |
| 95 | instanceId: created.instance.instanceId, |
| 96 | displayName: "alchemy-test-bt-mview", |
| 97 | type: "PRODUCTION", |
| 98 | clusters: { |
| 99 | cluster: { |
| 100 | location: "us-central1-b", |
| 101 | serveNodes: 1, |
| 102 | defaultStorageType: "HDD", |
| 103 | }, |
| 104 | }, |
| 105 | }); |
| 106 | const table = yield* GCP.Bigtable.Table("Events", { |
| 107 | instance: instance.name, |
| 108 | tableId: "events", |
| 109 | columnFamilies: { cf: { gcRule: { maxNumVersions: 1 } } }, |
| 110 | }); |
| 111 | const view = yield* GCP.Bigtable.InstancesMaterializedView("Counts", { |
| 112 | instance: instance.name, |
| 113 | materializedViewId: created.view.materializedViewId, |
| 114 | query: Output.interpolate`SELECT '*' AS _key, COUNT(*) AS row_count FROM \`${table.tableId}\` GROUP BY _key`, |
| 115 | deletionProtection: true, |
| 116 | }); |
| 117 | return { instance, table, view }; |
| 118 | }), |
| 119 | ); |
| 120 | |
| 121 | expect(updated.view.name).toEqual(created.view.name); |
| 122 | expect(updated.view.deletionProtection).toEqual(true); |
| 123 | |
| 124 | const refetched = yield* bigtable.getProjectsInstancesMaterializedViews({ |
| 125 | name: created.view.name, |
| 126 | }); |
| 127 | expect(refetched.deletionProtection).toEqual(true); |
| 128 | |
| 129 | yield* stack.destroy(); |
| 130 | |
| 131 | const gone = yield* waitUntilGone(created.view.name); |
| 132 | expect(gone).toEqual("gone"); |
| 133 | }).pipe(logLevel), |
| 134 | { tags: ["provider:gcp", "provider:gcp:bigtable", "live"], timeout: 480_000 }, |
| 135 | ); |