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

main
ts 83 lines 3.09 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as Core from "@alchemy.run/test/Core";
5 import * as resourcemanager from "@distilled.cloud/gcp/cloudresourcemanager_v3";
6 import type * as recommendationengine from "@distilled.cloud/gcp/recommendationengine_v1beta1";
7 import * as Effect from "effect/Effect";
8 import { expectProbe } from "../bindingHost.ts";
9 import { currentProject, entitled } from "./common.ts";
10 import RecommendationEngineBindingsHost, { Shirt, TITLE } 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, "RecommendationEngineBindings");
15
16 let baseUrl: string;
17 let member: string;
18 let itemId: string;
19
20 // Recommendations AI (Beta) is not enabled in the testing project; see
21 // common.ts (GCP_TEST_RECOMMENDATION_ENGINE=1).
22 describe.skipIf(!entitled || !!process.env.FAST)(
23 "RecommendationEngine Bindings",
24 {
25 tags: ["provider:gcp", "provider:gcp:recommendationengine", "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* RecommendationEngineBindingsHost;
34 return {
35 uri: host.uri,
36 serviceAccount: host.serviceAccount,
37 itemId: (yield* Shirt).catalogItemId,
38 };
39 }),
40 );
41 baseUrl = out.uri!;
42 member = `serviceAccount:${out.serviceAccount!}`;
43 itemId = out.itemId;
44 }),
45 { timeout: 900_000 },
46 );
47
48 afterAll(sharedStack.destroy(), { timeout: 600_000 });
49
50 describe("GetCatalogItem", () => {
51 test.provider(
52 "reads the catalog item, granted viewer on the project",
53 (_stack) =>
54 Effect.gen(function* () {
55 const live =
56 yield* expectProbe<recommendationengine.GoogleCloudRecommendationengineV1beta1CatalogItem>(
57 baseUrl,
58 "getCatalogItem",
59 );
60 expect(live.id).toEqual(itemId);
61 expect(live.title).toEqual(TITLE);
62
63 // Recommendations AI has no resource-level IAM or IAM
64 // Conditions, so the viewer role is granted on the project.
65 const project = yield* currentProject;
66 const policy = yield* resourcemanager.getIamPolicyProjects({
67 resource: `projects/${project}`,
68 body: { options: { requestedPolicyVersion: 3 } },
69 });
70 expect(
71 (policy.bindings ?? [])
72 .filter((binding) => (binding.members ?? []).includes(member))
73 .map((binding) => [binding.role, binding.condition]),
74 ).toEqual([["roles/automlrecommendations.viewer", undefined]]);
75 }),
76 {
77 tags: ["provider:gcp", "provider:gcp:recommendationengine", "live"],
78 timeout: 600_000,
79 },
80 );
81 });
82 },
83 );