@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 126 lines 4.5 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 resourcemanager from "@distilled.cloud/gcp/cloudresourcemanager_v3";
7 import * as rma from "@distilled.cloud/gcp/rapidmigrationassessment_v1";
8 import * as Effect from "effect/Effect";
9 import { expectProbe } from "../bindingHost.ts";
10 import RmaBindingsHost, { OnPrem } 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, "RapidMigrationAssessmentBindings");
15
16 // Needs the Rapid Migration Assessment API (disabled on the testing
17 // project). Set GCP_TEST_RMA=1 on a project with the API enabled.
18 const runLifecycle = !!process.env.GCP_TEST_RMA && !process.env.FAST;
19
20 let baseUrl: string;
21 let member: string;
22 let collectorName: string;
23
24 /** The operation a probe started exists and targets the bound collector. */
25 const expectOperationOnCollector = (operation: rma.Operation) =>
26 Effect.gen(function* () {
27 expect(operation.name).toContain("/operations/");
28 const live = yield* rma.getProjectsLocationsOperations({
29 name: operation.name!,
30 });
31 expect(live.name).toEqual(operation.name);
32 expect(JSON.stringify(live.metadata ?? {})).toContain(collectorName);
33 });
34
35 /** `[role, condition]` the host holds on the project. */
36 const hostProjectGrants = Effect.gen(function* () {
37 const { project } = yield* GcpEnvironment.current;
38 const policy = yield* resourcemanager.getIamPolicyProjects({
39 resource: `projects/${project}`,
40 body: { options: { requestedPolicyVersion: 3 } },
41 });
42 return (policy.bindings ?? [])
43 .filter((binding) => (binding.members ?? []).includes(member))
44 .map((binding) => [binding.role, binding.condition]);
45 });
46
47 describe.skipIf(!runLifecycle)(
48 "RapidMigrationAssessment Bindings",
49 {
50 tags: ["provider:gcp", "provider:gcp:rapidmigrationassessment", "provider:gcp:run", "live"],
51 },
52 () => {
53 beforeAll(
54 Effect.gen(function* () {
55 yield* sharedStack.destroy();
56 const out = yield* sharedStack.deploy(
57 Effect.gen(function* () {
58 const host = yield* RmaBindingsHost;
59 return {
60 uri: host.uri,
61 serviceAccount: host.serviceAccount,
62 collector: (yield* OnPrem).name,
63 };
64 }),
65 );
66 baseUrl = out.uri!;
67 member = `serviceAccount:${out.serviceAccount!}`;
68 collectorName = out.collector;
69 }),
70 { timeout: 900_000 },
71 );
72
73 afterAll(sharedStack.destroy(), { timeout: 600_000 });
74
75 // RMA has no resource-level IAM; rma.runner is granted on the project.
76 const runnerOnProject = [["roles/rma.runner", undefined]];
77
78 describe("PauseCollector", () => {
79 test.provider(
80 "starts a pause operation on the collector",
81 (_stack) =>
82 Effect.gen(function* () {
83 const operation = yield* expectProbe<rma.Operation>(baseUrl, "pause");
84 yield* expectOperationOnCollector(operation);
85 expect(yield* hostProjectGrants).toEqual(runnerOnProject);
86 }),
87 {
88 tags: ["provider:gcp", "provider:gcp:rapidmigrationassessment", "live"],
89 timeout: 600_000,
90 },
91 );
92 });
93
94 describe("ResumeCollector", () => {
95 test.provider(
96 "starts a resume operation on the collector",
97 (_stack) =>
98 Effect.gen(function* () {
99 const operation = yield* expectProbe<rma.Operation>(baseUrl, "resume");
100 yield* expectOperationOnCollector(operation);
101 expect(yield* hostProjectGrants).toEqual(runnerOnProject);
102 }),
103 {
104 tags: ["provider:gcp", "provider:gcp:rapidmigrationassessment", "live"],
105 timeout: 600_000,
106 },
107 );
108 });
109
110 describe("RegisterCollector", () => {
111 test.provider(
112 "starts a register operation on the collector",
113 (_stack) =>
114 Effect.gen(function* () {
115 const operation = yield* expectProbe<rma.Operation>(baseUrl, "register");
116 yield* expectOperationOnCollector(operation);
117 expect(yield* hostProjectGrants).toEqual(runnerOnProject);
118 }),
119 {
120 tags: ["provider:gcp", "provider:gcp:rapidmigrationassessment", "live"],
121 timeout: 600_000,
122 },
123 );
124 });
125 },
126 );