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

main
ts 124 lines 4.11 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 zone = "us-central1-a";
15
16 const runLifecycle = !process.env.FAST;
17
18 const waitUntilGone = (projectId: string, reservationZone: string, reservation: string) =>
19 compute
20 .getReservations({
21 project: projectId,
22 zone: reservationZone,
23 reservation,
24 })
25 .pipe(
26 Effect.as("found" as const),
27 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
28 Effect.repeat({
29 schedule: Schedule.spaced("1 second"),
30 until: (status) => status === "gone",
31 times: 10,
32 }),
33 );
34
35 test.provider(
36 "getReservations on a missing reservation fails with NotFound",
37 (stack) =>
38 Effect.gen(function* () {
39 const { project } = yield* GcpEnvironment.current;
40 yield* stack.destroy();
41
42 const error = yield* Effect.flip(
43 compute.getReservations({
44 project,
45 zone,
46 reservation: "alchemy-missing-reservation",
47 }),
48 );
49 expect(error._tag).toBe("NotFound");
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 300_000 },
54 );
55
56 test.provider.skipIf(!runLifecycle)(
57 "create, update, and delete a reservation",
58 (stack) =>
59 Effect.gen(function* () {
60 yield* stack.destroy();
61
62 const created = yield* stack.deploy(
63 Effect.gen(function* () {
64 return yield* GCP.Compute.Reservation("Burst", {
65 zone,
66 description: "burst capacity",
67 specificReservation: {
68 count: 1,
69 instanceProperties: { machineType: "n1-standard-1" },
70 },
71 specificReservationRequired: true,
72 });
73 }),
74 );
75
76 expect(created.reservationName).toEqual(expect.any(String));
77 expect(created.zone).toEqual(zone);
78 expect(created.status).toEqual("READY");
79 expect(created.description).toEqual("burst capacity");
80 expect(created.specificReservationRequired).toEqual(true);
81 expect(created.specificReservation?.count).toEqual("1");
82
83 const fetched = yield* compute.getReservations({
84 project: created.project,
85 zone: created.zone,
86 reservation: created.reservationName,
87 });
88 expect(fetched.name).toEqual(created.reservationName);
89 expect(fetched.status).toEqual("READY");
90 expect(fetched.description).toContain("[alchemy ");
91 expect(fetched.description).toContain("burst capacity");
92 expect(fetched.specificReservation?.count).toEqual("1");
93
94 const updated = yield* stack.deploy(
95 Effect.gen(function* () {
96 return yield* GCP.Compute.Reservation("Burst", {
97 reservationName: created.reservationName,
98 zone,
99 description: "burst capacity",
100 specificReservation: {
101 count: 2,
102 instanceProperties: { machineType: "n1-standard-1" },
103 },
104 specificReservationRequired: true,
105 });
106 }),
107 );
108
109 expect(updated.reservationName).toEqual(created.reservationName);
110 expect(updated.specificReservation?.count).toEqual("2");
111
112 const fetchedUpdated = yield* compute.getReservations({
113 project: updated.project,
114 zone: updated.zone,
115 reservation: updated.reservationName,
116 });
117 expect(fetchedUpdated.specificReservation?.count).toEqual("2");
118
119 yield* stack.destroy();
120 const gone = yield* waitUntilGone(created.project, created.zone, created.reservationName);
121 expect(gone).toEqual("gone");
122 }).pipe(logLevel),
123 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 300_000 },
124 );