@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 101 lines 3.7 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as Core from "@alchemy.run/test/Core";
6 import * as bigqueryconnection from "@distilled.cloud/gcp/bigqueryconnection_v1";
7 import * as resourcemanager from "@distilled.cloud/gcp/cloudresourcemanager_v3";
8 import * as Effect from "effect/Effect";
9 import { expectProbe } from "../bindingHost.ts";
10 import BigQueryConnectionBindingsHost, { Cloud } from "./fixtures/bindings-host.ts";
11
12 const testOptions = { providers: GCP.providers() };
13 const { test, beforeAll, afterAll } = Test.make(testOptions);
14 const sharedStack = Core.scratchStack(testOptions, "BigQueryConnectionBindings");
15
16 let baseUrl: string;
17 let connectionName: string;
18 let hostAccount: string;
19
20 /** Every project-level role (and its IAM Condition) `account` holds. */
21 const projectGrantsOf = (account: string) =>
22 Effect.gen(function* () {
23 const { project } = yield* GcpEnvironment.current;
24 const policy = yield* resourcemanager.getIamPolicyProjects({
25 resource: `projects/${project}`,
26 body: { options: { requestedPolicyVersion: 3 } },
27 });
28 return (policy.bindings ?? [])
29 .filter((binding) => (binding.members ?? []).includes(`serviceAccount:${account}`))
30 .map((binding) => ({
31 role: binding.role,
32 condition: binding.condition?.expression,
33 }));
34 });
35
36 describe(
37 "BigQueryConnection Bindings",
38 {
39 tags: ["provider:gcp", "provider:gcp:bigqueryconnection", "provider:gcp:run", "live"],
40 },
41 () => {
42 beforeAll(
43 Effect.gen(function* () {
44 yield* sharedStack.destroy();
45 const out = yield* sharedStack.deploy(
46 Effect.gen(function* () {
47 const host = yield* BigQueryConnectionBindingsHost;
48 const connection = yield* Cloud;
49 return {
50 uri: host.uri,
51 serviceAccount: host.serviceAccount,
52 connection: connection.name,
53 };
54 }),
55 );
56 baseUrl = out.uri!;
57 connectionName = out.connection;
58 hostAccount = out.serviceAccount!;
59 }),
60 { timeout: 900_000 },
61 );
62
63 afterAll(sharedStack.destroy(), { timeout: 600_000 });
64
65 describe("GetConnection", () => {
66 test.provider(
67 "reads the connection as the host's service account, granted on the connection only",
68 (_stack) =>
69 Effect.gen(function* () {
70 const live = yield* expectProbe<{
71 name?: string;
72 cloudResource?: { serviceAccountId?: string };
73 }>(baseUrl, "getConnection");
74 const expected = yield* bigqueryconnection.getProjectsLocationsConnections({
75 name: connectionName,
76 });
77 expect(live.name).toEqual(connectionName);
78 expect(live.cloudResource?.serviceAccountId).toEqual(
79 expected.cloudResource?.serviceAccountId,
80 );
81
82 const policy = yield* bigqueryconnection.getIamPolicyProjectsLocationsConnections({
83 resource: connectionName,
84 body: { options: { requestedPolicyVersion: 3 } },
85 });
86 const roles = (policy.bindings ?? [])
87 .filter((binding) =>
88 (binding.members ?? []).includes(`serviceAccount:${hostAccount}`),
89 )
90 .map((binding) => binding.role);
91 expect(roles).toEqual(["roles/bigquery.connectionUser"]);
92 expect(yield* projectGrantsOf(hostAccount)).toEqual([]);
93 }),
94 {
95 tags: ["provider:gcp", "provider:gcp:bigqueryconnection", "live"],
96 timeout: 600_000,
97 },
98 );
99 });
100 },
101 );