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 ces from "@distilled.cloud/gcp/ces_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 = (name: string) => |
| 15 | ces.getProjectsLocationsAppsDeployments({ name }).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 | "getProjectsLocationsAppsDeployments on a missing deployment fails with a typed tag", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | const { project } = yield* GcpEnvironment.current; |
| 30 | |
| 31 | yield* stack.destroy(); |
| 32 | |
| 33 | const error = yield* Effect.flip( |
| 34 | ces.getProjectsLocationsAppsDeployments({ |
| 35 | name: `projects/${project}/locations/us/apps/missing/deployments/missing`, |
| 36 | }), |
| 37 | ); |
| 38 | expect(error._tag).toEqual("NotFound"); |
| 39 | |
| 40 | yield* stack.destroy(); |
| 41 | }).pipe(logLevel), |
| 42 | { tags: ["provider:gcp", "provider:gcp:ces", "live"], timeout: 300_000 }, |
| 43 | ); |
| 44 | |
| 45 | test.provider( |
| 46 | "create, update, and delete a deployment", |
| 47 | (stack) => |
| 48 | Effect.gen(function* () { |
| 49 | yield* stack.destroy(); |
| 50 | |
| 51 | const created = yield* stack.deploy( |
| 52 | Effect.gen(function* () { |
| 53 | const app = yield* GCP.CES.App("Support", { |
| 54 | location: "us", |
| 55 | displayName: "support-deployment", |
| 56 | }); |
| 57 | const version = yield* GCP.CES.AppsVersion("V1", { app: app.name }); |
| 58 | const deployment = yield* GCP.CES.AppsDeployment("Prod", { |
| 59 | app: app.name, |
| 60 | appVersion: version.name, |
| 61 | displayName: "prod", |
| 62 | channelProfile: { channelType: "API", profileId: "api" }, |
| 63 | }); |
| 64 | return { app, deployment }; |
| 65 | }), |
| 66 | ); |
| 67 | |
| 68 | expect(created.deployment.name).toContain("/deployments/"); |
| 69 | expect(created.deployment.app).toEqual(created.app.name); |
| 70 | expect(created.deployment.displayName).toEqual("prod"); |
| 71 | expect(created.deployment.channelProfile).toBeDefined(); |
| 72 | |
| 73 | const fetched = yield* ces.getProjectsLocationsAppsDeployments({ |
| 74 | name: created.deployment.name, |
| 75 | }); |
| 76 | expect(fetched.name).toEqual(created.deployment.name); |
| 77 | expect(fetched.displayName).toContain("alchemy-"); |
| 78 | |
| 79 | const updated = yield* stack.deploy( |
| 80 | Effect.gen(function* () { |
| 81 | const app = yield* GCP.CES.App("Support", { |
| 82 | appId: created.app.appId, |
| 83 | location: created.app.location, |
| 84 | displayName: "support-deployment", |
| 85 | }); |
| 86 | const version = yield* GCP.CES.AppsVersion("V1", { app: app.name }); |
| 87 | const deployment = yield* GCP.CES.AppsDeployment("Prod", { |
| 88 | app: app.name, |
| 89 | appVersion: version.name, |
| 90 | deploymentId: created.deployment.deploymentId, |
| 91 | displayName: "prod-api", |
| 92 | channelProfile: { channelType: "API", profileId: "api" }, |
| 93 | }); |
| 94 | return { app, deployment }; |
| 95 | }), |
| 96 | ); |
| 97 | |
| 98 | expect(updated.deployment.name).toEqual(created.deployment.name); |
| 99 | expect(updated.deployment.displayName).toEqual("prod-api"); |
| 100 | |
| 101 | yield* stack.destroy(); |
| 102 | const gone = yield* waitUntilGone(created.deployment.name); |
| 103 | expect(gone).toEqual("gone"); |
| 104 | }).pipe(logLevel), |
| 105 | { tags: ["provider:gcp", "provider:gcp:ces", "live"], timeout: 300_000 }, |
| 106 | ); |