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

main
ts 123 lines 4.33 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 firebaserules from "@distilled.cloud/gcp/firebaserules_v1";
8 import * as Effect from "effect/Effect";
9 import { expectProbe } from "../bindingHost.ts";
10 import FirebaseRulesBindingsHost, { DenyAll, Live } 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, "FirebaseRulesBindings");
15
16 let baseUrl: string;
17 let rulesetName: string;
18 let releaseName: string;
19 let hostAccount: string;
20
21 /** Roles the host's service account holds on the project, by condition. */
22 const hostProjectRoles = 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:${hostAccount}`))
30 .map((binding) => ({
31 role: binding.role,
32 condition: binding.condition?.expression,
33 }));
34 });
35
36 describe(
37 "FirebaseRules Bindings",
38 {
39 tags: ["provider:gcp", "provider:gcp:firebaserules", "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* FirebaseRulesBindingsHost;
48 const ruleset = yield* DenyAll;
49 const release = yield* Live;
50 return {
51 uri: host.uri,
52 serviceAccount: host.serviceAccount,
53 ruleset: ruleset.name,
54 release: release.name,
55 };
56 }),
57 );
58 baseUrl = out.uri!;
59 hostAccount = out.serviceAccount!;
60 rulesetName = out.ruleset;
61 releaseName = out.release;
62 }),
63 { timeout: 900_000 },
64 );
65
66 afterAll(sharedStack.destroy(), { timeout: 600_000 });
67
68 describe("TestRuleset", () => {
69 test.provider(
70 "evaluates the deployed ruleset as the host's service account",
71 (_stack) =>
72 Effect.gen(function* () {
73 const out = yield* expectProbe<firebaserules.TestRulesetResponse>(
74 baseUrl,
75 "testRuleset",
76 );
77 expect(out.issues ?? []).toEqual([]);
78 // deny-all: the DENY expectation holds, the ALLOW one fails.
79 expect((out.testResults ?? []).map((result) => result.state)).toEqual([
80 "SUCCESS",
81 "FAILURE",
82 ]);
83
84 // Firebase Rules has no resource-level IAM: project grant.
85 const roles = yield* hostProjectRoles;
86 expect(roles).toEqual([{ role: "roles/firebaserules.admin", condition: undefined }]);
87 }),
88 {
89 tags: ["provider:gcp", "provider:gcp:firebaserules", "live"],
90 timeout: 600_000,
91 },
92 );
93 });
94
95 describe("GetReleaseExecutable", () => {
96 test.provider(
97 "reads the release's compiled executable as the host's service account",
98 (_stack) =>
99 Effect.gen(function* () {
100 const out = yield* expectProbe<firebaserules.GetReleaseExecutableResponse>(
101 baseUrl,
102 "getReleaseExecutable",
103 );
104 expect(out.rulesetName).toEqual(rulesetName);
105 expect((out.executable ?? "").length).toBeGreaterThan(0);
106
107 const direct = yield* firebaserules.getExecutableProjectsReleases({
108 name: releaseName,
109 });
110 expect(out.rulesetName).toEqual(direct.rulesetName);
111 expect(out.executableVersion).toEqual(direct.executableVersion);
112
113 const roles = yield* hostProjectRoles;
114 expect(roles).toEqual([{ role: "roles/firebaserules.admin", condition: undefined }]);
115 }),
116 {
117 tags: ["provider:gcp", "provider:gcp:firebaserules", "live"],
118 timeout: 600_000,
119 },
120 );
121 });
122 },
123 );