The best way to control Claude Code, Codex and more from any computer or phone

main
ts 120 lines 3.94 KB
Raw
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 pingSchema = JSON.stringify({
15 openapi: "3.0.0",
16 info: { title: "Ping", version: "1.0.0" },
17 servers: [{ url: "https://example.com" }],
18 paths: {
19 "/ping": {
20 get: {
21 operationId: "ping",
22 responses: { "200": { description: "ok" } },
23 },
24 },
25 },
26 });
27
28 const waitUntilGone = (name: string) =>
29 ces.getProjectsLocationsAppsToolsets({ name }).pipe(
30 Effect.as("found" as const),
31 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
32 Effect.repeat({
33 schedule: Schedule.spaced("1 second"),
34 until: (status) => status === "gone",
35 times: 10,
36 }),
37 );
38
39 test.provider(
40 "getProjectsLocationsAppsToolsets on a missing toolset fails with a typed tag",
41 (stack) =>
42 Effect.gen(function* () {
43 const { project } = yield* GcpEnvironment.current;
44
45 yield* stack.destroy();
46
47 const error = yield* Effect.flip(
48 ces.getProjectsLocationsAppsToolsets({
49 name: `projects/${project}/locations/us/apps/missing/toolsets/missing`,
50 }),
51 );
52 expect(error._tag).toEqual("NotFound");
53
54 yield* stack.destroy();
55 }).pipe(logLevel),
56 { tags: ["provider:gcp", "provider:gcp:ces", "live"], timeout: 300_000 },
57 );
58
59 test.provider(
60 "create, update, and delete a toolset",
61 (stack) =>
62 Effect.gen(function* () {
63 yield* stack.destroy();
64
65 const created = yield* stack.deploy(
66 Effect.gen(function* () {
67 const app = yield* GCP.CES.App("Support", {
68 location: "us",
69 displayName: "support-toolset",
70 });
71 const toolset = yield* GCP.CES.AppsToolset("Ping", {
72 app: app.name,
73 displayName: "ping",
74 description: "ping endpoints",
75 openApiToolset: { openApiSchema: pingSchema },
76 });
77 return { app, toolset };
78 }),
79 );
80
81 expect(created.toolset.name).toContain("/toolsets/");
82 expect(created.toolset.app).toEqual(created.app.name);
83 expect(created.toolset.displayName).toEqual("ping");
84 expect(created.toolset.description).toEqual("ping endpoints");
85 expect(created.toolset.openApiToolset?.openApiSchema).toBeDefined();
86
87 const fetched = yield* ces.getProjectsLocationsAppsToolsets({
88 name: created.toolset.name,
89 });
90 expect(fetched.name).toEqual(created.toolset.name);
91 // The description reaches the model: no ownership marker.
92 expect(fetched.description).toEqual("ping endpoints");
93
94 const updated = yield* stack.deploy(
95 Effect.gen(function* () {
96 const app = yield* GCP.CES.App("Support", {
97 appId: created.app.appId,
98 location: created.app.location,
99 displayName: "support-toolset",
100 });
101 const toolset = yield* GCP.CES.AppsToolset("Ping", {
102 app: app.name,
103 toolsetId: created.toolset.toolsetId,
104 displayName: "ping",
105 description: "ping and health",
106 openApiToolset: { openApiSchema: pingSchema },
107 });
108 return { app, toolset };
109 }),
110 );
111
112 expect(updated.toolset.name).toEqual(created.toolset.name);
113 expect(updated.toolset.description).toEqual("ping and health");
114
115 yield* stack.destroy();
116 const gone = yield* waitUntilGone(created.toolset.name);
117 expect(gone).toEqual("gone");
118 }).pipe(logLevel),
119 { tags: ["provider:gcp", "provider:gcp:ces", "live"], timeout: 300_000 },
120 );