@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 102 lines 3.67 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 * as workflowexecutions from "@distilled.cloud/gcp/workflowexecutions_v1";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9 import { expectProbe } from "../bindingHost.ts";
10 import WorkflowsBindingsHost, { Greet } 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, "WorkflowsBindings");
15
16 let baseUrl: string;
17 let hostAccount: string;
18 let project: string;
19 let workflowName: string;
20
21 describe(
22 "Workflows Bindings",
23 {
24 tags: ["provider:gcp", "provider:gcp:workflows", "provider:gcp:run", "live"],
25 },
26 () => {
27 beforeAll(
28 Effect.gen(function* () {
29 yield* sharedStack.destroy();
30 const out = yield* sharedStack.deploy(
31 Effect.gen(function* () {
32 const host = yield* WorkflowsBindingsHost;
33 const workflow = yield* Greet;
34 return {
35 uri: host.uri,
36 serviceAccount: host.serviceAccount,
37 name: workflow.name,
38 project: workflow.project,
39 };
40 }),
41 );
42 baseUrl = out.uri!;
43 hostAccount = out.serviceAccount!;
44 workflowName = out.name;
45 project = out.project;
46 }),
47 { timeout: 900_000 },
48 );
49
50 afterAll(sharedStack.destroy(), { timeout: 600_000 });
51
52 describe("CreateExecution", () => {
53 test.provider(
54 "starts a run as the host's service account, granted workflows.invoker on the project",
55 (_stack) =>
56 Effect.gen(function* () {
57 const started = yield* expectProbe<workflowexecutions.Execution>(
58 baseUrl,
59 "createExecution",
60 );
61 // Execution names carry the project number, not its id.
62 const workflowPath = workflowName.slice(workflowName.indexOf("/locations/"));
63 expect(started.name).toEqual(expect.stringContaining(`${workflowPath}/executions/`));
64
65 const finished = yield* workflowexecutions
66 .getProjectsLocationsWorkflowsExecutions({
67 name: started.name ?? "",
68 })
69 .pipe(
70 Effect.repeat({
71 schedule: Schedule.spaced("2 seconds"),
72 until: (execution) => execution.state !== "ACTIVE",
73 times: 30,
74 }),
75 );
76 expect(finished.state).toEqual("SUCCEEDED");
77 expect(finished.result).toEqual(JSON.stringify("hello alchemy"));
78
79 // Workflows has no per-workflow IAM policy: the binding grants
80 // roles/workflows.invoker on the project.
81 const policy = yield* crm.getIamPolicyProjects({
82 resource: `projects/${project}`,
83 body: { options: { requestedPolicyVersion: 3 } },
84 });
85 const roles = (policy.bindings ?? [])
86 .filter((binding) =>
87 (binding.members ?? []).includes(`serviceAccount:${hostAccount}`),
88 )
89 .map((binding) => ({
90 role: binding.role,
91 condition: binding.condition,
92 }));
93 expect(roles).toEqual([{ role: "roles/workflows.invoker", condition: undefined }]);
94 }),
95 {
96 tags: ["provider:gcp", "provider:gcp:workflows", "live"],
97 timeout: 600_000,
98 },
99 );
100 });
101 },
102 );