@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 97 lines 3.14 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 location = "us-central1";
15
16 const waitUntilGone = (name: string) =>
17 developerconnect.getProjectsLocationsConnections({ name }).pipe(
18 Effect.as("found" as const),
19 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("1 second"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 );
26
27 test.provider(
28 "getProjectsLocationsConnections on a missing connection fails with a typed tag",
29 (stack) =>
30 Effect.gen(function* () {
31 const { project } = yield* GcpEnvironment.current;
32 yield* stack.destroy();
33
34 const error = yield* Effect.flip(
35 developerconnect.getProjectsLocationsConnections({
36 name: `projects/${project}/locations/${location}/connections/alchemy-missing-connection`,
37 }),
38 );
39 expect(error._tag).toEqual("NotFound");
40
41 yield* stack.destroy();
42 }).pipe(logLevel),
43 {
44 tags: ["provider:gcp", "provider:gcp:developerconnect", "live"],
45 timeout: 90_000,
46 },
47 );
48
49 // Project setup (one-time): the Developer Connect service agent must hold
50 // roles/secretmanager.admin, see the Connection JSDoc.
51 test.provider(
52 "create, update, and delete a developer connect connection",
53 (stack) =>
54 Effect.gen(function* () {
55 yield* stack.destroy();
56
57 const created = yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* GCP.DeveloperConnect.Connection("Github", {
60 location,
61 githubConfig: { githubApp: "DEVELOPER_CONNECT" },
62 labels: { env: "test" },
63 });
64 }),
65 );
66
67 expect(created.name).toContain("/connections/");
68 expect(created.labels).toMatchObject({ env: "test" });
69
70 const fetched = yield* developerconnect.getProjectsLocationsConnections({
71 name: created.name,
72 });
73 expect(fetched.name).toEqual(created.name);
74
75 const updated = yield* stack.deploy(
76 Effect.gen(function* () {
77 return yield* GCP.DeveloperConnect.Connection("Github", {
78 connectionId: created.connectionId,
79 location,
80 githubConfig: { githubApp: "DEVELOPER_CONNECT" },
81 labels: { env: "prod", role: "git" },
82 });
83 }),
84 );
85
86 expect(updated.name).toEqual(created.name);
87 expect(updated.labels).toMatchObject({ env: "prod", role: "git" });
88
89 yield* stack.destroy();
90 const gone = yield* waitUntilGone(created.name);
91 expect(gone).toEqual("gone");
92 }).pipe(logLevel),
93 {
94 tags: ["provider:gcp", "provider:gcp:developerconnect", "live"],
95 timeout: 180_000,
96 },
97 );