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 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 | const runLifecycle = !process.env.FAST; |
| 15 | |
| 16 | const waitUntilGone = (name: string) => |
| 17 | netapp.getProjectsLocationsKmsConfigs({ name }).pipe( |
| 18 | Effect.as("found" as const), |
| 19 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 20 | Effect.repeat({ |
| 21 | schedule: Schedule.spaced("2 seconds"), |
| 22 | until: (status) => status === "gone", |
| 23 | times: 10, |
| 24 | }), |
| 25 | ); |
| 26 | |
| 27 | test.provider( |
| 28 | "getProjectsLocationsKmsConfigs on a missing config fails with a typed tag", |
| 29 | (stack) => |
| 30 | Effect.gen(function* () { |
| 31 | const { project } = yield* GcpEnvironment.current; |
| 32 | |
| 33 | yield* stack.destroy(); |
| 34 | |
| 35 | const error = yield* Effect.flip( |
| 36 | netapp.getProjectsLocationsKmsConfigs({ |
| 37 | name: `projects/${project}/locations/us-central1/kmsConfigs/alchemy-netapp-missing`, |
| 38 | }), |
| 39 | ); |
| 40 | expect(error._tag).toEqual("NotFound"); |
| 41 | |
| 42 | const page = yield* netapp.listProjectsLocationsKmsConfigs({ |
| 43 | parent: `projects/${project}/locations/-`, |
| 44 | pageSize: 10, |
| 45 | }); |
| 46 | expect((page.kmsConfigs ?? []).map((item) => item.name)).not.toContain( |
| 47 | `projects/${project}/locations/us-central1/kmsConfigs/alchemy-netapp-missing`, |
| 48 | ); |
| 49 | |
| 50 | yield* stack.destroy(); |
| 51 | }).pipe(logLevel), |
| 52 | { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 90_000 }, |
| 53 | ); |
| 54 | |
| 55 | test.provider.skipIf(!runLifecycle)( |
| 56 | "create, update, and delete a kms config", |
| 57 | (stack) => |
| 58 | Effect.gen(function* () { |
| 59 | const { project } = yield* GcpEnvironment.current; |
| 60 | const cryptoKeyName = `projects/${project}/locations/us-central1/keyRings/alchemy-test-keyring/cryptoKeys/alchemy-test-cryptokey-enc`; |
| 61 | |
| 62 | yield* stack.destroy(); |
| 63 | |
| 64 | const created = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | return yield* GCP.NetApp.KmsConfig("Cmek", { |
| 67 | cryptoKeyName, |
| 68 | description: "alchemy-test-cmek", |
| 69 | labels: { env: "test" }, |
| 70 | }); |
| 71 | }), |
| 72 | ); |
| 73 | |
| 74 | expect(created.name).toContain("/kmsConfigs/"); |
| 75 | expect(created.cryptoKeyName).toEqual(cryptoKeyName); |
| 76 | expect(created.labels).toMatchObject({ env: "test" }); |
| 77 | |
| 78 | const fetched = yield* netapp.getProjectsLocationsKmsConfigs({ |
| 79 | name: created.name, |
| 80 | }); |
| 81 | expect(fetched.name).toEqual(created.name); |
| 82 | expect(fetched.cryptoKeyName).toEqual(cryptoKeyName); |
| 83 | expect(fetched.labels?.env).toEqual("test"); |
| 84 | |
| 85 | const updated = yield* stack.deploy( |
| 86 | Effect.gen(function* () { |
| 87 | return yield* GCP.NetApp.KmsConfig("Cmek", { |
| 88 | kmsConfigId: created.kmsConfigId, |
| 89 | cryptoKeyName, |
| 90 | description: "alchemy-prod-cmek", |
| 91 | labels: { env: "prod", role: "cmek" }, |
| 92 | }); |
| 93 | }), |
| 94 | ); |
| 95 | |
| 96 | expect(updated.name).toEqual(created.name); |
| 97 | expect(updated.description).toEqual("alchemy-prod-cmek"); |
| 98 | expect(updated.labels).toMatchObject({ env: "prod", role: "cmek" }); |
| 99 | |
| 100 | yield* stack.destroy(); |
| 101 | |
| 102 | const gone = yield* waitUntilGone(created.name); |
| 103 | expect(gone).toEqual("gone"); |
| 104 | }).pipe(logLevel), |
| 105 | { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 900_000 }, |
| 106 | ); |