@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 82 lines 2.83 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 crm from "@distilled.cloud/gcp/cloudresourcemanager_v3";
6 import type * as memcache from "@distilled.cloud/gcp/memcache_v1";
7 import * as Effect from "effect/Effect";
8 import { expectProbe } from "../bindingHost.ts";
9 import MemcacheBindingsHost, { Cache, memcacheEnabled } 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, "MemcacheBindings");
14
15 let baseUrl: string;
16 let hostAccount: string;
17 let project: string;
18 let instanceName: string;
19
20 describe.skipIf(!memcacheEnabled)(
21 "Memcache Bindings",
22 {
23 tags: ["provider:gcp", "provider:gcp:memcache", "provider:gcp:run", "live"],
24 },
25 () => {
26 beforeAll(
27 Effect.gen(function* () {
28 yield* sharedStack.destroy();
29 const out = yield* sharedStack.deploy(
30 Effect.gen(function* () {
31 const host = yield* MemcacheBindingsHost;
32 const cache = yield* Cache;
33 return {
34 uri: host.uri,
35 serviceAccount: host.serviceAccount,
36 name: cache.name,
37 project: cache.project,
38 };
39 }),
40 );
41 baseUrl = out.uri!;
42 hostAccount = out.serviceAccount!;
43 instanceName = out.name;
44 project = out.project;
45 }),
46 { timeout: 1_800_000 },
47 );
48
49 afterAll(sharedStack.destroy(), { timeout: 1_200_000 });
50
51 describe("GetInstance", () => {
52 test.provider(
53 "reads the instance as the host's service account, granted memcache.viewer on the project",
54 (_stack) =>
55 Effect.gen(function* () {
56 const live = yield* expectProbe<memcache.Instance>(baseUrl, "getInstance");
57 expect(live.name).toEqual(instanceName);
58 expect(live.state).toEqual("READY");
59
60 // Memcache instances have no IAM policy of their own.
61 const policy = yield* crm.getIamPolicyProjects({
62 resource: `projects/${project}`,
63 body: { options: { requestedPolicyVersion: 3 } },
64 });
65 const roles = (policy.bindings ?? [])
66 .filter((binding) =>
67 (binding.members ?? []).includes(`serviceAccount:${hostAccount}`),
68 )
69 .map((binding) => ({
70 role: binding.role,
71 condition: binding.condition,
72 }));
73 expect(roles).toEqual([{ role: "roles/memcache.viewer", condition: undefined }]);
74 }),
75 {
76 tags: ["provider:gcp", "provider:gcp:memcache", "live"],
77 timeout: 600_000,
78 },
79 );
80 });
81 },
82 );