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 { describe, expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as Core from "@alchemy.run/test/Core"; |
| 6 | import * as resourcemanager from "@distilled.cloud/gcp/cloudresourcemanager_v3"; |
| 7 | import * as file from "@distilled.cloud/gcp/file_v1"; |
| 8 | import * as Effect from "effect/Effect"; |
| 9 | import { expectProbe } from "../bindingHost.ts"; |
| 10 | import FilestoreBindingsHost, { Nfs, Nightly } from "./fixtures/bindings-host.ts"; |
| 11 | import FilestoreSnapshotBindingsHost, { Snap, ZonalNfs } from "./fixtures/snapshot-host.ts"; |
| 12 | |
| 13 | const testOptions = { providers: GCP.providers() }; |
| 14 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 15 | const sharedStack = Core.scratchStack(testOptions, "FilestoreBindings"); |
| 16 | const snapshotStack = Core.scratchStack(testOptions, "FilestoreSnapshotBindings"); |
| 17 | |
| 18 | // Filestore instances take 5–20 minutes to provision. |
| 19 | const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST; |
| 20 | // Snapshot-capable tiers draw on `EnterpriseStorageGibPerRegion`, which the |
| 21 | // testing project lacks (limit 0); InstancesSnapshot.test.ts pins the typed |
| 22 | // StorageQuotaExceeded rejection. |
| 23 | const runSnapshot = runLifecycle && !!process.env.GCP_TEST_FILESTORE_ENTERPRISE; |
| 24 | |
| 25 | let baseUrl: string; |
| 26 | let hostAccount: string; |
| 27 | let instanceName: string; |
| 28 | let backupName: string; |
| 29 | let snapshotBaseUrl: string; |
| 30 | let snapshotHostAccount: string; |
| 31 | let snapshotName: string; |
| 32 | |
| 33 | /** |
| 34 | * Roles the host's service account holds on the project. Filestore has no |
| 35 | * resource-level IAM, so its bindings grant `roles/file.viewer` there. |
| 36 | */ |
| 37 | const hostProjectRoles = (account: string) => |
| 38 | Effect.gen(function* () { |
| 39 | const { project } = yield* GcpEnvironment.current; |
| 40 | const policy = yield* resourcemanager.getIamPolicyProjects({ |
| 41 | resource: `projects/${project}`, |
| 42 | body: { options: { requestedPolicyVersion: 3 } }, |
| 43 | }); |
| 44 | return (policy.bindings ?? []) |
| 45 | .filter((binding) => (binding.members ?? []).includes(`serviceAccount:${account}`)) |
| 46 | .map((binding) => ({ |
| 47 | role: binding.role, |
| 48 | condition: binding.condition?.expression, |
| 49 | })); |
| 50 | }); |
| 51 | |
| 52 | const expectedRoles = [{ role: "roles/file.viewer", condition: undefined }]; |
| 53 | |
| 54 | describe.skipIf(!runLifecycle)( |
| 55 | "Filestore Bindings", |
| 56 | { |
| 57 | tags: ["provider:gcp", "provider:gcp:filestore", "provider:gcp:run", "live"], |
| 58 | }, |
| 59 | () => { |
| 60 | beforeAll( |
| 61 | Effect.gen(function* () { |
| 62 | yield* sharedStack.destroy(); |
| 63 | const out = yield* sharedStack.deploy( |
| 64 | Effect.gen(function* () { |
| 65 | const host = yield* FilestoreBindingsHost; |
| 66 | const instance = yield* Nfs; |
| 67 | const backup = yield* Nightly; |
| 68 | return { |
| 69 | uri: host.uri, |
| 70 | serviceAccount: host.serviceAccount, |
| 71 | instance: instance.name, |
| 72 | backup: backup.name, |
| 73 | }; |
| 74 | }), |
| 75 | ); |
| 76 | baseUrl = out.uri!; |
| 77 | hostAccount = out.serviceAccount!; |
| 78 | instanceName = out.instance; |
| 79 | backupName = out.backup; |
| 80 | }), |
| 81 | { timeout: 1_800_000 }, |
| 82 | ); |
| 83 | |
| 84 | afterAll(sharedStack.destroy(), { timeout: 1_800_000 }); |
| 85 | |
| 86 | describe("GetInstance", () => { |
| 87 | test.provider( |
| 88 | "reads the instance as the host's service account", |
| 89 | (_stack) => |
| 90 | Effect.gen(function* () { |
| 91 | const out = yield* expectProbe<file.Instance>(baseUrl, "getInstance"); |
| 92 | const direct = yield* file.getProjectsLocationsInstances({ |
| 93 | name: instanceName, |
| 94 | }); |
| 95 | expect(out.name).toEqual(instanceName); |
| 96 | expect(out.tier).toEqual(direct.tier); |
| 97 | expect(out.fileShares?.[0]?.name).toEqual("share1"); |
| 98 | expect(yield* hostProjectRoles(hostAccount)).toEqual(expectedRoles); |
| 99 | }), |
| 100 | { |
| 101 | tags: ["provider:gcp", "provider:gcp:filestore", "live"], |
| 102 | timeout: 600_000, |
| 103 | }, |
| 104 | ); |
| 105 | }); |
| 106 | |
| 107 | describe("GetBackup", () => { |
| 108 | test.provider( |
| 109 | "reads the backup as the host's service account", |
| 110 | (_stack) => |
| 111 | Effect.gen(function* () { |
| 112 | const out = yield* expectProbe<file.Backup>(baseUrl, "getBackup"); |
| 113 | const direct = yield* file.getProjectsLocationsBackups({ |
| 114 | name: backupName, |
| 115 | }); |
| 116 | expect(out.name).toEqual(backupName); |
| 117 | expect(out.sourceInstance).toEqual(direct.sourceInstance); |
| 118 | expect(out.sourceFileShare).toEqual("share1"); |
| 119 | expect(yield* hostProjectRoles(hostAccount)).toEqual(expectedRoles); |
| 120 | }), |
| 121 | { |
| 122 | tags: ["provider:gcp", "provider:gcp:filestore", "live"], |
| 123 | timeout: 600_000, |
| 124 | }, |
| 125 | ); |
| 126 | }); |
| 127 | }, |
| 128 | ); |
| 129 | |
| 130 | describe.skipIf(!runSnapshot)( |
| 131 | "Filestore Bindings (enterprise quota)", |
| 132 | { |
| 133 | tags: ["provider:gcp", "provider:gcp:filestore", "provider:gcp:run", "live"], |
| 134 | }, |
| 135 | () => { |
| 136 | beforeAll( |
| 137 | Effect.gen(function* () { |
| 138 | yield* snapshotStack.destroy(); |
| 139 | const out = yield* snapshotStack.deploy( |
| 140 | Effect.gen(function* () { |
| 141 | const host = yield* FilestoreSnapshotBindingsHost; |
| 142 | yield* ZonalNfs; |
| 143 | const snapshot = yield* Snap; |
| 144 | return { |
| 145 | uri: host.uri, |
| 146 | serviceAccount: host.serviceAccount, |
| 147 | snapshot: snapshot.name, |
| 148 | }; |
| 149 | }), |
| 150 | ); |
| 151 | snapshotBaseUrl = out.uri!; |
| 152 | snapshotHostAccount = out.serviceAccount!; |
| 153 | snapshotName = out.snapshot; |
| 154 | }), |
| 155 | { timeout: 1_800_000 }, |
| 156 | ); |
| 157 | |
| 158 | afterAll(snapshotStack.destroy(), { timeout: 1_800_000 }); |
| 159 | |
| 160 | describe("GetInstancesSnapshot", () => { |
| 161 | test.provider( |
| 162 | "reads the snapshot as the host's service account", |
| 163 | (_stack) => |
| 164 | Effect.gen(function* () { |
| 165 | const out = yield* expectProbe<file.Snapshot>(snapshotBaseUrl, "getInstancesSnapshot"); |
| 166 | const direct = yield* file.getProjectsLocationsInstancesSnapshots({ |
| 167 | name: snapshotName, |
| 168 | }); |
| 169 | expect(out.name).toEqual(snapshotName); |
| 170 | expect(out.createTime).toEqual(direct.createTime); |
| 171 | expect(yield* hostProjectRoles(snapshotHostAccount)).toEqual(expectedRoles); |
| 172 | }), |
| 173 | { |
| 174 | tags: ["provider:gcp", "provider:gcp:filestore", "live"], |
| 175 | timeout: 600_000, |
| 176 | }, |
| 177 | ); |
| 178 | }); |
| 179 | }, |
| 180 | ); |