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 { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as compute from "@distilled.cloud/gcp/compute_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 12 | |
| 13 | const waitUntilGone = (project: string, region: string, targetPoolName: string) => |
| 14 | compute.getTargetPools({ project, region, targetPool: targetPoolName }).pipe( |
| 15 | Effect.as("found" as const), |
| 16 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 17 | Effect.repeat({ |
| 18 | schedule: Schedule.spaced("1 second"), |
| 19 | until: (status) => status === "gone", |
| 20 | times: 10, |
| 21 | }), |
| 22 | ); |
| 23 | |
| 24 | test.provider( |
| 25 | "create, replace, and delete a target pool", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | const created = yield* stack.deploy( |
| 31 | Effect.gen(function* () { |
| 32 | return yield* GCP.Compute.TargetPool("Pool", { |
| 33 | region: "us-central1", |
| 34 | description: "nlb backends", |
| 35 | }); |
| 36 | }), |
| 37 | ); |
| 38 | |
| 39 | expect(created.targetPoolName).toEqual(expect.any(String)); |
| 40 | expect(created.region).toEqual("us-central1"); |
| 41 | expect(created.description).toEqual("nlb backends"); |
| 42 | expect(created.sessionAffinity).toEqual("NONE"); |
| 43 | expect(created.selfLink).toEqual(expect.stringContaining("targetPools")); |
| 44 | |
| 45 | const fetched = yield* compute.getTargetPools({ |
| 46 | project: created.project, |
| 47 | region: created.region, |
| 48 | targetPool: created.targetPoolName, |
| 49 | }); |
| 50 | expect(fetched.name).toEqual(created.targetPoolName); |
| 51 | expect(fetched.sessionAffinity).toEqual("NONE"); |
| 52 | expect(fetched.description).toContain("[alchemy "); |
| 53 | expect(fetched.description).toContain("nlb backends"); |
| 54 | |
| 55 | const replaced = yield* stack.deploy( |
| 56 | Effect.gen(function* () { |
| 57 | return yield* GCP.Compute.TargetPool("Pool", { |
| 58 | targetPoolName: created.targetPoolName, |
| 59 | region: "us-central1", |
| 60 | description: "nlb backends", |
| 61 | sessionAffinity: "CLIENT_IP", |
| 62 | }); |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(replaced.targetPoolName).toEqual(created.targetPoolName); |
| 67 | expect(replaced.sessionAffinity).toEqual("CLIENT_IP"); |
| 68 | expect(replaced.description).toEqual("nlb backends"); |
| 69 | |
| 70 | const refetched = yield* compute.getTargetPools({ |
| 71 | project: replaced.project, |
| 72 | region: replaced.region, |
| 73 | targetPool: replaced.targetPoolName, |
| 74 | }); |
| 75 | expect(refetched.sessionAffinity).toEqual("CLIENT_IP"); |
| 76 | expect(refetched.description).toContain("[alchemy "); |
| 77 | expect(refetched.description).toContain("nlb backends"); |
| 78 | |
| 79 | yield* stack.destroy(); |
| 80 | |
| 81 | const gone = yield* waitUntilGone(created.project, created.region, created.targetPoolName); |
| 82 | expect(gone).toEqual("gone"); |
| 83 | }).pipe(logLevel), |
| 84 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 85 | ); |