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 | missingMembership, |
| 10 | missingVmwareCluster, |
| 11 | currentProject, |
| 12 | vmwareAdminMembership, |
| 13 | runVmwareLifecycle, |
| 14 | vmwareControlPlane, |
| 15 | vmwareLoadBalancer, |
| 16 | vmwareNetwork, |
| 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.getProjectsLocationsVmwareClustersVmwareNodePools({ 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 | "getProjectsLocationsVmwareClustersVmwareNodePools on a missing pool 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.getProjectsLocationsVmwareClustersVmwareNodePools({ |
| 44 | name: `${missingVmwareCluster(project)}/vmwareNodePools/alchemy-missing-pool`, |
| 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(runVmwareLifecycle)( |
| 55 | "create under a missing cluster is rejected with a typed tag", |
| 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.VmwareClustersVmwareNodePool("Workers", { |
| 66 | vmwareCluster: missingVmwareCluster(project), |
| 67 | config: { |
| 68 | imageType: "ubuntu_containerd", |
| 69 | replicas: "3", |
| 70 | cpus: "4", |
| 71 | memoryMb: "8192", |
| 72 | }, |
| 73 | displayName: "alchemy-test-vmnp", |
| 74 | labels: { env: "test" }, |
| 75 | }); |
| 76 | }), |
| 77 | ), |
| 78 | ); |
| 79 | expect(error._tag).toEqual("NotFound"); |
| 80 | |
| 81 | yield* stack.destroy(); |
| 82 | }).pipe(logLevel), |
| 83 | { tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"], timeout: 90_000 }, |
| 84 | ); |
| 85 | |
| 86 | test.provider.skipIf(!runVmwareLifecycle)( |
| 87 | "create, update, and delete a vmware node pool", |
| 88 | (stack) => |
| 89 | Effect.gen(function* () { |
| 90 | const project = yield* currentProject; |
| 91 | |
| 92 | yield* stack.destroy(); |
| 93 | |
| 94 | const created = yield* stack.deploy( |
| 95 | Effect.gen(function* () { |
| 96 | const cluster = yield* GCP.GKEOnPrem.VmwareCluster("Workload", { |
| 97 | adminClusterMembership: vmwareAdminMembership ?? missingMembership(project), |
| 98 | onPremVersion: "1.28.0-gke.1", |
| 99 | controlPlaneNode: vmwareControlPlane, |
| 100 | networkConfig: vmwareNetwork, |
| 101 | loadBalancer: vmwareLoadBalancer, |
| 102 | description: "node pool parent", |
| 103 | }); |
| 104 | const pool = yield* GCP.GKEOnPrem.VmwareClustersVmwareNodePool("Workers", { |
| 105 | vmwareCluster: cluster.name, |
| 106 | config: { |
| 107 | imageType: "ubuntu_containerd", |
| 108 | replicas: "3", |
| 109 | cpus: "4", |
| 110 | memoryMb: "8192", |
| 111 | }, |
| 112 | displayName: "alchemy-test-vmnp", |
| 113 | labels: { env: "test" }, |
| 114 | }); |
| 115 | return { cluster, pool }; |
| 116 | }), |
| 117 | ); |
| 118 | |
| 119 | expect(created.pool.name).toContain("/vmwareNodePools/"); |
| 120 | expect(created.pool.vmwareCluster).toEqual(created.cluster.name); |
| 121 | expect(created.pool.displayName).toEqual("alchemy-test-vmnp"); |
| 122 | |
| 123 | const fetched = yield* gkeonprem.getProjectsLocationsVmwareClustersVmwareNodePools({ |
| 124 | name: created.pool.name, |
| 125 | }); |
| 126 | expect(fetched.name).toEqual(created.pool.name); |
| 127 | expect(fetched.displayName).toContain("alchemy-id="); |
| 128 | expect(fetched.annotations?.["alchemy-id"]).toBeDefined(); |
| 129 | |
| 130 | const updated = yield* stack.deploy( |
| 131 | Effect.gen(function* () { |
| 132 | const cluster = yield* GCP.GKEOnPrem.VmwareCluster("Workload", { |
| 133 | vmwareClusterId: created.cluster.vmwareClusterId, |
| 134 | location: created.cluster.location, |
| 135 | adminClusterMembership: |
| 136 | created.cluster.adminClusterMembership ?? |
| 137 | vmwareAdminMembership ?? |
| 138 | missingMembership(project), |
| 139 | onPremVersion: created.cluster.onPremVersion ?? "1.28.0-gke.1", |
| 140 | controlPlaneNode: created.cluster.controlPlaneNode ?? vmwareControlPlane, |
| 141 | networkConfig: created.cluster.networkConfig ?? vmwareNetwork, |
| 142 | loadBalancer: created.cluster.loadBalancer ?? vmwareLoadBalancer, |
| 143 | description: "node pool parent", |
| 144 | }); |
| 145 | const pool = yield* GCP.GKEOnPrem.VmwareClustersVmwareNodePool("Workers", { |
| 146 | vmwareNodePoolId: created.pool.vmwareNodePoolId, |
| 147 | vmwareCluster: cluster.name, |
| 148 | config: { |
| 149 | imageType: "ubuntu_containerd", |
| 150 | replicas: "5", |
| 151 | cpus: "4", |
| 152 | memoryMb: "8192", |
| 153 | }, |
| 154 | displayName: "alchemy-test-vmnp-v2", |
| 155 | }); |
| 156 | return { cluster, pool }; |
| 157 | }), |
| 158 | ); |
| 159 | |
| 160 | expect(updated.pool.displayName).toEqual("alchemy-test-vmnp-v2"); |
| 161 | expect(updated.pool.vmwareNodePoolId).toEqual(created.pool.vmwareNodePoolId); |
| 162 | |
| 163 | yield* stack.destroy(); |
| 164 | yield* waitUntilGone(created.pool.name); |
| 165 | }).pipe(logLevel), |
| 166 | { |
| 167 | tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"], |
| 168 | timeout: 120_000, |
| 169 | }, |
| 170 | ); |