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 compute from "@distilled.cloud/gcp/compute_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 13 | |
| 14 | const zone = "us-central1-a"; |
| 15 | |
| 16 | const waitUntilGone = (networkEndpointGroup: string) => |
| 17 | GcpEnvironment.current.pipe( |
| 18 | Effect.flatMap(({ project }) => |
| 19 | compute |
| 20 | .getNetworkEndpointGroups({ |
| 21 | project, |
| 22 | zone, |
| 23 | networkEndpointGroup, |
| 24 | }) |
| 25 | .pipe( |
| 26 | Effect.as("found" as const), |
| 27 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 28 | Effect.repeat({ |
| 29 | schedule: Schedule.spaced("1 second"), |
| 30 | until: (status) => status === "gone", |
| 31 | times: 10, |
| 32 | }), |
| 33 | ), |
| 34 | ), |
| 35 | ); |
| 36 | |
| 37 | test.provider( |
| 38 | "create, replace, and delete a network endpoint group", |
| 39 | (stack) => |
| 40 | Effect.gen(function* () { |
| 41 | const { project } = yield* GcpEnvironment.current; |
| 42 | yield* stack.destroy(); |
| 43 | |
| 44 | const created = yield* stack.deploy( |
| 45 | Effect.gen(function* () { |
| 46 | return yield* GCP.Compute.NetworkEndpointGroup("Web", { |
| 47 | zone, |
| 48 | description: "zonal backends", |
| 49 | network: "default", |
| 50 | defaultPort: 80, |
| 51 | }); |
| 52 | }), |
| 53 | ); |
| 54 | |
| 55 | expect(created.networkEndpointGroupName).toEqual(expect.any(String)); |
| 56 | expect(created.zone).toEqual(zone); |
| 57 | expect(created.description).toEqual("zonal backends"); |
| 58 | expect(created.networkEndpointType).toEqual("GCE_VM_IP_PORT"); |
| 59 | expect(created.defaultPort).toEqual(80); |
| 60 | expect(created.size).toEqual(0); |
| 61 | |
| 62 | const fetched = yield* compute.getNetworkEndpointGroups({ |
| 63 | project, |
| 64 | zone, |
| 65 | networkEndpointGroup: created.networkEndpointGroupName, |
| 66 | }); |
| 67 | expect(fetched.name).toEqual(created.networkEndpointGroupName); |
| 68 | expect(fetched.description).toContain("[alchemy "); |
| 69 | expect(fetched.description).toContain("zonal backends"); |
| 70 | expect(fetched.networkEndpointType).toEqual("GCE_VM_IP_PORT"); |
| 71 | expect(fetched.defaultPort).toEqual(80); |
| 72 | expect(fetched.network).toContain("default"); |
| 73 | |
| 74 | const replaced = yield* stack.deploy( |
| 75 | Effect.gen(function* () { |
| 76 | return yield* GCP.Compute.NetworkEndpointGroup("Web", { |
| 77 | networkEndpointGroupName: created.networkEndpointGroupName, |
| 78 | zone, |
| 79 | description: "replaced backends", |
| 80 | network: "default", |
| 81 | defaultPort: 8080, |
| 82 | }); |
| 83 | }), |
| 84 | ); |
| 85 | |
| 86 | expect(replaced.networkEndpointGroupName).toEqual(created.networkEndpointGroupName); |
| 87 | expect(replaced.description).toEqual("replaced backends"); |
| 88 | expect(replaced.defaultPort).toEqual(8080); |
| 89 | expect(replaced.id).not.toEqual(created.id); |
| 90 | |
| 91 | const replacedFetched = yield* compute.getNetworkEndpointGroups({ |
| 92 | project, |
| 93 | zone, |
| 94 | networkEndpointGroup: replaced.networkEndpointGroupName, |
| 95 | }); |
| 96 | expect(replacedFetched.description).toContain("replaced backends"); |
| 97 | expect(replacedFetched.defaultPort).toEqual(8080); |
| 98 | expect(replacedFetched.id).toEqual(replaced.id); |
| 99 | |
| 100 | yield* stack.destroy(); |
| 101 | |
| 102 | const gone = yield* waitUntilGone(created.networkEndpointGroupName); |
| 103 | expect(gone).toEqual("gone"); |
| 104 | }).pipe(logLevel), |
| 105 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 106 | ); |