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 { describe, expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Core from "@alchemy.run/test/Core"; |
| 5 | import * as bigtable from "@distilled.cloud/gcp/bigtableadmin_v2"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { expectProbe } from "../bindingHost.ts"; |
| 8 | import BigtableBindingsHost, { Db, Nodes, Rows } from "./fixtures/bindings-host.ts"; |
| 9 | |
| 10 | const testOptions = { providers: GCP.providers() }; |
| 11 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 12 | const sharedStack = Core.scratchStack(testOptions, "BigtableBindings"); |
| 13 | |
| 14 | let baseUrl: string; |
| 15 | let hostAccount: string; |
| 16 | let instanceName: string; |
| 17 | let clusterName: string; |
| 18 | let tableName: string; |
| 19 | |
| 20 | const hostRoles = (policy: bigtable.Policy) => |
| 21 | (policy.bindings ?? []) |
| 22 | .filter((binding) => (binding.members ?? []).includes(`serviceAccount:${hostAccount}`)) |
| 23 | .map((binding) => binding.role) |
| 24 | .sort(); |
| 25 | |
| 26 | /** GetInstance and GetCluster grant bigtable.viewer on the instance only. */ |
| 27 | const expectInstanceGrants = Effect.gen(function* () { |
| 28 | const policy = yield* bigtable.getIamPolicyProjectsInstances({ |
| 29 | resource: instanceName, |
| 30 | body: {}, |
| 31 | }); |
| 32 | expect(hostRoles(policy)).toEqual(["roles/bigtable.viewer"]); |
| 33 | }); |
| 34 | |
| 35 | /** GetTable grants bigtable.viewer on the table only. */ |
| 36 | const expectTableGrants = Effect.gen(function* () { |
| 37 | const policy = yield* bigtable.getIamPolicyProjectsInstancesTables({ |
| 38 | resource: tableName, |
| 39 | body: {}, |
| 40 | }); |
| 41 | expect(hostRoles(policy)).toEqual(["roles/bigtable.viewer"]); |
| 42 | }); |
| 43 | |
| 44 | describe.skipIf(!!process.env.FAST)( |
| 45 | "Bigtable Bindings", |
| 46 | { |
| 47 | tags: ["provider:gcp", "provider:gcp:bigtable", "provider:gcp:run", "live"], |
| 48 | }, |
| 49 | () => { |
| 50 | beforeAll( |
| 51 | Effect.gen(function* () { |
| 52 | yield* sharedStack.destroy(); |
| 53 | const out = yield* sharedStack.deploy( |
| 54 | Effect.gen(function* () { |
| 55 | const host = yield* BigtableBindingsHost; |
| 56 | return { |
| 57 | uri: host.uri, |
| 58 | serviceAccount: host.serviceAccount, |
| 59 | instance: (yield* Db).name, |
| 60 | cluster: (yield* Nodes).name, |
| 61 | table: (yield* Rows).name, |
| 62 | }; |
| 63 | }), |
| 64 | ); |
| 65 | baseUrl = out.uri!; |
| 66 | hostAccount = out.serviceAccount!; |
| 67 | instanceName = out.instance; |
| 68 | clusterName = out.cluster; |
| 69 | tableName = out.table; |
| 70 | }), |
| 71 | { timeout: 900_000 }, |
| 72 | ); |
| 73 | |
| 74 | afterAll(sharedStack.destroy(), { timeout: 600_000 }); |
| 75 | |
| 76 | describe("GetInstance", () => { |
| 77 | test.provider( |
| 78 | "reads the instance as the host's service account, granted on the instance only", |
| 79 | (_stack) => |
| 80 | Effect.gen(function* () { |
| 81 | const live = yield* expectProbe<bigtable.Instance>(baseUrl, "getInstance"); |
| 82 | const actual = yield* bigtable.getProjectsInstances({ |
| 83 | name: instanceName, |
| 84 | }); |
| 85 | expect(live.name).toEqual(instanceName); |
| 86 | expect(live.displayName).toEqual(actual.displayName); |
| 87 | expect(live.state).toEqual("READY"); |
| 88 | yield* expectInstanceGrants; |
| 89 | }), |
| 90 | { |
| 91 | tags: ["provider:gcp", "provider:gcp:bigtable", "live"], |
| 92 | timeout: 600_000, |
| 93 | }, |
| 94 | ); |
| 95 | }); |
| 96 | |
| 97 | describe("GetCluster", () => { |
| 98 | test.provider( |
| 99 | "reads the cluster as the host's service account, granted on the instance only", |
| 100 | (_stack) => |
| 101 | Effect.gen(function* () { |
| 102 | const live = yield* expectProbe<bigtable.Cluster>(baseUrl, "getCluster"); |
| 103 | expect(live.name).toEqual(clusterName); |
| 104 | expect(live.serveNodes).toEqual(1); |
| 105 | expect(live.defaultStorageType).toEqual("HDD"); |
| 106 | yield* expectInstanceGrants; |
| 107 | }), |
| 108 | { |
| 109 | tags: ["provider:gcp", "provider:gcp:bigtable", "live"], |
| 110 | timeout: 600_000, |
| 111 | }, |
| 112 | ); |
| 113 | }); |
| 114 | |
| 115 | describe("GetTable", () => { |
| 116 | test.provider( |
| 117 | "reads the table as the host's service account, granted on the table only", |
| 118 | (_stack) => |
| 119 | Effect.gen(function* () { |
| 120 | const live = yield* expectProbe<bigtable.Table>(baseUrl, "getTable"); |
| 121 | expect(live.name).toEqual(tableName); |
| 122 | expect(Object.keys(live.columnFamilies ?? {})).toEqual(["cf"]); |
| 123 | yield* expectTableGrants; |
| 124 | }), |
| 125 | { |
| 126 | tags: ["provider:gcp", "provider:gcp:bigtable", "live"], |
| 127 | timeout: 600_000, |
| 128 | }, |
| 129 | ); |
| 130 | }); |
| 131 | }, |
| 132 | ); |