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 oracle from "@distilled.cloud/gcp/oracledatabase_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 | // Oracle Database@Google Cloud is not enabled in the test project |
| 15 | // (ServiceDisabled) and needs an Oracle Cloud subscription. Set |
| 16 | // GCP_TEST_ORACLE=1 in a project that has one. |
| 17 | const runLifecycle = !!process.env.GCP_TEST_ORACLE && !process.env.FAST; |
| 18 | |
| 19 | const SSH_KEY = |
| 20 | "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl alchemy-test"; |
| 21 | |
| 22 | const waitUntilGone = (name: string) => |
| 23 | oracle.getProjectsLocationsExadbVmClusters({ name }).pipe( |
| 24 | Effect.as("found" as const), |
| 25 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 26 | Effect.repeat({ |
| 27 | schedule: Schedule.spaced("2 seconds"), |
| 28 | until: (status) => status === "gone", |
| 29 | times: 10, |
| 30 | }), |
| 31 | ); |
| 32 | |
| 33 | test.provider.skipIf(runLifecycle)( |
| 34 | "getProjectsLocationsExadbVmClusters without Oracle Database enabled fails with ServiceDisabled", |
| 35 | (stack) => |
| 36 | Effect.gen(function* () { |
| 37 | const { project } = yield* GcpEnvironment.current; |
| 38 | |
| 39 | yield* stack.destroy(); |
| 40 | |
| 41 | const error = yield* Effect.flip( |
| 42 | oracle.getProjectsLocationsExadbVmClusters({ |
| 43 | name: `projects/${project}/locations/us-central1/exadbVmClusters/alchemy-oracle-missing`, |
| 44 | }), |
| 45 | ); |
| 46 | expect(error._tag).toEqual("ServiceDisabled"); |
| 47 | |
| 48 | yield* stack.destroy(); |
| 49 | }).pipe(logLevel), |
| 50 | { |
| 51 | tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"], |
| 52 | timeout: 90_000, |
| 53 | }, |
| 54 | ); |
| 55 | |
| 56 | test.provider.skipIf(!runLifecycle)( |
| 57 | "create, update, and delete an exadb vm cluster", |
| 58 | (stack) => |
| 59 | Effect.gen(function* () { |
| 60 | const { project } = yield* GcpEnvironment.current; |
| 61 | |
| 62 | yield* stack.destroy(); |
| 63 | |
| 64 | const created = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | const vault = yield* GCP.OracleDatabase.ExascaleDbStorageVault("Vault", { |
| 67 | displayName: "alchemyvault", |
| 68 | totalSizeGbs: 300, |
| 69 | }); |
| 70 | return yield* GCP.OracleDatabase.ExadbVmCluster("ExaVm", { |
| 71 | location: "us-central1", |
| 72 | displayName: "alchemyexavm", |
| 73 | odbSubnet: `projects/${project}/locations/us-central1/odbNetworks/missing/odbSubnets/client`, |
| 74 | backupOdbSubnet: `projects/${project}/locations/us-central1/odbNetworks/missing/odbSubnets/backup`, |
| 75 | gridImageId: "19.0.0.0", |
| 76 | hostnamePrefix: "exavm", |
| 77 | sshPublicKeys: [SSH_KEY], |
| 78 | exascaleDbStorageVault: vault.name, |
| 79 | enabledEcpuCountPerNode: 8, |
| 80 | nodeCount: 2, |
| 81 | properties: { |
| 82 | vmFileSystemStorage: { sizeInGbsPerNode: 180 }, |
| 83 | shapeAttribute: "SMART_STORAGE", |
| 84 | }, |
| 85 | labels: { env: "test" }, |
| 86 | }); |
| 87 | }), |
| 88 | ); |
| 89 | |
| 90 | expect(created.name).toContain("/exadbVmClusters/"); |
| 91 | expect(created.exadbVmClusterId).toEqual(expect.any(String)); |
| 92 | expect(created.labels).toMatchObject({ env: "test" }); |
| 93 | |
| 94 | const fetched = yield* oracle.getProjectsLocationsExadbVmClusters({ |
| 95 | name: created.name, |
| 96 | }); |
| 97 | expect(fetched.name).toEqual(created.name); |
| 98 | |
| 99 | yield* stack.destroy(); |
| 100 | |
| 101 | const gone = yield* waitUntilGone(created.name); |
| 102 | expect(gone).toEqual("gone"); |
| 103 | }).pipe(logLevel), |
| 104 | { |
| 105 | tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"], |
| 106 | timeout: 120_000, |
| 107 | }, |
| 108 | ); |