The best way to control Claude Code, Codex and more from any computer or phone

main
ts 97 lines 3.41 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 config from "@distilled.cloud/gcp/config_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const runLifecycle = !process.env.FAST;
15
16 const waitUntilGone = (name: string) =>
17 config.getProjectsLocationsDeploymentGroups({ name }).pipe(
18 Effect.as("found" as const),
19 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("2 seconds"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 );
26
27 test.provider(
28 "getProjectsLocationsDeploymentGroups on a missing group fails with a typed tag",
29 (stack) =>
30 Effect.gen(function* () {
31 const { project } = yield* GcpEnvironment.current;
32 yield* stack.destroy();
33
34 const error = yield* Effect.flip(
35 config.getProjectsLocationsDeploymentGroups({
36 name: `projects/${project}/locations/us-central1/deploymentGroups/alchemy-missing-group`,
37 }),
38 );
39 expect(error._tag).toEqual("NotFound");
40
41 yield* stack.destroy();
42 }).pipe(logLevel),
43 { tags: ["provider:gcp", "provider:gcp:config", "live"], timeout: 90_000 },
44 );
45
46 test.provider.skipIf(!runLifecycle)(
47 "create, update, and delete a deployment group",
48 (stack) =>
49 Effect.gen(function* () {
50 yield* stack.destroy();
51
52 const created = yield* stack.deploy(
53 Effect.gen(function* () {
54 return yield* GCP.Config.DeploymentGroup("App", {
55 deploymentUnits: [{ id: "network", dependencies: [] }],
56 labels: { env: "test" },
57 });
58 }),
59 );
60
61 expect(created.name).toContain("/deploymentGroups/");
62 expect(created.deploymentGroupId).toEqual(expect.any(String));
63 expect(created.location).toEqual("us-central1");
64 expect(created.deploymentUnits[0]?.id).toEqual("network");
65 expect(created.labels).toMatchObject({ env: "test" });
66
67 const fetched = yield* config.getProjectsLocationsDeploymentGroups({
68 name: created.name,
69 });
70 expect(fetched.name).toEqual(created.name);
71 expect(fetched.labels?.env).toEqual("test");
72 expect(fetched.deploymentUnits?.[0]?.id).toEqual("network");
73
74 const updated = yield* stack.deploy(
75 Effect.gen(function* () {
76 return yield* GCP.Config.DeploymentGroup("App", {
77 deploymentGroupId: created.deploymentGroupId,
78 deploymentUnits: [
79 { id: "network", dependencies: [] },
80 { id: "cluster", dependencies: ["network"] },
81 ],
82 labels: { env: "prod", role: "config" },
83 });
84 }),
85 );
86
87 expect(updated.name).toEqual(created.name);
88 expect(updated.deploymentUnits.map((unit) => unit.id)).toEqual(["network", "cluster"]);
89 expect(updated.labels).toMatchObject({ env: "prod", role: "config" });
90
91 yield* stack.destroy();
92
93 const gone = yield* waitUntilGone(created.name);
94 expect(gone).toEqual("gone");
95 }).pipe(logLevel),
96 { tags: ["provider:gcp", "provider:gcp:config", "live"], timeout: 90_000 },
97 );