@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 144 lines 5.35 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 composer from "@distilled.cloud/gcp/composer_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { CAPACITY_REGION } from "../zones.ts";
10 import { defaultComputeServiceAccount } from "./serviceAccount.ts";
11
12 const { test } = Test.make({ providers: GCP.providers() });
13
14 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
15
16 // Composer environments take 20-45 minutes to provision.
17 const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST;
18
19 const missingParentOf = (project: string) =>
20 `projects/${project}/locations/${CAPACITY_REGION}/environments/alchemy-composer-missing`;
21
22 const waitUntilGone = (name: string) =>
23 composer.getProjectsLocationsEnvironmentsUserWorkloadsConfigMaps({ name }).pipe(
24 Effect.as("found" as const),
25 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
26 Effect.repeat({
27 schedule: Schedule.spaced("1 second"),
28 until: (status) => status === "gone",
29 times: 10,
30 }),
31 );
32
33 test.provider(
34 "getProjectsLocationsEnvironmentsUserWorkloadsConfigMaps on a missing config map fails with NotFound",
35 (stack) =>
36 Effect.gen(function* () {
37 const { project } = yield* GcpEnvironment.current;
38 const missingParent = missingParentOf(project);
39 yield* stack.destroy();
40
41 const error = yield* Effect.flip(
42 composer.getProjectsLocationsEnvironmentsUserWorkloadsConfigMaps({
43 name: `${missingParent}/userWorkloadsConfigMaps/alchemy-missing`,
44 }),
45 );
46 expect(error._tag).toEqual("NotFound");
47
48 const created = yield* Effect.flip(
49 composer.createProjectsLocationsEnvironmentsUserWorkloadsConfigMaps({
50 parent: missingParent,
51 body: {
52 name: `${missingParent}/userWorkloadsConfigMaps/alchemy-missing`,
53 data: { LOG_LEVEL: "INFO" },
54 },
55 }),
56 );
57 expect(created._tag).toEqual("NotFound");
58
59 yield* stack.destroy();
60 }).pipe(logLevel),
61 { tags: ["provider:gcp", "provider:gcp:composer", "live"], timeout: 90_000 },
62 );
63
64 test.provider.skipIf(!runLifecycle)(
65 "create, update, and delete a user workloads config map",
66 (stack) =>
67 Effect.gen(function* () {
68 const serviceAccount = yield* defaultComputeServiceAccount;
69 yield* stack.destroy();
70
71 const created = yield* stack.deploy(
72 Effect.gen(function* () {
73 const airflow = yield* GCP.Composer.Environment("Airflow", {
74 location: CAPACITY_REGION,
75 config: {
76 environmentSize: "ENVIRONMENT_SIZE_SMALL",
77 nodeConfig: { serviceAccount },
78 softwareConfig: { imageVersion: "composer-3-airflow-2" },
79 },
80 });
81 const config = yield* GCP.Composer.EnvironmentsUserWorkloadsConfigMap("TaskConfig", {
82 environmentName: airflow.name,
83 data: { LOG_LEVEL: "INFO" },
84 });
85 return { airflow, config };
86 }),
87 );
88
89 expect(created.config.name).toContain("/userWorkloadsConfigMaps/");
90 expect(created.config.environmentName).toEqual(created.airflow.name);
91 expect(created.config.data).toMatchObject({ LOG_LEVEL: "INFO" });
92 expect(created.config.data["alchemy-id"]).toBeUndefined();
93
94 const fetched = yield* composer.getProjectsLocationsEnvironmentsUserWorkloadsConfigMaps({
95 name: created.config.name,
96 });
97 expect(fetched.name).toEqual(created.config.name);
98 expect(fetched.data?.LOG_LEVEL).toEqual("INFO");
99 expect(fetched.data?.["alchemy-id"]).toBeUndefined();
100
101 const updated = yield* stack.deploy(
102 Effect.gen(function* () {
103 const airflow = yield* GCP.Composer.Environment("Airflow", {
104 environmentId: created.airflow.environmentId,
105 location: CAPACITY_REGION,
106 config: {
107 environmentSize: "ENVIRONMENT_SIZE_SMALL",
108 nodeConfig: { serviceAccount },
109 softwareConfig: { imageVersion: "composer-3-airflow-2" },
110 },
111 });
112 const config = yield* GCP.Composer.EnvironmentsUserWorkloadsConfigMap("TaskConfig", {
113 environmentName: airflow.name,
114 configMapId: created.config.configMapId,
115 data: { LOG_LEVEL: "DEBUG", REGION: "us-central1" },
116 });
117 return { airflow, config };
118 }),
119 );
120
121 expect(updated.config.name).toEqual(created.config.name);
122 expect(updated.config.data).toMatchObject({
123 LOG_LEVEL: "DEBUG",
124 REGION: "us-central1",
125 });
126
127 const refetched = yield* composer.getProjectsLocationsEnvironmentsUserWorkloadsConfigMaps({
128 name: created.config.name,
129 });
130 expect(refetched.data?.LOG_LEVEL).toEqual("DEBUG");
131 expect(refetched.data?.REGION).toEqual("us-central1");
132
133 yield* stack.destroy();
134
135 const gone = yield* waitUntilGone(created.config.name);
136 expect(gone).toEqual("gone");
137 }).pipe(logLevel),
138 // Create (~45 min) + update + delete; a timed-out lifecycle is not retried.
139 {
140 tags: ["provider:gcp", "provider:gcp:composer", "live"],
141 timeout: 5_400_000,
142 retry: 0,
143 },
144 );