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

main
ts 79 lines 2.54 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 kms from "@distilled.cloud/gcp/cloudkms_v1";
6 import * as Effect from "effect/Effect";
7 import { expectProbe } from "../bindingHost.ts";
8 import KmsBindingsHost, { Cipher } from "./fixtures/bindings-host.ts";
9
10 const testOptions = { providers: GCP.providers() };
11 const { test, beforeAll, afterAll } = Test.make(testOptions);
12 const sharedStack = Core.scratchStack(testOptions, "KmsBindings");
13
14 let baseUrl: string;
15 let keyName: string;
16 let hostAccount: string;
17
18 describe(
19 "KMS Bindings",
20 { tags: ["provider:gcp", "provider:gcp:kms", "provider:gcp:run", "live"] },
21 () => {
22 beforeAll(
23 Effect.gen(function* () {
24 yield* sharedStack.destroy();
25 const out = yield* sharedStack.deploy(
26 Effect.gen(function* () {
27 const host = yield* KmsBindingsHost;
28 const key = yield* Cipher;
29 return {
30 uri: host.uri,
31 serviceAccount: host.serviceAccount,
32 key: key.name,
33 };
34 }),
35 );
36 baseUrl = out.uri!;
37 keyName = out.key;
38 hostAccount = out.serviceAccount!;
39 }),
40 { timeout: 900_000 },
41 );
42
43 afterAll(sharedStack.destroy(), { timeout: 600_000 });
44
45 describe("Encrypt / Decrypt", () => {
46 test.provider(
47 "round-trip as the host's service account, granted on the key only",
48 (_stack) =>
49 Effect.gen(function* () {
50 const out = yield* expectProbe<{
51 plaintext: string;
52 ciphertext: string;
53 decrypted: string;
54 }>(baseUrl, "roundTrip");
55 expect(out.ciphertext).not.toEqual(out.plaintext);
56 expect(out.decrypted).toEqual(out.plaintext);
57
58 const policy = yield* kms.getIamPolicyProjectsLocationsKeyRingsCryptoKeys({
59 resource: keyName,
60 });
61 const roles = (policy.bindings ?? [])
62 .filter((binding) =>
63 (binding.members ?? []).includes(`serviceAccount:${hostAccount}`),
64 )
65 .map((binding) => binding.role)
66 .sort();
67 expect(roles).toEqual([
68 "roles/cloudkms.cryptoKeyDecrypter",
69 "roles/cloudkms.cryptoKeyEncrypter",
70 ]);
71 }),
72 {
73 tags: ["provider:gcp", "provider:gcp:kms", "live"],
74 timeout: 600_000,
75 },
76 );
77 });
78 },
79 );