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 region = "us-central1"; |
| 15 | |
| 16 | const waitUntilGone = (nodeTemplate: string) => |
| 17 | GcpEnvironment.current.pipe( |
| 18 | Effect.flatMap(({ project }) => |
| 19 | compute.getNodeTemplates({ project, region, nodeTemplate }).pipe( |
| 20 | Effect.as("found" as const), |
| 21 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 22 | Effect.repeat({ |
| 23 | schedule: Schedule.spaced("1 second"), |
| 24 | until: (status) => status === "gone", |
| 25 | times: 10, |
| 26 | }), |
| 27 | ), |
| 28 | ), |
| 29 | ); |
| 30 | |
| 31 | test.provider( |
| 32 | "getNodeTemplates on a missing template fails with NotFound", |
| 33 | (stack) => |
| 34 | Effect.gen(function* () { |
| 35 | const { project } = yield* GcpEnvironment.current; |
| 36 | yield* stack.destroy(); |
| 37 | |
| 38 | const error = yield* Effect.flip( |
| 39 | compute.getNodeTemplates({ |
| 40 | project, |
| 41 | region, |
| 42 | nodeTemplate: "alchemy-missing-nt", |
| 43 | }), |
| 44 | ); |
| 45 | expect(error._tag).toBe("NotFound"); |
| 46 | |
| 47 | yield* stack.destroy(); |
| 48 | }).pipe(logLevel), |
| 49 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 50 | ); |
| 51 | |
| 52 | test.provider( |
| 53 | "create and delete a node template", |
| 54 | (stack) => |
| 55 | Effect.gen(function* () { |
| 56 | yield* stack.destroy(); |
| 57 | |
| 58 | const created = yield* stack.deploy( |
| 59 | Effect.gen(function* () { |
| 60 | return yield* GCP.Compute.NodeTemplate("SoleTenant", { |
| 61 | region, |
| 62 | nodeType: "n2-node-80-640", |
| 63 | description: "prod sole tenant", |
| 64 | }); |
| 65 | }), |
| 66 | ); |
| 67 | |
| 68 | expect(created.nodeTemplateName).toEqual(expect.any(String)); |
| 69 | expect(created.region).toEqual(region); |
| 70 | expect(created.description).toEqual("prod sole tenant"); |
| 71 | expect(created.nodeType).toEqual("n2-node-80-640"); |
| 72 | |
| 73 | const fetched = yield* compute.getNodeTemplates({ |
| 74 | project: created.project, |
| 75 | region, |
| 76 | nodeTemplate: created.nodeTemplateName, |
| 77 | }); |
| 78 | expect(fetched.name).toEqual(created.nodeTemplateName); |
| 79 | expect(fetched.description).toContain("[alchemy "); |
| 80 | |
| 81 | yield* stack.destroy(); |
| 82 | const gone = yield* waitUntilGone(created.nodeTemplateName); |
| 83 | expect(gone).toEqual("gone"); |
| 84 | }).pipe(logLevel), |
| 85 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 86 | ); |