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.getProjectsLocationsAppsExamples({ 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 | "getProjectsLocationsAppsExamples on a missing example 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.getProjectsLocationsAppsExamples({ |
| 35 | name: `projects/${project}/locations/us/apps/missing/examples/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 an example", |
| 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-example", |
| 56 | }); |
| 57 | const example = yield* GCP.CES.AppsExample("Hello", { |
| 58 | app: app.name, |
| 59 | displayName: "hello", |
| 60 | description: "greeting", |
| 61 | messages: [ |
| 62 | { role: "user", chunks: [{ text: "Hi" }] }, |
| 63 | { role: "agent", chunks: [{ text: "Hello!" }] }, |
| 64 | ], |
| 65 | }); |
| 66 | return { app, example }; |
| 67 | }), |
| 68 | ); |
| 69 | |
| 70 | expect(created.example.name).toContain("/examples/"); |
| 71 | expect(created.example.app).toEqual(created.app.name); |
| 72 | expect(created.example.displayName).toEqual("hello"); |
| 73 | expect(created.example.description).toEqual("greeting"); |
| 74 | expect(created.example.messages?.length).toEqual(2); |
| 75 | |
| 76 | const fetched = yield* ces.getProjectsLocationsAppsExamples({ |
| 77 | name: created.example.name, |
| 78 | }); |
| 79 | expect(fetched.name).toEqual(created.example.name); |
| 80 | expect(fetched.description).toContain("alchemy-id="); |
| 81 | |
| 82 | const updated = yield* stack.deploy( |
| 83 | Effect.gen(function* () { |
| 84 | const app = yield* GCP.CES.App("Support", { |
| 85 | appId: created.app.appId, |
| 86 | location: created.app.location, |
| 87 | displayName: "support-example", |
| 88 | }); |
| 89 | const example = yield* GCP.CES.AppsExample("Hello", { |
| 90 | app: app.name, |
| 91 | exampleId: created.example.exampleId, |
| 92 | displayName: "hello", |
| 93 | description: "greeting with help", |
| 94 | messages: [ |
| 95 | { role: "user", chunks: [{ text: "Hi" }] }, |
| 96 | { |
| 97 | role: "agent", |
| 98 | chunks: [{ text: "Hello! How can I help?" }], |
| 99 | }, |
| 100 | ], |
| 101 | }); |
| 102 | return { app, example }; |
| 103 | }), |
| 104 | ); |
| 105 | |
| 106 | expect(updated.example.name).toEqual(created.example.name); |
| 107 | expect(updated.example.description).toEqual("greeting with help"); |
| 108 | |
| 109 | yield* stack.destroy(); |
| 110 | const gone = yield* waitUntilGone(created.example.name); |
| 111 | expect(gone).toEqual("gone"); |
| 112 | }).pipe(logLevel), |
| 113 | { tags: ["provider:gcp", "provider:gcp:ces", "live"], timeout: 300_000 }, |
| 114 | ); |