@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 104 lines 3.51 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 dlp from "@distilled.cloud/gcp/dlp_v2";
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 // Organization-scoped: set GOOGLE_ORGANIZATION_ID when the credentials
13 // administer the organization (the testing service account does not).
14 const organizationId = process.env.GOOGLE_ORGANIZATION_ID?.trim().replace(/^organizations\//, "");
15 const organization = `organizations/${organizationId}`;
16
17 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
18
19 const location = "us-central1";
20
21 const waitUntilGone = (name: string) =>
22 dlp.getOrganizationsLocationsConnections({ name }).pipe(
23 Effect.as("found" as const),
24 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
25 Effect.repeat({
26 schedule: Schedule.spaced("1 second"),
27 until: (status) => status === "gone",
28 times: 10,
29 }),
30 );
31
32 test.provider.skipIf(!organizationId)(
33 "getOrganizationsLocationsConnections on a missing connection fails with a typed tag",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const error = yield* Effect.flip(
39 dlp.getOrganizationsLocationsConnections({
40 name: `${organization}/locations/${location}/connections/alchemy-missing`,
41 }),
42 );
43 expect(error._tag).toEqual("NotFound");
44
45 yield* stack.destroy();
46 }).pipe(logLevel),
47 { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 },
48 );
49
50 test.provider.skipIf(!organizationId || !!process.env.FAST)(
51 "create, update, and delete an organization DLP connection",
52 (stack) =>
53 Effect.gen(function* () {
54 const { project } = yield* GcpEnvironment.current;
55 yield* stack.destroy();
56
57 const cloudSql = {
58 connectionName: `${project}:${location}:alchemy-dlp-sql`,
59 databaseEngine: "DATABASE_ENGINE_POSTGRES" as const,
60 maxConnections: 2,
61 cloudSqlIam: {},
62 };
63
64 const created = yield* stack.deploy(
65 Effect.gen(function* () {
66 return yield* GCP.DLP.OrganizationsLocationsConnection("Warehouse", {
67 organization,
68 location,
69 state: "MISSING_CREDENTIALS",
70 cloudSql,
71 });
72 }),
73 );
74
75 expect(created.location).toEqual(location);
76 expect(created.name).toContain("/connections/");
77 expect(created.cloudSql?.connectionName).toEqual(cloudSql.connectionName);
78
79 const fetched = yield* dlp.getOrganizationsLocationsConnections({
80 name: created.name,
81 });
82 expect(fetched.name).toEqual(created.name);
83
84 const updated = yield* stack.deploy(
85 Effect.gen(function* () {
86 return yield* GCP.DLP.OrganizationsLocationsConnection("Warehouse", {
87 organization,
88 location,
89 state: "MISSING_CREDENTIALS",
90 cloudSql: { ...cloudSql, maxConnections: 3 },
91 });
92 }),
93 );
94
95 expect(updated.name).toEqual(created.name);
96 expect(updated.cloudSql?.maxConnections).toEqual(3);
97
98 yield* stack.destroy();
99
100 const gone = yield* waitUntilGone(created.name);
101 expect(gone).toEqual("gone");
102 }).pipe(logLevel),
103 { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 },
104 );