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

main
ts 106 lines 4.12 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as compute from "@distilled.cloud/gcp/compute_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (project: string, region: string, resourcePolicy: string) =>
14 compute.getResourcePolicies({ project, region, resourcePolicy }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 test.provider(
25 "create, update, and delete a resource policy",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const created = yield* stack.deploy(
31 Effect.gen(function* () {
32 return yield* GCP.Compute.ResourcePolicy("Nightly", {
33 region: "us-central1",
34 description: "nightly snapshots",
35 snapshotSchedulePolicy: {
36 schedule: {
37 dailySchedule: { daysInCycle: 1, startTime: "04:00" },
38 },
39 retentionPolicy: { maxRetentionDays: 7 },
40 },
41 });
42 }),
43 );
44
45 expect(created.resourcePolicyName).toEqual(expect.any(String));
46 expect(created.region).toEqual("us-central1");
47 expect(created.status).toEqual("READY");
48 expect(created.description).toEqual("nightly snapshots");
49 expect(created.snapshotSchedulePolicy?.schedule?.dailySchedule?.startTime).toEqual("04:00");
50 expect(created.snapshotSchedulePolicy?.retentionPolicy?.maxRetentionDays).toEqual(7);
51
52 const fetched = yield* compute.getResourcePolicies({
53 project: created.project,
54 region: created.region,
55 resourcePolicy: created.resourcePolicyName,
56 });
57 expect(fetched.name).toEqual(created.resourcePolicyName);
58 expect(fetched.status).toEqual("READY");
59 expect(fetched.description).toContain("[alchemy ");
60 expect(fetched.description).toContain("nightly snapshots");
61 expect(fetched.snapshotSchedulePolicy?.schedule?.dailySchedule?.daysInCycle).toEqual(1);
62 expect(fetched.snapshotSchedulePolicy?.retentionPolicy?.maxRetentionDays).toEqual(7);
63
64 const updated = yield* stack.deploy(
65 Effect.gen(function* () {
66 return yield* GCP.Compute.ResourcePolicy("Nightly", {
67 resourcePolicyName: created.resourcePolicyName,
68 region: "us-central1",
69 description: "daily snapshots",
70 snapshotSchedulePolicy: {
71 schedule: {
72 dailySchedule: { daysInCycle: 1, startTime: "08:00" },
73 },
74 retentionPolicy: { maxRetentionDays: 14 },
75 },
76 });
77 }),
78 );
79
80 expect(updated.resourcePolicyName).toEqual(created.resourcePolicyName);
81 expect(updated.description).toEqual("daily snapshots");
82 expect(updated.snapshotSchedulePolicy?.schedule?.dailySchedule?.startTime).toEqual("08:00");
83 expect(updated.snapshotSchedulePolicy?.retentionPolicy?.maxRetentionDays).toEqual(14);
84
85 const fetchedUpdated = yield* compute.getResourcePolicies({
86 project: updated.project,
87 region: updated.region,
88 resourcePolicy: updated.resourcePolicyName,
89 });
90 expect(fetchedUpdated.description).toContain("daily snapshots");
91 expect(fetchedUpdated.snapshotSchedulePolicy?.schedule?.dailySchedule?.startTime).toEqual(
92 "08:00",
93 );
94 expect(fetchedUpdated.snapshotSchedulePolicy?.retentionPolicy?.maxRetentionDays).toEqual(14);
95
96 yield* stack.destroy();
97
98 const gone = yield* waitUntilGone(
99 created.project,
100 created.region,
101 created.resourcePolicyName,
102 );
103 expect(gone).toEqual("gone");
104 }).pipe(logLevel),
105 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
106 );