The best way to control Claude Code, Codex and more from any computer or phone
| 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 netapp from "@distilled.cloud/gcp/netapp_v1"; |
| 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 | // Volumes need a Private Service Access connection to |
| 15 | // `netapp.servicenetworking.goog` on the `default` network (otherwise volume |
| 16 | // create fails with `Please create Service Networking connection with |
| 17 | // service 'netapp.servicenetworking.goog' ...`), and each file provisions its |
| 18 | // own 2 TiB STANDARD pool while the default regional quota |
| 19 | // (StandardStoragePoolCapacityGiBPerRegion = 2048) fits one. Set |
| 20 | // GCP_TEST_NETAPP_VOLUMES=1 on a project with both. |
| 21 | const runLifecycle = !!process.env.GCP_TEST_NETAPP_VOLUMES && !process.env.FAST; |
| 22 | |
| 23 | const waitUntilGone = (name: string) => |
| 24 | netapp.getProjectsLocationsBackupVaultsBackups({ name }).pipe( |
| 25 | Effect.as("found" as const), |
| 26 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 27 | Effect.repeat({ |
| 28 | schedule: Schedule.spaced("2 seconds"), |
| 29 | until: (status) => status === "gone", |
| 30 | times: 10, |
| 31 | }), |
| 32 | ); |
| 33 | |
| 34 | test.provider( |
| 35 | "getProjectsLocationsBackupVaultsBackups on a missing backup fails with a typed tag", |
| 36 | (stack) => |
| 37 | Effect.gen(function* () { |
| 38 | const { project } = yield* GcpEnvironment.current; |
| 39 | |
| 40 | yield* stack.destroy(); |
| 41 | |
| 42 | const error = yield* Effect.flip( |
| 43 | netapp.getProjectsLocationsBackupVaultsBackups({ |
| 44 | name: `projects/${project}/locations/us-central1/backupVaults/alchemy-missing-vault/backups/alchemy-missing-backup`, |
| 45 | }), |
| 46 | ); |
| 47 | expect(error._tag).toEqual("NotFound"); |
| 48 | |
| 49 | const page = yield* netapp.listProjectsLocationsBackupVaultsBackups({ |
| 50 | parent: `projects/${project}/locations/-/backupVaults/-`, |
| 51 | pageSize: 10, |
| 52 | }); |
| 53 | expect((page.backups ?? []).map((item) => item.name)).not.toContain( |
| 54 | `projects/${project}/locations/us-central1/backupVaults/alchemy-missing-vault/backups/alchemy-missing-backup`, |
| 55 | ); |
| 56 | |
| 57 | yield* stack.destroy(); |
| 58 | }).pipe(logLevel), |
| 59 | { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 90_000 }, |
| 60 | ); |
| 61 | |
| 62 | test.provider.skipIf(!runLifecycle)( |
| 63 | "create, update, and delete a backup", |
| 64 | (stack) => |
| 65 | Effect.gen(function* () { |
| 66 | yield* stack.destroy(); |
| 67 | |
| 68 | const created = yield* stack.deploy( |
| 69 | Effect.gen(function* () { |
| 70 | const pool = yield* GCP.NetApp.StoragePool("Pool", { |
| 71 | network: "default", |
| 72 | serviceLevel: "STANDARD", |
| 73 | capacityGib: 2048, |
| 74 | labels: { env: "test" }, |
| 75 | }); |
| 76 | const volume = yield* GCP.NetApp.Volume("Share", { |
| 77 | storagePool: pool.name, |
| 78 | protocols: ["NFSV3"], |
| 79 | capacityGib: 100, |
| 80 | labels: { env: "test" }, |
| 81 | }); |
| 82 | const vault = yield* GCP.NetApp.BackupVault("Vault", { |
| 83 | labels: { env: "test" }, |
| 84 | }); |
| 85 | return yield* GCP.NetApp.BackupVaultsBackup("Nightly", { |
| 86 | backupVault: vault.name, |
| 87 | sourceVolume: volume.name, |
| 88 | description: "alchemy-test-backup", |
| 89 | labels: { env: "test" }, |
| 90 | }); |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | expect(created.name).toContain("/backups/"); |
| 95 | expect(created.sourceVolume).toContain("/volumes/"); |
| 96 | expect(created.labels).toMatchObject({ env: "test" }); |
| 97 | |
| 98 | const fetched = yield* netapp.getProjectsLocationsBackupVaultsBackups({ |
| 99 | name: created.name, |
| 100 | }); |
| 101 | expect(fetched.name).toEqual(created.name); |
| 102 | expect(fetched.labels?.env).toEqual("test"); |
| 103 | |
| 104 | const updated = yield* stack.deploy( |
| 105 | Effect.gen(function* () { |
| 106 | const pool = yield* GCP.NetApp.StoragePool("Pool", { |
| 107 | network: "default", |
| 108 | serviceLevel: "STANDARD", |
| 109 | capacityGib: 2048, |
| 110 | labels: { env: "test" }, |
| 111 | }); |
| 112 | const volume = yield* GCP.NetApp.Volume("Share", { |
| 113 | storagePool: pool.name, |
| 114 | protocols: ["NFSV3"], |
| 115 | capacityGib: 100, |
| 116 | labels: { env: "test" }, |
| 117 | }); |
| 118 | const vault = yield* GCP.NetApp.BackupVault("Vault", { |
| 119 | labels: { env: "test" }, |
| 120 | }); |
| 121 | return yield* GCP.NetApp.BackupVaultsBackup("Nightly", { |
| 122 | backupId: created.backupId, |
| 123 | backupVault: vault.name, |
| 124 | sourceVolume: volume.name, |
| 125 | description: "alchemy-prod-backup", |
| 126 | labels: { env: "prod", role: "backup" }, |
| 127 | }); |
| 128 | }), |
| 129 | ); |
| 130 | |
| 131 | expect(updated.name).toEqual(created.name); |
| 132 | expect(updated.description).toEqual("alchemy-prod-backup"); |
| 133 | expect(updated.labels).toMatchObject({ env: "prod", role: "backup" }); |
| 134 | |
| 135 | yield* stack.destroy(); |
| 136 | |
| 137 | const gone = yield* waitUntilGone(created.name); |
| 138 | expect(gone).toEqual("gone"); |
| 139 | }).pipe(logLevel), |
| 140 | { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 900_000 }, |
| 141 | ); |