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

main
ts 99 lines 3.28 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 // CES only serves the `us` and `eu` multi-regions; `us-central1` returns
15 // Forbidden ("Location us-central1 is not found or access is unauthorized").
16
17 const waitUntilGone = (name: string) =>
18 ces.getProjectsLocationsApps({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("1 second"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider(
29 "getProjectsLocationsApps on a missing app fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 ces.getProjectsLocationsApps({
38 name: `projects/${project}/locations/us/apps/alchemy-missing-app`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 yield* stack.destroy();
44 }).pipe(logLevel),
45 { tags: ["provider:gcp", "provider:gcp:ces", "live"], timeout: 300_000 },
46 );
47
48 test.provider(
49 "create, update, and delete an app",
50 (stack) =>
51 Effect.gen(function* () {
52 yield* stack.destroy();
53
54 const created = yield* stack.deploy(
55 Effect.gen(function* () {
56 return yield* GCP.CES.App("Support", {
57 location: "us",
58 displayName: "support",
59 description: "help desk",
60 timeZone: "America/Los_Angeles",
61 });
62 }),
63 );
64
65 expect(created.name).toContain("/apps/");
66 expect(created.location).toEqual("us");
67 expect(created.displayName).toEqual("support");
68 expect(created.description).toEqual("help desk");
69 expect(created.timeZone).toEqual("America/Los_Angeles");
70
71 const fetched = yield* ces.getProjectsLocationsApps({
72 name: created.name,
73 });
74 expect(fetched.name).toEqual(created.name);
75 expect(fetched.metadata?.["alchemy-id"]).toEqual(expect.any(String));
76
77 const updated = yield* stack.deploy(
78 Effect.gen(function* () {
79 return yield* GCP.CES.App("Support", {
80 appId: created.appId,
81 location: created.location,
82 displayName: "support-desk",
83 description: "updated help desk",
84 timeZone: "America/New_York",
85 });
86 }),
87 );
88
89 expect(updated.name).toEqual(created.name);
90 expect(updated.displayName).toEqual("support-desk");
91 expect(updated.description).toEqual("updated help desk");
92 expect(updated.timeZone).toEqual("America/New_York");
93
94 yield* stack.destroy();
95 const gone = yield* waitUntilGone(created.name);
96 expect(gone).toEqual("gone");
97 }).pipe(logLevel),
98 { tags: ["provider:gcp", "provider:gcp:ces", "live"], timeout: 300_000 },
99 );