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 { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as gkeonprem from "@distilled.cloud/gcp/gkeonprem_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { |
| 9 | bareMetalControlPlane, |
| 10 | bareMetalLoadBalancer, |
| 11 | bareMetalNetwork, |
| 12 | bareMetalStorage, |
| 13 | missingMembership, |
| 14 | currentProject, |
| 15 | bareMetalAdminMembership, |
| 16 | runBareMetalLifecycle, |
| 17 | } from "./common.ts"; |
| 18 | |
| 19 | const { test } = Test.make({ providers: GCP.providers() }); |
| 20 | |
| 21 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 22 | |
| 23 | const waitUntilGone = (name: string) => |
| 24 | gkeonprem.getProjectsLocationsBareMetalClusters({ 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 | "getProjectsLocationsBareMetalClusters on a missing cluster fails with a typed tag", |
| 36 | (stack) => |
| 37 | Effect.gen(function* () { |
| 38 | const project = yield* currentProject; |
| 39 | |
| 40 | yield* stack.destroy(); |
| 41 | |
| 42 | const error = yield* Effect.flip( |
| 43 | gkeonprem.getProjectsLocationsBareMetalClusters({ |
| 44 | name: `projects/${project}/locations/us-central1/bareMetalClusters/alchemy-missing-bmc`, |
| 45 | }), |
| 46 | ); |
| 47 | expect(error._tag).toEqual("NotFound"); |
| 48 | |
| 49 | yield* stack.destroy(); |
| 50 | }).pipe(logLevel), |
| 51 | { tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"], timeout: 90_000 }, |
| 52 | ); |
| 53 | |
| 54 | test.provider.skipIf(runBareMetalLifecycle)( |
| 55 | "create without an admin cluster fails with AdminClusterUnreachable", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | const project = yield* currentProject; |
| 59 | |
| 60 | yield* stack.destroy(); |
| 61 | |
| 62 | const error = yield* Effect.flip( |
| 63 | stack.deploy( |
| 64 | Effect.gen(function* () { |
| 65 | return yield* GCP.GKEOnPrem.BareMetalCluster("Workload", { |
| 66 | adminClusterMembership: missingMembership(project), |
| 67 | bareMetalVersion: "1.28.0-gke.1", |
| 68 | controlPlane: bareMetalControlPlane, |
| 69 | storage: bareMetalStorage, |
| 70 | networkConfig: bareMetalNetwork, |
| 71 | loadBalancer: bareMetalLoadBalancer, |
| 72 | description: "alchemy-test-bmc", |
| 73 | labels: { env: "test" }, |
| 74 | }); |
| 75 | }), |
| 76 | ), |
| 77 | ); |
| 78 | expect(error._tag).toEqual("AdminClusterUnreachable"); |
| 79 | |
| 80 | yield* stack.destroy(); |
| 81 | }).pipe(logLevel), |
| 82 | { tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"], timeout: 90_000 }, |
| 83 | ); |
| 84 | |
| 85 | test.provider.skipIf(!runBareMetalLifecycle)( |
| 86 | "create, update, and delete a bare metal cluster", |
| 87 | (stack) => |
| 88 | Effect.gen(function* () { |
| 89 | const project = yield* currentProject; |
| 90 | |
| 91 | yield* stack.destroy(); |
| 92 | |
| 93 | const created = yield* stack.deploy( |
| 94 | Effect.gen(function* () { |
| 95 | return yield* GCP.GKEOnPrem.BareMetalCluster("Workload", { |
| 96 | adminClusterMembership: bareMetalAdminMembership ?? missingMembership(project), |
| 97 | bareMetalVersion: "1.28.0-gke.1", |
| 98 | controlPlane: bareMetalControlPlane, |
| 99 | storage: bareMetalStorage, |
| 100 | networkConfig: bareMetalNetwork, |
| 101 | loadBalancer: bareMetalLoadBalancer, |
| 102 | description: "alchemy-test-bmc", |
| 103 | labels: { env: "test" }, |
| 104 | }); |
| 105 | }), |
| 106 | ); |
| 107 | |
| 108 | expect(created.name).toContain("/bareMetalClusters/"); |
| 109 | expect(created.description).toEqual("alchemy-test-bmc"); |
| 110 | expect(created.labels.env).toEqual("test"); |
| 111 | |
| 112 | const fetched = yield* gkeonprem.getProjectsLocationsBareMetalClusters({ |
| 113 | name: created.name, |
| 114 | }); |
| 115 | expect(fetched.name).toEqual(created.name); |
| 116 | expect(fetched.description).toContain("alchemy-id="); |
| 117 | expect(fetched.description).toContain("alchemy-test-bmc"); |
| 118 | expect(fetched.annotations?.["alchemy-id"]).toBeDefined(); |
| 119 | |
| 120 | const updated = yield* stack.deploy( |
| 121 | Effect.gen(function* () { |
| 122 | return yield* GCP.GKEOnPrem.BareMetalCluster("Workload", { |
| 123 | bareMetalClusterId: created.bareMetalClusterId, |
| 124 | location: created.location, |
| 125 | adminClusterMembership: |
| 126 | created.adminClusterMembership ?? |
| 127 | bareMetalAdminMembership ?? |
| 128 | missingMembership(project), |
| 129 | bareMetalVersion: created.bareMetalVersion ?? "1.28.0-gke.1", |
| 130 | controlPlane: created.controlPlane ?? bareMetalControlPlane, |
| 131 | storage: created.storage ?? bareMetalStorage, |
| 132 | networkConfig: created.networkConfig ?? bareMetalNetwork, |
| 133 | loadBalancer: created.loadBalancer ?? bareMetalLoadBalancer, |
| 134 | description: "alchemy-test-bmc-v2", |
| 135 | labels: { env: "test", team: "platform" }, |
| 136 | }); |
| 137 | }), |
| 138 | ); |
| 139 | |
| 140 | expect(updated.description).toEqual("alchemy-test-bmc-v2"); |
| 141 | expect(updated.labels.team).toEqual("platform"); |
| 142 | expect(updated.bareMetalClusterId).toEqual(created.bareMetalClusterId); |
| 143 | |
| 144 | yield* stack.destroy(); |
| 145 | yield* waitUntilGone(created.name); |
| 146 | }).pipe(logLevel), |
| 147 | { |
| 148 | tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"], |
| 149 | timeout: 120_000, |
| 150 | }, |
| 151 | ); |