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, name: string) => |
| 14 | compute.getRegionBackendServices({ project, region, backendService: name }).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, update, and delete a region backend service", |
| 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.RegionBackendService("Web", { |
| 33 | protocol: "HTTP", |
| 34 | loadBalancingScheme: "INTERNAL_MANAGED", |
| 35 | description: "alchemy test", |
| 36 | labels: { env: "test" }, |
| 37 | }); |
| 38 | }), |
| 39 | ); |
| 40 | |
| 41 | expect(created.name).toEqual(expect.any(String)); |
| 42 | expect(created.region).toEqual("us-central1"); |
| 43 | expect(created.protocol).toEqual("HTTP"); |
| 44 | expect(created.loadBalancingScheme).toEqual("INTERNAL_MANAGED"); |
| 45 | expect(created.timeoutSec).toEqual(30); |
| 46 | expect(created.description).toEqual("alchemy test"); |
| 47 | expect(created.labels).toMatchObject({ env: "test" }); |
| 48 | |
| 49 | const fetched = yield* compute.getRegionBackendServices({ |
| 50 | project: created.project, |
| 51 | region: created.region, |
| 52 | backendService: created.name, |
| 53 | }); |
| 54 | expect(fetched.name).toEqual(created.name); |
| 55 | expect(fetched.protocol).toEqual("HTTP"); |
| 56 | expect(fetched.loadBalancingScheme).toEqual("INTERNAL_MANAGED"); |
| 57 | expect(fetched.description).toContain("alchemy-id="); |
| 58 | expect(fetched.description).toContain("env=test"); |
| 59 | expect(fetched.description).toContain("alchemy test"); |
| 60 | expect(fetched.timeoutSec).toEqual(30); |
| 61 | |
| 62 | const updated = yield* stack.deploy( |
| 63 | Effect.gen(function* () { |
| 64 | return yield* GCP.Compute.RegionBackendService("Web", { |
| 65 | name: created.name, |
| 66 | region: created.region, |
| 67 | protocol: "HTTP", |
| 68 | loadBalancingScheme: "INTERNAL_MANAGED", |
| 69 | timeoutSec: 60, |
| 70 | localityLbPolicy: "ROUND_ROBIN", |
| 71 | description: "updated", |
| 72 | labels: { env: "prod", role: "lb" }, |
| 73 | }); |
| 74 | }), |
| 75 | ); |
| 76 | |
| 77 | expect(updated.name).toEqual(created.name); |
| 78 | expect(updated.timeoutSec).toEqual(60); |
| 79 | expect(updated.localityLbPolicy).toEqual("ROUND_ROBIN"); |
| 80 | expect(updated.description).toEqual("updated"); |
| 81 | expect(updated.labels).toMatchObject({ env: "prod", role: "lb" }); |
| 82 | |
| 83 | const fetchedUpdate = yield* compute.getRegionBackendServices({ |
| 84 | project: created.project, |
| 85 | region: created.region, |
| 86 | backendService: created.name, |
| 87 | }); |
| 88 | expect(fetchedUpdate.timeoutSec).toEqual(60); |
| 89 | expect(fetchedUpdate.localityLbPolicy).toEqual("ROUND_ROBIN"); |
| 90 | expect(fetchedUpdate.description).toContain("env=prod"); |
| 91 | expect(fetchedUpdate.description).toContain("role=lb"); |
| 92 | expect(fetchedUpdate.description).toContain("updated"); |
| 93 | |
| 94 | yield* stack.destroy(); |
| 95 | |
| 96 | const gone = yield* waitUntilGone(created.project, created.region, created.name); |
| 97 | expect(gone).toEqual("gone"); |
| 98 | }).pipe(logLevel), |
| 99 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 120_000 }, |
| 100 | ); |