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

main
ts 114 lines 3.69 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 compute from "@distilled.cloud/gcp/compute_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 waitUntilGone = (projectId: string, rolloutPlan: string) =>
15 compute.getRolloutPlans({ project: projectId, rolloutPlan }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 const wave = (locations: string[]): compute.RolloutPlanWave => ({
26 displayName: "central",
27 selectors: [
28 {
29 locationSelector: {
30 includedLocations: locations,
31 },
32 },
33 ],
34 validation: {
35 type: "time",
36 timeBasedValidationMetadata: { waitDuration: "0s" },
37 },
38 });
39
40 test.provider(
41 "getRolloutPlans on a missing plan fails with NotFound",
42 (stack) =>
43 Effect.gen(function* () {
44 const { project } = yield* GcpEnvironment.current;
45 yield* stack.destroy();
46
47 const error = yield* Effect.flip(
48 compute.getRolloutPlans({
49 project,
50 rolloutPlan: "alchemy-missing-rollout-plan",
51 }),
52 );
53 expect(error._tag).toBe("NotFound");
54
55 yield* stack.destroy();
56 }).pipe(logLevel),
57 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
58 );
59
60 test.provider(
61 "create, replace, and delete a rollout plan",
62 (stack) =>
63 Effect.gen(function* () {
64 yield* stack.destroy();
65
66 const created = yield* stack.deploy(
67 Effect.gen(function* () {
68 return yield* GCP.Compute.RolloutPlan("Fleet", {
69 description: "ops-agent canary",
70 locationScope: "ZONAL",
71 waves: [wave(["us-central1-a"])],
72 });
73 }),
74 );
75
76 expect(created.rolloutPlanName).toEqual(expect.any(String));
77 expect(created.locationScope).toEqual("ZONAL");
78 expect(created.description).toEqual("ops-agent canary");
79 expect(created.waves.length).toBeGreaterThan(0);
80
81 const fetched = yield* compute.getRolloutPlans({
82 project: created.project,
83 rolloutPlan: created.rolloutPlanName,
84 });
85 expect(fetched.name).toEqual(created.rolloutPlanName);
86 expect(fetched.description).toContain("[alchemy ");
87 expect(fetched.description).toContain("ops-agent canary");
88
89 const updated = yield* stack.deploy(
90 Effect.gen(function* () {
91 return yield* GCP.Compute.RolloutPlan("Fleet", {
92 rolloutPlanName: created.rolloutPlanName,
93 description: "ops-agent rollout",
94 locationScope: "ZONAL",
95 waves: [wave(["us-central1-a", "us-central1-b"])],
96 });
97 }),
98 );
99
100 expect(updated.rolloutPlanName).toEqual(created.rolloutPlanName);
101 expect(updated.description).toEqual("ops-agent rollout");
102
103 const fetchedUpdated = yield* compute.getRolloutPlans({
104 project: updated.project,
105 rolloutPlan: updated.rolloutPlanName,
106 });
107 expect(fetchedUpdated.description).toContain("ops-agent rollout");
108
109 yield* stack.destroy();
110 const gone = yield* waitUntilGone(created.project, created.rolloutPlanName);
111 expect(gone).toEqual("gone");
112 }).pipe(logLevel),
113 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
114 );