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

main
ts 124 lines 4.24 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 developerconnect from "@distilled.cloud/gcp/developerconnect_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 developerconnect.getProjectsLocationsInsightsConfigs({ 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 "getProjectsLocationsInsightsConfigs on a missing config fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 developerconnect.getProjectsLocationsInsightsConfigs({
34 name: `projects/${project}/locations/us-central1/insightsConfigs/alchemy-missing-insights`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:developerconnect", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 test.provider(
48 "create, update, replace, and delete an insights config",
49 (stack) =>
50 Effect.gen(function* () {
51 const { project } = yield* GcpEnvironment.current;
52 yield* stack.destroy();
53
54 const created = yield* stack.deploy(
55 Effect.gen(function* () {
56 return yield* GCP.DeveloperConnect.InsightsConfig("Sdlc", {
57 location: "us-central1",
58 projects: { projectIds: [project] },
59 labels: { env: "test" },
60 });
61 }),
62 );
63
64 expect(created.insightsConfigId).toEqual(expect.any(String));
65 expect(created.name).toContain("/insightsConfigs/");
66 expect(created.location).toEqual("us-central1");
67 expect(created.labels).toMatchObject({ env: "test" });
68
69 const fetched = yield* developerconnect.getProjectsLocationsInsightsConfigs({
70 name: created.name,
71 });
72 expect(fetched.name).toEqual(created.name);
73 expect(fetched.labels?.env).toEqual("test");
74 expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String));
75
76 const updated = yield* stack.deploy(
77 Effect.gen(function* () {
78 return yield* GCP.DeveloperConnect.InsightsConfig("Sdlc", {
79 insightsConfigId: created.insightsConfigId,
80 location: "us-central1",
81 projects: { projectIds: [project] },
82 labels: { env: "prod", role: "sdlc" },
83 });
84 }),
85 );
86
87 expect(updated.name).toEqual(created.name);
88 expect(updated.labels).toMatchObject({ env: "prod", role: "sdlc" });
89
90 const fetchedUpdate = yield* developerconnect.getProjectsLocationsInsightsConfigs({
91 name: updated.name,
92 });
93 expect(fetchedUpdate.labels?.env).toEqual("prod");
94 expect(fetchedUpdate.labels?.role).toEqual("sdlc");
95
96 const replaced = yield* stack.deploy(
97 Effect.gen(function* () {
98 return yield* GCP.DeveloperConnect.InsightsConfig("Sdlc", {
99 insightsConfigId: created.insightsConfigId,
100 location: "us-east1",
101 projects: { projectIds: [project] },
102 labels: { env: "test" },
103 });
104 }),
105 );
106
107 expect(replaced.insightsConfigId).toEqual(created.insightsConfigId);
108 expect(replaced.location).toEqual("us-east1");
109 expect(replaced.name).toContain("/locations/us-east1/");
110 expect(replaced.name).not.toEqual(created.name);
111
112 const oldGone = yield* waitUntilGone(created.name);
113 expect(oldGone).toEqual("gone");
114
115 yield* stack.destroy();
116
117 const gone = yield* waitUntilGone(replaced.name);
118 expect(gone).toEqual("gone");
119 }).pipe(logLevel),
120 {
121 tags: ["provider:gcp", "provider:gcp:developerconnect", "live"],
122 timeout: 300_000,
123 },
124 );