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 waitUntilGone = (project: string, crossSiteNetwork: string) => |
| 15 | compute.getCrossSiteNetworks({ project, crossSiteNetwork }).pipe( |
| 16 | Effect.as("found" as const), |
| 17 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 18 | Effect.repeat({ |
| 19 | schedule: Schedule.spaced("1 second"), |
| 20 | until: (status) => status === "gone", |
| 21 | times: 10, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | test.provider( |
| 26 | "create, update, replace, and delete a cross-site network", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | yield* stack.destroy(); |
| 30 | |
| 31 | const created = yield* stack.deploy( |
| 32 | Effect.gen(function* () { |
| 33 | return yield* GCP.Compute.CrossSiteNetwork("Backbone", { |
| 34 | description: "cross-cloud fabric", |
| 35 | }); |
| 36 | }), |
| 37 | ); |
| 38 | |
| 39 | expect(created.crossSiteNetworkName).toEqual(expect.any(String)); |
| 40 | expect(created.description).toEqual("cross-cloud fabric"); |
| 41 | |
| 42 | const fetched = yield* compute.getCrossSiteNetworks({ |
| 43 | project: created.project, |
| 44 | crossSiteNetwork: created.crossSiteNetworkName, |
| 45 | }); |
| 46 | expect(fetched.name).toEqual(created.crossSiteNetworkName); |
| 47 | expect(fetched.description).toContain("[alchemy "); |
| 48 | expect(fetched.description).toContain("cross-cloud fabric"); |
| 49 | |
| 50 | const updated = yield* stack.deploy( |
| 51 | Effect.gen(function* () { |
| 52 | return yield* GCP.Compute.CrossSiteNetwork("Backbone", { |
| 53 | crossSiteNetworkName: created.crossSiteNetworkName, |
| 54 | description: "updated fabric", |
| 55 | }); |
| 56 | }), |
| 57 | ); |
| 58 | expect(updated.crossSiteNetworkName).toEqual(created.crossSiteNetworkName); |
| 59 | expect(updated.description).toEqual("updated fabric"); |
| 60 | |
| 61 | const nextName = `r${created.crossSiteNetworkName}`.slice(0, 63).replace(/-+$/, "x"); |
| 62 | const replaced = yield* stack.deploy( |
| 63 | Effect.gen(function* () { |
| 64 | return yield* GCP.Compute.CrossSiteNetwork("Backbone", { |
| 65 | crossSiteNetworkName: nextName, |
| 66 | description: "replaced fabric", |
| 67 | }); |
| 68 | }), |
| 69 | ); |
| 70 | expect(replaced.crossSiteNetworkName).toEqual(nextName); |
| 71 | |
| 72 | const oldGone = yield* waitUntilGone(created.project, created.crossSiteNetworkName); |
| 73 | expect(oldGone).toEqual("gone"); |
| 74 | |
| 75 | yield* stack.destroy(); |
| 76 | const gone = yield* waitUntilGone(replaced.project, replaced.crossSiteNetworkName); |
| 77 | expect(gone).toEqual("gone"); |
| 78 | }).pipe(logLevel), |
| 79 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 80 | ); |