@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 139 lines 4.59 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 const runLifecycle = !!process.env.GCP_TEST_STORAGE_POOL && !process.env.FAST;
16
17 const waitUntilGone = (projectId: string, poolZone: string, storagePool: string) =>
18 compute
19 .getStoragePools({
20 project: projectId,
21 zone: poolZone,
22 storagePool,
23 })
24 .pipe(
25 Effect.as("found" as const),
26 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
27 Effect.repeat({
28 schedule: Schedule.spaced("1 second"),
29 until: (status) => status === "gone",
30 times: 10,
31 }),
32 );
33
34 test.provider(
35 "getStoragePools on a missing pool fails with NotFound",
36 (stack) =>
37 Effect.gen(function* () {
38 const { project } = yield* GcpEnvironment.current;
39 yield* stack.destroy();
40
41 const error = yield* Effect.flip(
42 compute.getStoragePools({
43 project,
44 zone,
45 storagePool: "alchemy-missing-storage-pool",
46 }),
47 );
48 expect(error._tag).toBe("NotFound");
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
53 );
54
55 test.provider.skipIf(!!process.env.GCP_TEST_STORAGE_POOL)(
56 "insertStoragePools below minimum capacity fails with BadRequest",
57 (stack) =>
58 Effect.gen(function* () {
59 const { project } = yield* GcpEnvironment.current;
60 yield* stack.destroy();
61
62 const error = yield* Effect.flip(
63 compute.insertStoragePools({
64 project,
65 zone,
66 body: {
67 name: "alchemy-storage-pool-probe",
68 storagePoolType: `projects/${project}/zones/${zone}/storagePoolTypes/hyperdisk-balanced`,
69 poolProvisionedCapacityGb: "10",
70 },
71 }),
72 );
73 expect(error._tag).toBe("BadRequest");
74
75 yield* stack.destroy();
76 }).pipe(logLevel),
77 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
78 );
79
80 test.provider.skipIf(!runLifecycle)(
81 "create, update, and delete a storage pool",
82 (stack) =>
83 Effect.gen(function* () {
84 yield* stack.destroy();
85
86 const created = yield* stack.deploy(
87 Effect.gen(function* () {
88 return yield* GCP.Compute.StoragePool("Disks", {
89 zone,
90 description: "shared hyperdisk",
91 storagePoolType: "hyperdisk-balanced",
92 poolProvisionedCapacityGb: 10240,
93 poolProvisionedIops: 10000,
94 poolProvisionedThroughput: 1024,
95 labels: { env: "test" },
96 });
97 }),
98 );
99
100 expect(created.storagePoolName).toEqual(expect.any(String));
101 expect(created.zone).toEqual(zone);
102 expect(created.state).toEqual("READY");
103 expect(created.labels).toMatchObject({ env: "test" });
104 expect(created.poolProvisionedCapacityGb).toEqual("10240");
105
106 const fetched = yield* compute.getStoragePools({
107 project: created.project,
108 zone: created.zone,
109 storagePool: created.storagePoolName,
110 });
111 expect(fetched.name).toEqual(created.storagePoolName);
112 expect(fetched.state).toEqual("READY");
113 expect(fetched.labels?.env).toEqual("test");
114
115 const updated = yield* stack.deploy(
116 Effect.gen(function* () {
117 return yield* GCP.Compute.StoragePool("Disks", {
118 storagePoolName: created.storagePoolName,
119 zone,
120 description: "shared hyperdisk v2",
121 storagePoolType: "hyperdisk-balanced",
122 poolProvisionedCapacityGb: 10240,
123 poolProvisionedIops: 11000,
124 poolProvisionedThroughput: 1024,
125 labels: { env: "prod" },
126 });
127 }),
128 );
129
130 expect(updated.storagePoolName).toEqual(created.storagePoolName);
131 expect(updated.description).toEqual("shared hyperdisk v2");
132 expect(updated.labels).toMatchObject({ env: "prod" });
133
134 yield* stack.destroy();
135 const gone = yield* waitUntilGone(created.project, created.zone, created.storagePoolName);
136 expect(gone).toEqual("gone");
137 }).pipe(logLevel),
138 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
139 );