@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 157 lines 5.94 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 netapp from "@distilled.cloud/gcp/netapp_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 // Pool + volume provisioning is multi-minute; skip unless explicitly enabled.
15 // Volumes need a Private Service Access connection to
16 // `netapp.servicenetworking.goog` on the `default` network (otherwise volume
17 // create fails with `Please create Service Networking connection with
18 // service 'netapp.servicenetworking.goog' ...`), and each file provisions its
19 // own 2 TiB STANDARD pool while the default regional quota
20 // (StandardStoragePoolCapacityGiBPerRegion = 2048) fits one. Set
21 // GCP_TEST_NETAPP_VOLUMES=1 on a project with both.
22 const runLifecycle = !!process.env.GCP_TEST_NETAPP_VOLUMES && !process.env.FAST;
23
24 const waitUntilGone = (name: string) =>
25 netapp.getProjectsLocationsVolumesSnapshots({ name }).pipe(
26 Effect.as("found" as const),
27 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
28 Effect.repeat({
29 schedule: Schedule.spaced("2 seconds"),
30 until: (status) => status === "gone",
31 times: 10,
32 }),
33 );
34
35 test.provider(
36 "getProjectsLocationsVolumesSnapshots on a missing snapshot fails with a typed tag",
37 (stack) =>
38 Effect.gen(function* () {
39 const { project } = yield* GcpEnvironment.current;
40
41 yield* stack.destroy();
42
43 const error = yield* Effect.flip(
44 netapp.getProjectsLocationsVolumesSnapshots({
45 name: `projects/${project}/locations/us-central1/volumes/alchemy-netapp-missing/snapshots/alchemy-snap-missing`,
46 }),
47 );
48 expect(error._tag).toEqual("NotFound");
49
50 const page = yield* netapp.listProjectsLocationsVolumesSnapshots({
51 parent: `projects/${project}/locations/us-central1/volumes/-`,
52 pageSize: 10,
53 });
54 expect((page.snapshots ?? []).map((item) => item.name)).not.toContain(
55 `projects/${project}/locations/us-central1/volumes/alchemy-netapp-missing/snapshots/alchemy-snap-missing`,
56 );
57
58 yield* stack.destroy();
59 }).pipe(logLevel),
60 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 90_000 },
61 );
62
63 test.provider.skipIf(!runLifecycle)(
64 "create, update, and delete a volume snapshot",
65 (stack) =>
66 Effect.gen(function* () {
67 yield* stack.destroy();
68
69 const created = yield* stack.deploy(
70 Effect.gen(function* () {
71 const pool = yield* GCP.NetApp.StoragePool("Pool", {
72 location: "us-central1",
73 network: "default",
74 serviceLevel: "STANDARD",
75 capacityGib: 2048,
76 labels: { env: "test" },
77 });
78 const volume = yield* GCP.NetApp.Volume("Share", {
79 location: "us-central1",
80 storagePool: pool.name,
81 protocols: ["NFSV3"],
82 capacityGib: 100,
83 shareName: "alchsnap",
84 labels: { env: "test" },
85 });
86 const snapshot = yield* GCP.NetApp.VolumesSnapshot("Nightly", {
87 volume: volume.name,
88 description: "alchemy-test-snap",
89 labels: { env: "test" },
90 });
91 return { pool, volume, snapshot };
92 }),
93 );
94
95 expect(created.snapshot.name).toContain("/snapshots/");
96 expect(created.snapshot.snapshotId).toEqual(expect.any(String));
97 expect(created.snapshot.volume).toEqual(created.volume.name);
98 expect(created.snapshot.description).toEqual("alchemy-test-snap");
99 expect(created.snapshot.labels).toMatchObject({ env: "test" });
100
101 const fetched = yield* netapp.getProjectsLocationsVolumesSnapshots({
102 name: created.snapshot.name,
103 });
104 expect(fetched.name).toEqual(created.snapshot.name);
105 expect(fetched.description).toEqual("alchemy-test-snap");
106 expect(fetched.labels?.env).toEqual("test");
107
108 const updated = yield* stack.deploy(
109 Effect.gen(function* () {
110 const pool = yield* GCP.NetApp.StoragePool("Pool", {
111 storagePoolId: created.pool.storagePoolId,
112 location: "us-central1",
113 network: "default",
114 serviceLevel: "STANDARD",
115 capacityGib: 2048,
116 labels: { env: "test" },
117 });
118 const volume = yield* GCP.NetApp.Volume("Share", {
119 volumeId: created.volume.volumeId,
120 location: "us-central1",
121 storagePool: pool.name,
122 protocols: ["NFSV3"],
123 capacityGib: 100,
124 shareName: "alchsnap",
125 labels: { env: "test" },
126 });
127 const snapshot = yield* GCP.NetApp.VolumesSnapshot("Nightly", {
128 volume: volume.name,
129 snapshotId: created.snapshot.snapshotId,
130 description: "alchemy-prod-snap",
131 labels: { env: "prod", role: "backup" },
132 });
133 return { pool, volume, snapshot };
134 }),
135 );
136
137 expect(updated.snapshot.name).toEqual(created.snapshot.name);
138 expect(updated.snapshot.description).toEqual("alchemy-prod-snap");
139 expect(updated.snapshot.labels).toMatchObject({
140 env: "prod",
141 role: "backup",
142 });
143
144 const refetched = yield* netapp.getProjectsLocationsVolumesSnapshots({
145 name: created.snapshot.name,
146 });
147 expect(refetched.description).toEqual("alchemy-prod-snap");
148 expect(refetched.labels?.env).toEqual("prod");
149 expect(refetched.labels?.role).toEqual("backup");
150
151 yield* stack.destroy();
152
153 const gone = yield* waitUntilGone(created.snapshot.name);
154 expect(gone).toEqual("gone");
155 }).pipe(logLevel),
156 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 900_000 },
157 );