@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 132 lines 4.48 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 region = "us-central1";
15
16 const waitUntilGone = (project: string, instantSnapshotGroup: string) =>
17 compute
18 .getRegionInstantSnapshotGroups({
19 project,
20 region,
21 instantSnapshotGroup,
22 })
23 .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 "insertRegionInstantSnapshotGroups with a malformed consistency group fails with BadRequest",
35 () =>
36 Effect.gen(function* () {
37 const { project } = yield* GcpEnvironment.current;
38 const error = yield* Effect.flip(
39 compute.insertRegionInstantSnapshotGroups({
40 project,
41 region,
42 sourceConsistencyGroup: "does-not-exist",
43 body: {
44 name: "alchemy-risg-probe",
45 description: "alchemy entitlement probe",
46 sourceConsistencyGroup: "does-not-exist",
47 },
48 }),
49 );
50 expect(error._tag).toEqual("BadRequest");
51 }).pipe(logLevel),
52 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 60_000 },
53 );
54
55 test.provider(
56 "create and delete a regional instant snapshot group",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 const policy = yield* GCP.Compute.ResourcePolicy("Consistent", {
64 region,
65 diskConsistencyGroupPolicy: {},
66 });
67 const disk = yield* GCP.Compute.RegionDisk("Member", {
68 region,
69 replicaZones: ["us-central1-a", "us-central1-b"],
70 type: "hyperdisk-balanced-high-availability",
71 sizeGb: 4,
72 });
73 return { policy, disk };
74 }),
75 );
76
77 yield* compute.addResourcePoliciesRegionDisks({
78 project: created.disk.project,
79 region,
80 disk: created.disk.diskName,
81 body: {
82 resourcePolicies: [
83 created.policy.selfLink ??
84 `projects/${created.disk.project}/regions/${region}/resourcePolicies/${created.policy.resourcePolicyName}`,
85 ],
86 },
87 });
88
89 const withGroup = yield* stack.deploy(
90 Effect.gen(function* () {
91 const policy = yield* GCP.Compute.ResourcePolicy("Consistent", {
92 resourcePolicyName: created.policy.resourcePolicyName,
93 region,
94 diskConsistencyGroupPolicy: {},
95 });
96 const disk = yield* GCP.Compute.RegionDisk("Member", {
97 diskName: created.disk.diskName,
98 region,
99 replicaZones: ["us-central1-a", "us-central1-b"],
100 type: "hyperdisk-balanced-high-availability",
101 sizeGb: 4,
102 });
103 const group = yield* GCP.Compute.RegionInstantSnapshotGroup("Checkpoint", {
104 region,
105 sourceConsistencyGroup: policy.selfLink.as<string>(),
106 description: "group checkpoint",
107 });
108 return { policy, disk, group };
109 }),
110 );
111
112 expect(withGroup.group.instantSnapshotGroupName).toEqual(expect.any(String));
113 expect(withGroup.group.region).toEqual(region);
114 expect(withGroup.group.description).toEqual("group checkpoint");
115
116 const fetched = yield* compute.getRegionInstantSnapshotGroups({
117 project: withGroup.group.project,
118 region,
119 instantSnapshotGroup: withGroup.group.instantSnapshotGroupName,
120 });
121 expect(fetched.name).toEqual(withGroup.group.instantSnapshotGroupName);
122 expect(fetched.description).toContain("[alchemy ");
123
124 yield* stack.destroy();
125 const gone = yield* waitUntilGone(
126 withGroup.group.project,
127 withGroup.group.instantSnapshotGroupName,
128 );
129 expect(gone).toEqual("gone");
130 }).pipe(logLevel),
131 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 120_000 },
132 );