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 | import { DEFAULT_NETWORK } from "../networkQuota.ts"; |
| 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, routeName: string) => |
| 15 | compute.getRoutes({ project, route: routeName }).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, replace, and delete a route", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | yield* stack.destroy(); |
| 30 | |
| 31 | const created = yield* stack.deploy( |
| 32 | Effect.gen(function* () { |
| 33 | const route = yield* GCP.Compute.Route("Internet", { |
| 34 | destRange: "192.0.2.0/24", |
| 35 | network: DEFAULT_NETWORK, |
| 36 | nextHopGateway: "default-internet-gateway", |
| 37 | description: "test-net egress", |
| 38 | tags: ["alchemy-test"], |
| 39 | }); |
| 40 | return { route }; |
| 41 | }), |
| 42 | ); |
| 43 | |
| 44 | expect(created.route.routeName).toEqual(expect.any(String)); |
| 45 | expect(created.route.destRange).toEqual("192.0.2.0/24"); |
| 46 | expect(created.route.priority).toEqual(1000); |
| 47 | expect(created.route.description).toEqual("test-net egress"); |
| 48 | expect(created.route.tags).toEqual(["alchemy-test"]); |
| 49 | expect(created.route.network).toContain(`networks/${DEFAULT_NETWORK}`); |
| 50 | expect(created.route.nextHopGateway).toContain("default-internet-gateway"); |
| 51 | |
| 52 | const fetched = yield* compute.getRoutes({ |
| 53 | project: created.route.project, |
| 54 | route: created.route.routeName, |
| 55 | }); |
| 56 | expect(fetched.name).toEqual(created.route.routeName); |
| 57 | expect(fetched.destRange).toEqual("192.0.2.0/24"); |
| 58 | expect(fetched.description).toContain("[alchemy "); |
| 59 | expect(fetched.description).toContain("test-net egress"); |
| 60 | expect(fetched.tags).toEqual(["alchemy-test"]); |
| 61 | |
| 62 | const updated = yield* stack.deploy( |
| 63 | Effect.gen(function* () { |
| 64 | const route = yield* GCP.Compute.Route("Internet", { |
| 65 | routeName: created.route.routeName, |
| 66 | destRange: "198.51.100.0/24", |
| 67 | network: DEFAULT_NETWORK, |
| 68 | nextHopGateway: "default-internet-gateway", |
| 69 | description: "updated test-net", |
| 70 | priority: 900, |
| 71 | }); |
| 72 | return { route }; |
| 73 | }), |
| 74 | ); |
| 75 | |
| 76 | expect(updated.route.routeName).toEqual(created.route.routeName); |
| 77 | expect(updated.route.destRange).toEqual("198.51.100.0/24"); |
| 78 | expect(updated.route.description).toEqual("updated test-net"); |
| 79 | expect(updated.route.priority).toEqual(900); |
| 80 | expect(updated.route.tags).toEqual([]); |
| 81 | |
| 82 | const refetched = yield* compute.getRoutes({ |
| 83 | project: updated.route.project, |
| 84 | route: updated.route.routeName, |
| 85 | }); |
| 86 | expect(refetched.destRange).toEqual("198.51.100.0/24"); |
| 87 | expect(refetched.priority).toEqual(900); |
| 88 | expect(refetched.description).toContain("updated test-net"); |
| 89 | |
| 90 | yield* stack.destroy(); |
| 91 | |
| 92 | const gone = yield* waitUntilGone(created.route.project, created.route.routeName); |
| 93 | expect(gone).toEqual("gone"); |
| 94 | }).pipe(logLevel), |
| 95 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 120_000 }, |
| 96 | ); |