The best way to control Claude Code, Codex and more from any computer or phone
| 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 crm from "@distilled.cloud/gcp/cloudresourcemanager_v3"; |
| 6 | import type * as retail from "@distilled.cloud/gcp/retail_v2"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { expectProbe } from "../bindingHost.ts"; |
| 9 | import RetailBindingsHost, { retailEnabled, Serving, Shirt } from "./fixtures/bindings-host.ts"; |
| 10 | |
| 11 | const testOptions = { providers: GCP.providers() }; |
| 12 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 13 | const sharedStack = Core.scratchStack(testOptions, "RetailBindings"); |
| 14 | |
| 15 | let baseUrl: string; |
| 16 | let hostAccount: string; |
| 17 | let project: string; |
| 18 | |
| 19 | /** Serving configs have no IAM policy: both bindings grant on the project. */ |
| 20 | const expectProjectGrants = Effect.gen(function* () { |
| 21 | const policy = yield* crm.getIamPolicyProjects({ |
| 22 | resource: `projects/${project}`, |
| 23 | body: { options: { requestedPolicyVersion: 3 } }, |
| 24 | }); |
| 25 | const roles = (policy.bindings ?? []) |
| 26 | .filter((binding) => (binding.members ?? []).includes(`serviceAccount:${hostAccount}`)) |
| 27 | .map((binding) => ({ role: binding.role, condition: binding.condition })); |
| 28 | expect(roles).toEqual([{ role: "roles/retail.viewer", condition: undefined }]); |
| 29 | }); |
| 30 | |
| 31 | describe.skipIf(!retailEnabled)( |
| 32 | "Retail Bindings", |
| 33 | { |
| 34 | tags: ["provider:gcp", "provider:gcp:retail", "provider:gcp:run", "live"], |
| 35 | }, |
| 36 | () => { |
| 37 | beforeAll( |
| 38 | Effect.gen(function* () { |
| 39 | yield* sharedStack.destroy(); |
| 40 | const out = yield* sharedStack.deploy( |
| 41 | Effect.gen(function* () { |
| 42 | const host = yield* RetailBindingsHost; |
| 43 | const serving = yield* Serving; |
| 44 | yield* Shirt; |
| 45 | return { |
| 46 | uri: host.uri, |
| 47 | serviceAccount: host.serviceAccount, |
| 48 | project: serving.project, |
| 49 | }; |
| 50 | }), |
| 51 | ); |
| 52 | baseUrl = out.uri!; |
| 53 | hostAccount = out.serviceAccount!; |
| 54 | project = out.project; |
| 55 | }), |
| 56 | { timeout: 900_000 }, |
| 57 | ); |
| 58 | |
| 59 | afterAll(sharedStack.destroy(), { timeout: 600_000 }); |
| 60 | |
| 61 | describe("Search", () => { |
| 62 | test.provider( |
| 63 | "searches the catalog as the host's service account", |
| 64 | (_stack) => |
| 65 | Effect.gen(function* () { |
| 66 | const searched = yield* expectProbe<retail.GoogleCloudRetailV2SearchResponse>( |
| 67 | baseUrl, |
| 68 | "search", |
| 69 | ); |
| 70 | expect(searched.attributionToken).toEqual(expect.any(String)); |
| 71 | yield* expectProjectGrants; |
| 72 | }), |
| 73 | { |
| 74 | tags: ["provider:gcp", "provider:gcp:retail", "live"], |
| 75 | timeout: 600_000, |
| 76 | }, |
| 77 | ); |
| 78 | }); |
| 79 | |
| 80 | describe("Predict", () => { |
| 81 | test.provider( |
| 82 | "validates a prediction request as the host's service account", |
| 83 | (_stack) => |
| 84 | Effect.gen(function* () { |
| 85 | const predicted = yield* expectProbe<retail.GoogleCloudRetailV2PredictResponse>( |
| 86 | baseUrl, |
| 87 | "predict", |
| 88 | ); |
| 89 | expect(predicted.validateOnly).toEqual(true); |
| 90 | yield* expectProjectGrants; |
| 91 | }), |
| 92 | { |
| 93 | tags: ["provider:gcp", "provider:gcp:retail", "live"], |
| 94 | timeout: 600_000, |
| 95 | }, |
| 96 | ); |
| 97 | }); |
| 98 | }, |
| 99 | ); |