@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 131 lines 4.33 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 waitUntilGone = (project: string, zoneName: string, instantSnapshotGroup: string) =>
17 compute
18 .getInstantSnapshotGroups({
19 project,
20 zone: zoneName,
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 "insertInstantSnapshotGroups 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.insertInstantSnapshotGroups({
40 project,
41 zone,
42 sourceConsistencyGroup: "does-not-exist",
43 body: {
44 name: "alchemy-isg-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 an 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: "us-central1",
65 diskConsistencyGroupPolicy: {},
66 });
67 const disk = yield* GCP.Compute.Disk("Member", {
68 zone,
69 type: "hyperdisk-balanced",
70 sizeGb: 4,
71 });
72 return { policy, disk };
73 }),
74 );
75
76 yield* compute.addResourcePoliciesDisks({
77 project: created.disk.project,
78 zone,
79 disk: created.disk.diskName,
80 body: {
81 resourcePolicies: [
82 created.policy.selfLink ??
83 `projects/${created.disk.project}/regions/us-central1/resourcePolicies/${created.policy.resourcePolicyName}`,
84 ],
85 },
86 });
87
88 const withGroup = yield* stack.deploy(
89 Effect.gen(function* () {
90 const policy = yield* GCP.Compute.ResourcePolicy("Consistent", {
91 resourcePolicyName: created.policy.resourcePolicyName,
92 region: "us-central1",
93 diskConsistencyGroupPolicy: {},
94 });
95 const disk = yield* GCP.Compute.Disk("Member", {
96 diskName: created.disk.diskName,
97 zone,
98 type: "hyperdisk-balanced",
99 sizeGb: 4,
100 });
101 const group = yield* GCP.Compute.InstantSnapshotGroup("Checkpoint", {
102 zone,
103 sourceConsistencyGroup: policy.selfLink.as<string>(),
104 description: "group checkpoint",
105 });
106 return { policy, disk, group };
107 }),
108 );
109
110 expect(withGroup.group.instantSnapshotGroupName).toEqual(expect.any(String));
111 expect(withGroup.group.zone).toEqual(zone);
112 expect(withGroup.group.description).toEqual("group checkpoint");
113
114 const fetched = yield* compute.getInstantSnapshotGroups({
115 project: withGroup.group.project,
116 zone,
117 instantSnapshotGroup: withGroup.group.instantSnapshotGroupName,
118 });
119 expect(fetched.name).toEqual(withGroup.group.instantSnapshotGroupName);
120 expect(fetched.description).toContain("[alchemy ");
121
122 yield* stack.destroy();
123 const gone = yield* waitUntilGone(
124 withGroup.group.project,
125 zone,
126 withGroup.group.instantSnapshotGroupName,
127 );
128 expect(gone).toEqual("gone");
129 }).pipe(logLevel),
130 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 120_000 },
131 );