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.getProjectsLocationsAppsTools({ 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 | "getProjectsLocationsAppsTools on a missing tool 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.getProjectsLocationsAppsTools({ |
| 35 | name: `projects/${project}/locations/us/apps/missing/tools/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 tool", |
| 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-tool", |
| 56 | }); |
| 57 | const tool = yield* GCP.CES.AppsTool("Lookup", { |
| 58 | app: app.name, |
| 59 | clientFunction: { |
| 60 | name: "lookup_order", |
| 61 | description: "Look up an order.", |
| 62 | parameters: { |
| 63 | type: "OBJECT", |
| 64 | properties: { orderId: { type: "STRING" } }, |
| 65 | }, |
| 66 | }, |
| 67 | }); |
| 68 | return { app, tool }; |
| 69 | }), |
| 70 | ); |
| 71 | |
| 72 | expect(created.tool.name).toContain("/tools/"); |
| 73 | expect(created.tool.app).toEqual(created.app.name); |
| 74 | expect(created.tool.clientFunction?.name).toEqual("lookup_order"); |
| 75 | expect(created.tool.clientFunction?.description).toEqual("Look up an order."); |
| 76 | |
| 77 | const fetched = yield* ces.getProjectsLocationsAppsTools({ |
| 78 | name: created.tool.name, |
| 79 | }); |
| 80 | expect(fetched.name).toEqual(created.tool.name); |
| 81 | // The description tells the model when to call the tool: no marker. |
| 82 | expect(fetched.clientFunction?.description).toEqual("Look up an order."); |
| 83 | |
| 84 | const updated = yield* stack.deploy( |
| 85 | Effect.gen(function* () { |
| 86 | const app = yield* GCP.CES.App("Support", { |
| 87 | appId: created.app.appId, |
| 88 | location: created.app.location, |
| 89 | displayName: "support-tool", |
| 90 | }); |
| 91 | const tool = yield* GCP.CES.AppsTool("Lookup", { |
| 92 | app: app.name, |
| 93 | toolId: created.tool.toolId, |
| 94 | clientFunction: { |
| 95 | name: "lookup_order", |
| 96 | description: "Look up an order by id.", |
| 97 | parameters: { |
| 98 | type: "OBJECT", |
| 99 | properties: { |
| 100 | orderId: { type: "STRING" }, |
| 101 | includeHistory: { type: "BOOLEAN" }, |
| 102 | }, |
| 103 | }, |
| 104 | }, |
| 105 | }); |
| 106 | return { app, tool }; |
| 107 | }), |
| 108 | ); |
| 109 | |
| 110 | expect(updated.tool.name).toEqual(created.tool.name); |
| 111 | expect(updated.tool.clientFunction?.description).toEqual("Look up an order by id."); |
| 112 | |
| 113 | yield* stack.destroy(); |
| 114 | const gone = yield* waitUntilGone(created.tool.name); |
| 115 | expect(gone).toEqual("gone"); |
| 116 | }).pipe(logLevel), |
| 117 | { tags: ["provider:gcp", "provider:gcp:ces", "live"], timeout: 300_000 }, |
| 118 | ); |