@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 81 lines 2.75 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 cloudtasks from "@distilled.cloud/gcp/cloudtasks_v2";
6 import * as Effect from "effect/Effect";
7 import { expectProbe } from "../bindingHost.ts";
8 import CloudTasksBindingsHost, { Jobs, TASK_URL } 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, "CloudTasksBindings");
13
14 let baseUrl: string;
15 let queueName: string;
16 let hostAccount: string;
17
18 describe(
19 "CloudTasks Bindings",
20 {
21 tags: ["provider:gcp", "provider:gcp:cloudtasks", "provider:gcp:run", "live"],
22 },
23 () => {
24 beforeAll(
25 Effect.gen(function* () {
26 yield* sharedStack.destroy();
27 const out = yield* sharedStack.deploy(
28 Effect.gen(function* () {
29 const host = yield* CloudTasksBindingsHost;
30 const queue = yield* Jobs;
31 return {
32 uri: host.uri,
33 serviceAccount: host.serviceAccount,
34 queue: queue.name,
35 };
36 }),
37 );
38 baseUrl = out.uri!;
39 queueName = out.queue;
40 hostAccount = out.serviceAccount!;
41 }),
42 { timeout: 900_000 },
43 );
44
45 afterAll(sharedStack.destroy(), { timeout: 600_000 });
46
47 describe("CreateTask", () => {
48 test.provider(
49 "enqueues a task as the host's service account, granted on the queue only",
50 (_stack) =>
51 Effect.gen(function* () {
52 const task = yield* expectProbe<cloudtasks.Task>(baseUrl, "createTask");
53 expect(task.name?.startsWith(`${queueName}/tasks/`)).toBe(true);
54 expect(task.httpRequest?.url).toEqual(TASK_URL);
55
56 const live = yield* cloudtasks.getProjectsLocationsQueuesTasks({
57 name: task.name!,
58 });
59 expect(live.name).toEqual(task.name);
60 expect(live.httpRequest?.url).toEqual(TASK_URL);
61 expect(live.httpRequest?.httpMethod).toEqual("POST");
62
63 const policy = yield* cloudtasks.getIamPolicyProjectsLocationsQueues({
64 resource: queueName,
65 });
66 const roles = (policy.bindings ?? [])
67 .filter((binding) =>
68 (binding.members ?? []).includes(`serviceAccount:${hostAccount}`),
69 )
70 .map((binding) => binding.role)
71 .sort();
72 expect(roles).toEqual(["roles/cloudtasks.enqueuer"]);
73 }),
74 {
75 tags: ["provider:gcp", "provider:gcp:cloudtasks", "live"],
76 timeout: 600_000,
77 },
78 );
79 });
80 },
81 );