@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 153 lines 5.29 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as workloadmanager from "@distilled.cloud/gcp/workloadmanager_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { isServiceEnabled } from "../ServiceState.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 const parentOf = (project: string) => `projects/${project}/locations/us-central1`;
16 const missingDeploymentOf = (project: string) =>
17 `${parentOf(project)}/deployments/alchemy-missing-deployment`;
18
19 // Workload Manager API is entitlement-gated on the default testing project
20 // (`ServiceDisabled`: "Workload Manager API has not been used in project
21 // <project> before or it is disabled."). Set
22 // GCP_TEST_WORKLOADMANAGER=1 on an entitled project to run the lifecycle.
23 const entitled = process.env.GCP_TEST_WORKLOADMANAGER === "1";
24 const runLifecycle = entitled && !process.env.FAST;
25
26 const waitUntilGone = (name: string) =>
27 workloadmanager.getProjectsLocationsDeploymentsActuations({ name }).pipe(
28 Effect.as("found" as const),
29 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
30 Effect.repeat({
31 schedule: Schedule.spaced("1 second"),
32 until: (status) => status === "gone",
33 times: 10,
34 }),
35 );
36
37 test.provider(
38 "getProjectsLocationsDeploymentsActuations on a missing actuation fails with a typed tag",
39 (stack) =>
40 Effect.gen(function* () {
41 const { project } = yield* GcpEnvironment.current;
42 const missingDeployment = missingDeploymentOf(project);
43 yield* stack.destroy();
44
45 const error = yield* Effect.flip(
46 workloadmanager.getProjectsLocationsDeploymentsActuations({
47 name: `${missingDeployment}/actuations/alchemy-missing-actuation`,
48 }),
49 );
50 expect(["ServiceDisabled", "NotFound"]).toContain(error._tag);
51
52 yield* stack.destroy();
53 }).pipe(logLevel),
54 {
55 tags: ["provider:gcp", "provider:gcp:workloadmanager", "live"],
56 timeout: 90_000,
57 },
58 );
59
60 test.provider.skipIf(entitled)(
61 "createProjectsLocationsDeploymentsActuations is rejected with ServiceDisabled while Workload Manager is disabled",
62 (stack) =>
63 Effect.gen(function* () {
64 // Only meaningful while the API is disabled: enabled, the create would
65 // provision a real resource.
66 if (yield* isServiceEnabled("workloadmanager.googleapis.com")) return;
67 const { project } = yield* GcpEnvironment.current;
68 const missingDeployment = missingDeploymentOf(project);
69 yield* stack.destroy();
70
71 const error = yield* Effect.flip(
72 workloadmanager.createProjectsLocationsDeploymentsActuations({
73 parent: missingDeployment,
74 body: {
75 name: `${missingDeployment}/actuations/alchemy-actuation-probe`,
76 },
77 }),
78 );
79 expect(error._tag).toEqual("ServiceDisabled");
80
81 yield* stack.destroy();
82 }).pipe(logLevel),
83 {
84 tags: ["provider:gcp", "provider:gcp:workloadmanager", "live"],
85 timeout: 90_000,
86 },
87 );
88
89 test.provider.skipIf(!runLifecycle)(
90 "create against a missing deployment is rejected with a typed tag",
91 (stack) =>
92 Effect.gen(function* () {
93 const { project } = yield* GcpEnvironment.current;
94 const missingDeployment = missingDeploymentOf(project);
95 yield* stack.destroy();
96
97 const error = yield* Effect.flip(
98 stack.deploy(
99 Effect.gen(function* () {
100 return yield* GCP.WorkloadManager.DeploymentsActuation("Bootstrap", {
101 deployment: missingDeployment,
102 });
103 }),
104 ),
105 );
106 expect(error._tag).toEqual("ServiceDisabled");
107
108 yield* stack.destroy();
109 }).pipe(logLevel),
110 {
111 tags: ["provider:gcp", "provider:gcp:workloadmanager", "live"],
112 timeout: 90_000,
113 },
114 );
115
116 test.provider.skipIf(!runLifecycle || !process.env.GCP_TEST_WORKLOADMANAGER_DEPLOYMENT)(
117 "create and delete an actuation under an entitled deployment",
118 (stack) =>
119 Effect.gen(function* () {
120 const { project } = yield* GcpEnvironment.current;
121 yield* stack.destroy();
122
123 const deploymentName = process.env.GCP_TEST_WORKLOADMANAGER_DEPLOYMENT;
124 expect(deploymentName).toEqual(expect.any(String));
125
126 const created = yield* stack.deploy(
127 Effect.gen(function* () {
128 return yield* GCP.WorkloadManager.DeploymentsActuation("Bootstrap", {
129 deployment: deploymentName!,
130 });
131 }),
132 );
133
134 expect(created.name).toContain("/actuations/");
135 expect(created.actuationId).toEqual(expect.any(String));
136 expect(created.deployment).toEqual(deploymentName);
137 expect(created.project).toEqual(project);
138
139 const fetched = yield* workloadmanager.getProjectsLocationsDeploymentsActuations({
140 name: created.name,
141 });
142 expect(fetched.name).toEqual(created.name);
143
144 yield* stack.destroy();
145
146 const gone = yield* waitUntilGone(created.name);
147 expect(gone).toEqual("gone");
148 }).pipe(logLevel),
149 {
150 tags: ["provider:gcp", "provider:gcp:workloadmanager", "live"],
151 timeout: 120_000,
152 },
153 );