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 baremetalsolution from "@distilled.cloud/gcp/baremetalsolution_v2"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { isServiceEnabled } from "../ServiceState.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | // Bare Metal Solution is contracted physical hardware (real cost) and the API |
| 16 | // is off on the testing project (ServiceDisabled: "Bare Metal Solution API has not |
| 17 | // been used in project ... or it is disabled."). Set |
| 18 | // GCP_TEST_BAREMETALSOLUTION_VOLUME to a provisioned boot volume on an |
| 19 | // entitled project to run the lifecycle. |
| 20 | const bootVolume = process.env.GCP_TEST_BAREMETALSOLUTION_VOLUME; |
| 21 | const runLifecycle = !!bootVolume; |
| 22 | |
| 23 | const missingVolume = (projectId: string) => |
| 24 | `projects/${projectId}/locations/us-central1/volumes/alchemy-missing-boot`; |
| 25 | |
| 26 | const waitUntilGone = (name: string) => |
| 27 | baremetalsolution.getProjectsLocationsVolumesSnapshots({ name }).pipe( |
| 28 | Effect.as("found" as const), |
| 29 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 30 | Effect.repeat({ |
| 31 | schedule: Schedule.spaced("2 seconds"), |
| 32 | until: (status) => status === "gone", |
| 33 | times: 10, |
| 34 | }), |
| 35 | ); |
| 36 | |
| 37 | test.provider( |
| 38 | "getProjectsLocationsVolumesSnapshots on a missing snapshot fails with a typed tag", |
| 39 | (stack) => |
| 40 | Effect.gen(function* () { |
| 41 | const { project } = yield* GcpEnvironment.current; |
| 42 | yield* stack.destroy(); |
| 43 | |
| 44 | const error = yield* Effect.flip( |
| 45 | baremetalsolution.getProjectsLocationsVolumesSnapshots({ |
| 46 | name: `${missingVolume(project)}/snapshots/alchemy-bms-snap-missing`, |
| 47 | }), |
| 48 | ); |
| 49 | expect(error._tag).toEqual("ServiceDisabled"); |
| 50 | |
| 51 | yield* stack.destroy(); |
| 52 | }).pipe(logLevel), |
| 53 | { |
| 54 | tags: ["provider:gcp", "provider:gcp:baremetalsolution", "live"], |
| 55 | timeout: 90_000, |
| 56 | }, |
| 57 | ); |
| 58 | |
| 59 | test.provider.skipIf(runLifecycle)( |
| 60 | "create is rejected with ServiceDisabled when the Bare Metal Solution API is disabled", |
| 61 | (stack) => |
| 62 | Effect.gen(function* () { |
| 63 | // Only meaningful while the API is disabled: enabled, the create would |
| 64 | // provision a real resource. |
| 65 | if (yield* isServiceEnabled("baremetalsolution.googleapis.com")) return; |
| 66 | const { project } = yield* GcpEnvironment.current; |
| 67 | yield* stack.destroy(); |
| 68 | |
| 69 | const error = yield* Effect.flip( |
| 70 | stack.deploy( |
| 71 | Effect.gen(function* () { |
| 72 | return yield* GCP.BareMetalSolution.VolumesSnapshot("Nightly", { |
| 73 | volume: missingVolume(project), |
| 74 | description: "alchemy-test-snap", |
| 75 | }); |
| 76 | }), |
| 77 | ), |
| 78 | ); |
| 79 | expect(error._tag).toEqual("ServiceDisabled"); |
| 80 | |
| 81 | yield* stack.destroy(); |
| 82 | }).pipe(logLevel), |
| 83 | { |
| 84 | tags: ["provider:gcp", "provider:gcp:baremetalsolution", "live"], |
| 85 | timeout: 90_000, |
| 86 | }, |
| 87 | ); |
| 88 | |
| 89 | test.provider.skipIf(!runLifecycle)( |
| 90 | "create and delete a boot volume snapshot", |
| 91 | (stack) => |
| 92 | Effect.gen(function* () { |
| 93 | yield* stack.destroy(); |
| 94 | |
| 95 | const created = yield* stack.deploy( |
| 96 | Effect.gen(function* () { |
| 97 | return yield* GCP.BareMetalSolution.VolumesSnapshot("Nightly", { |
| 98 | volume: bootVolume!, |
| 99 | description: "alchemy-test-snap", |
| 100 | }); |
| 101 | }), |
| 102 | ); |
| 103 | |
| 104 | expect(created.name).toContain("/snapshots/"); |
| 105 | expect(created.snapshotId).toEqual(expect.any(String)); |
| 106 | expect(created.description).toEqual("alchemy-test-snap"); |
| 107 | |
| 108 | const fetched = yield* baremetalsolution.getProjectsLocationsVolumesSnapshots({ |
| 109 | name: created.name, |
| 110 | }); |
| 111 | expect(fetched.name).toEqual(created.name); |
| 112 | expect(fetched.description).toContain("alchemy-id="); |
| 113 | expect(fetched.description).toContain("alchemy-test-snap"); |
| 114 | |
| 115 | yield* stack.destroy(); |
| 116 | |
| 117 | const gone = yield* waitUntilGone(created.name); |
| 118 | expect(gone).toEqual("gone"); |
| 119 | }).pipe(logLevel), |
| 120 | { |
| 121 | tags: ["provider:gcp", "provider:gcp:baremetalsolution", "live"], |
| 122 | timeout: 120_000, |
| 123 | }, |
| 124 | ); |