@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 124 lines 4.47 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as cloudbuild from "@distilled.cloud/gcp/cloudbuild_v2";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (name: string) =>
14 cloudbuild.getProjectsLocationsConnections({ name }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 test.provider(
25 "create, update, replace, and delete a connection",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const created = yield* stack.deploy(
31 Effect.gen(function* () {
32 return yield* GCP.CloudBuild.Connection("Github", {
33 location: "us-central1",
34 annotations: { env: "test" },
35 githubConfig: {},
36 });
37 }),
38 );
39
40 expect(created.connectionId).toEqual(expect.any(String));
41 expect(created.name).toContain("/connections/");
42 expect(created.location).toEqual("us-central1");
43 expect(created.disabled).toEqual(false);
44 expect(created.annotations).toMatchObject({ env: "test" });
45 expect(created.githubConfig).toEqual(expect.any(Object));
46 expect(created.installationState?.stage).toEqual(expect.any(String));
47
48 const fetched = yield* cloudbuild.getProjectsLocationsConnections({
49 name: created.name,
50 });
51 expect(fetched.name).toEqual(created.name);
52 expect(fetched.annotations?.env).toEqual("test");
53 expect(fetched.annotations?.["alchemy-id"]).toEqual(expect.any(String));
54 expect(fetched.disabled ?? false).toEqual(false);
55 expect(fetched.githubConfig).toEqual(expect.any(Object));
56
57 const listed = yield* cloudbuild.listProjectsLocationsConnections({
58 parent: `projects/${created.project}/locations/${created.location}`,
59 });
60 expect(
61 (listed.connections ?? []).some((connection) => connection.name === created.name),
62 ).toEqual(true);
63
64 const updated = yield* stack.deploy(
65 Effect.gen(function* () {
66 return yield* GCP.CloudBuild.Connection("Github", {
67 connectionId: created.connectionId,
68 location: "us-central1",
69 annotations: { env: "prod", role: "scm" },
70 disabled: true,
71 githubConfig: {},
72 });
73 }),
74 );
75
76 expect(updated.name).toEqual(created.name);
77 expect(updated.connectionId).toEqual(created.connectionId);
78 expect(updated.disabled).toEqual(true);
79 expect(updated.annotations).toMatchObject({ env: "prod", role: "scm" });
80
81 const fetchedUpdate = yield* cloudbuild.getProjectsLocationsConnections({
82 name: updated.name,
83 });
84 expect(fetchedUpdate.disabled).toEqual(true);
85 expect(fetchedUpdate.annotations?.env).toEqual("prod");
86 expect(fetchedUpdate.annotations?.role).toEqual("scm");
87
88 const replaced = yield* stack.deploy(
89 Effect.gen(function* () {
90 return yield* GCP.CloudBuild.Connection("Github", {
91 connectionId: created.connectionId,
92 location: "us-east1",
93 annotations: { env: "test" },
94 githubConfig: {},
95 });
96 }),
97 );
98
99 expect(replaced.connectionId).toEqual(created.connectionId);
100 expect(replaced.location).toEqual("us-east1");
101 expect(replaced.name).toContain("/locations/us-east1/");
102 expect(replaced.name).not.toEqual(created.name);
103 expect(replaced.disabled).toEqual(false);
104
105 const oldGone = yield* waitUntilGone(created.name);
106 expect(oldGone).toEqual("gone");
107
108 const fetchedReplace = yield* cloudbuild.getProjectsLocationsConnections({
109 name: replaced.name,
110 });
111 expect(fetchedReplace.name).toEqual(replaced.name);
112 expect(fetchedReplace.disabled ?? false).toEqual(false);
113 expect(fetchedReplace.annotations?.env).toEqual("test");
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:cloudbuild", "live"],
122 timeout: 90_000,
123 },
124 );