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

main
ts 109 lines 3.63 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 clouddeploy from "@distilled.cloud/gcp/clouddeploy_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 clouddeploy.getProjectsLocationsTargets({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsTargets on a missing target 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 clouddeploy.getProjectsLocationsTargets({
35 name: `projects/${project}/locations/us-central1/targets/alchemy-missing-target`,
36 }),
37 );
38 expect(error._tag).toEqual("NotFound");
39
40 yield* stack.destroy();
41 }).pipe(logLevel),
42 {
43 tags: ["provider:gcp", "provider:gcp:clouddeploy", "live"],
44 timeout: 90_000,
45 },
46 );
47
48 test.provider(
49 "create, update, and delete a Cloud Run target",
50 (stack) =>
51 Effect.gen(function* () {
52 const { project } = yield* GcpEnvironment.current;
53 const runLocation = `projects/${project}/locations/us-central1`;
54
55 yield* stack.destroy();
56
57 const created = yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* GCP.CloudDeploy.Target("Prod", {
60 run: { location: runLocation },
61 description: "alchemy-test-target",
62 labels: { env: "test" },
63 });
64 }),
65 );
66
67 expect(created.name).toContain("/targets/");
68 expect(created.targetId).toEqual(expect.any(String));
69 expect(created.location).toEqual("us-central1");
70 expect(created.description).toEqual("alchemy-test-target");
71 expect(created.run?.location).toEqual(runLocation);
72 expect(created.requireApproval).toEqual(false);
73 expect(created.labels).toMatchObject({ env: "test" });
74
75 const fetched = yield* clouddeploy.getProjectsLocationsTargets({
76 name: created.name,
77 });
78 expect(fetched.name).toEqual(created.name);
79 expect(fetched.description).toEqual("alchemy-test-target");
80 expect(fetched.labels?.env).toEqual("test");
81 expect(fetched.run?.location).toEqual(runLocation);
82
83 const updated = yield* stack.deploy(
84 Effect.gen(function* () {
85 return yield* GCP.CloudDeploy.Target("Prod", {
86 targetId: created.targetId,
87 run: { location: runLocation },
88 requireApproval: true,
89 description: "alchemy-prod-target",
90 labels: { env: "prod", role: "run" },
91 });
92 }),
93 );
94
95 expect(updated.name).toEqual(created.name);
96 expect(updated.description).toEqual("alchemy-prod-target");
97 expect(updated.requireApproval).toEqual(true);
98 expect(updated.labels).toMatchObject({ env: "prod", role: "run" });
99
100 yield* stack.destroy();
101
102 const gone = yield* waitUntilGone(created.name);
103 expect(gone).toEqual("gone");
104 }).pipe(logLevel),
105 {
106 tags: ["provider:gcp", "provider:gcp:clouddeploy", "live"],
107 timeout: 90_000,
108 },
109 );