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

main
ts 98 lines 3.48 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 bqdt from "@distilled.cloud/gcp/bigquerydatatransfer_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 BigQueryDataTransferBindingsHost, { Nightly } 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, "BigQueryDataTransferBindings");
15
16 let baseUrl: string;
17 let configName: 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 "BigQueryDataTransfer Bindings",
38 {
39 tags: ["provider:gcp", "provider:gcp:bigquerydatatransfer", "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* BigQueryDataTransferBindingsHost;
48 const config = yield* Nightly;
49 return {
50 uri: host.uri,
51 serviceAccount: host.serviceAccount,
52 config: config.name,
53 };
54 }),
55 );
56 baseUrl = out.uri!;
57 configName = out.config;
58 hostAccount = out.serviceAccount!;
59 }),
60 { timeout: 900_000 },
61 );
62
63 afterAll(sharedStack.destroy(), { timeout: 600_000 });
64
65 describe("StartManualRuns", () => {
66 test.provider(
67 "starts a run as the host's service account",
68 (_stack) =>
69 Effect.gen(function* () {
70 const out = yield* expectProbe<bqdt.StartManualTransferRunsResponse>(
71 baseUrl,
72 "startManualRuns",
73 );
74 expect(out.runs).toHaveLength(1);
75 const runName = out.runs?.[0]?.name ?? "";
76 expect(runName.startsWith(`${configName}/runs/`)).toEqual(true);
77
78 const run = yield* bqdt.getProjectsLocationsTransferConfigsRuns({
79 name: runName,
80 });
81 expect(run.name).toEqual(runName);
82 expect(run.dataSourceId).toEqual("scheduled_query");
83 expect(run.runTime).toEqual("2020-01-01T00:00:00Z");
84
85 // Transfer configs have no resource-level IAM or IAM Conditions
86 // support, so the binding documents a project grant.
87 expect(yield* projectGrantsOf(hostAccount)).toEqual([
88 { role: "roles/bigquery.admin", condition: undefined },
89 ]);
90 }),
91 {
92 tags: ["provider:gcp", "provider:gcp:bigquerydatatransfer", "live"],
93 timeout: 600_000,
94 },
95 );
96 });
97 },
98 );