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