@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 84 lines 3.13 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 crm from "@distilled.cloud/gcp/cloudresourcemanager_v3";
7 import * as connectors from "@distilled.cloud/gcp/connectors_v2";
8 import * as Effect from "effect/Effect";
9 import { expectProbe } from "../bindingHost.ts";
10 import ConnectorsBindingsHost, { Account, ENTITY_TYPE_PARENT } 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, "ConnectorsBindings");
15
16 let baseUrl: string;
17 let hostAccount: string;
18 let entityName: string;
19
20 // Entities live in an existing Integration Connectors connection; set
21 // GCP_TEST_CONNECTORS_PARENT to its `…/entityTypes/{type}` to run this.
22 describe.skipIf(ENTITY_TYPE_PARENT.length === 0)(
23 "Connectors Bindings",
24 {
25 tags: ["provider:gcp", "provider:gcp:connectors", "provider:gcp:run", "live"],
26 },
27 () => {
28 beforeAll(
29 Effect.gen(function* () {
30 yield* sharedStack.destroy();
31 const out = yield* sharedStack.deploy(
32 Effect.gen(function* () {
33 const host = yield* ConnectorsBindingsHost;
34 const entity = yield* Account;
35 return {
36 uri: host.uri,
37 serviceAccount: host.serviceAccount,
38 entity: entity.name,
39 };
40 }),
41 );
42 baseUrl = out.uri!;
43 hostAccount = out.serviceAccount!;
44 entityName = out.entity;
45 }),
46 { timeout: 900_000 },
47 );
48
49 afterAll(sharedStack.destroy(), { timeout: 600_000 });
50
51 describe("GetEntity", () => {
52 test.provider(
53 "reads the entity as the host's service account, granted on the project",
54 (_stack) =>
55 Effect.gen(function* () {
56 const entity = yield* expectProbe<connectors.Entity>(baseUrl, "getEntity");
57 const live = yield* connectors.getProjectsLocationsConnectionsEntityTypesEntities({
58 name: entityName,
59 });
60 expect(entity.name).toEqual(entityName);
61 expect(entity.fields).toMatchObject({ Name: "Alchemy Binding" });
62 expect(entity.fields).toEqual(live.fields);
63
64 // Connectors has no resource-level IAM for entities.
65 const { project } = yield* GcpEnvironment.current;
66 const policy = yield* crm.getIamPolicyProjects({
67 resource: `projects/${project}`,
68 body: { options: { requestedPolicyVersion: 3 } },
69 });
70 const roles = (policy.bindings ?? [])
71 .filter((binding) =>
72 (binding.members ?? []).includes(`serviceAccount:${hostAccount}`),
73 )
74 .map((binding) => binding.role);
75 expect(roles).toEqual(["roles/connectors.invoker"]);
76 }),
77 {
78 tags: ["provider:gcp", "provider:gcp:connectors", "live"],
79 timeout: 600_000,
80 },
81 );
82 });
83 },
84 );