@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 138 lines 4.97 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 file from "@distilled.cloud/gcp/file_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { CAPACITY_REGION, CAPACITY_ZONE } from "../zones.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 // Filestore instances take 5–20 minutes to provision and several to delete.
16 const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST;
17
18 const waitUntilGone = (name: string) =>
19 file.getProjectsLocationsBackups({ name }).pipe(
20 Effect.as("found" as const),
21 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
22 Effect.repeat({
23 schedule: Schedule.spaced("2 seconds"),
24 until: (status) => status === "gone",
25 times: 10,
26 }),
27 );
28
29 test.provider(
30 "getProjectsLocationsBackups on a missing backup fails with a typed tag",
31 (stack) =>
32 Effect.gen(function* () {
33 const { project } = yield* GcpEnvironment.current;
34
35 yield* stack.destroy();
36
37 const error = yield* Effect.flip(
38 file.getProjectsLocationsBackups({
39 name: `projects/${project}/locations/us-central1/backups/alchemy-filestore-missing`,
40 }),
41 );
42 expect(error._tag).toEqual("NotFound");
43
44 yield* stack.destroy();
45 }).pipe(logLevel),
46 { tags: ["provider:gcp", "provider:gcp:filestore", "live"], timeout: 90_000 },
47 );
48
49 test.provider.skipIf(!runLifecycle)(
50 "create, update, and delete a filestore backup",
51 (stack) =>
52 Effect.gen(function* () {
53 yield* stack.destroy();
54
55 const created = yield* stack.deploy(
56 Effect.gen(function* () {
57 const nfs = yield* GCP.Filestore.Instance("Nfs", {
58 location: CAPACITY_ZONE,
59 tier: "BASIC_HDD",
60 fileShares: [{ name: "share1", capacityGb: 1024 }],
61 networks: [{ network: "default", modes: ["MODE_IPV4"] }],
62 labels: { env: "test" },
63 });
64 const backup = yield* GCP.Filestore.Backup("Nightly", {
65 sourceInstance: nfs.name,
66 sourceFileShare: "share1",
67 location: CAPACITY_REGION,
68 description: "alchemy-test-backup",
69 labels: { env: "test" },
70 });
71 return { nfs, backup };
72 }),
73 );
74
75 expect(created.backup.name).toContain("/backups/");
76 expect(created.backup.backupId).toEqual(expect.any(String));
77 expect(created.backup.location).toEqual(CAPACITY_REGION);
78 expect(created.backup.sourceInstance).toEqual(created.nfs.name);
79 expect(created.backup.sourceFileShare).toEqual("share1");
80 expect(created.backup.description).toEqual("alchemy-test-backup");
81 expect(created.backup.labels).toMatchObject({ env: "test" });
82 expect(created.backup.state).toEqual("READY");
83
84 const fetched = yield* file.getProjectsLocationsBackups({
85 name: created.backup.name,
86 });
87 expect(fetched.name).toEqual(created.backup.name);
88 expect(fetched.description).toEqual("alchemy-test-backup");
89 expect(fetched.labels?.env).toEqual("test");
90 expect(fetched.sourceFileShare).toEqual("share1");
91
92 const updated = yield* stack.deploy(
93 Effect.gen(function* () {
94 const nfs = yield* GCP.Filestore.Instance("Nfs", {
95 instanceId: created.nfs.instanceId,
96 location: CAPACITY_ZONE,
97 tier: "BASIC_HDD",
98 fileShares: [{ name: "share1", capacityGb: 1024 }],
99 networks: [{ network: "default", modes: ["MODE_IPV4"] }],
100 labels: { env: "test" },
101 });
102 const backup = yield* GCP.Filestore.Backup("Nightly", {
103 sourceInstance: nfs.name,
104 sourceFileShare: "share1",
105 backupId: created.backup.backupId,
106 location: CAPACITY_REGION,
107 description: "alchemy-prod-backup",
108 labels: { env: "prod", role: "backup" },
109 });
110 return { nfs, backup };
111 }),
112 );
113
114 expect(updated.backup.name).toEqual(created.backup.name);
115 expect(updated.backup.description).toEqual("alchemy-prod-backup");
116 expect(updated.backup.labels).toMatchObject({
117 env: "prod",
118 role: "backup",
119 });
120
121 const refetched = yield* file.getProjectsLocationsBackups({
122 name: created.backup.name,
123 });
124 expect(refetched.description).toEqual("alchemy-prod-backup");
125 expect(refetched.labels?.env).toEqual("prod");
126 expect(refetched.labels?.role).toEqual("backup");
127
128 yield* stack.destroy();
129
130 const gone = yield* waitUntilGone(created.backup.name);
131 expect(gone).toEqual("gone");
132 }).pipe(logLevel),
133 {
134 tags: ["provider:gcp", "provider:gcp:filestore", "live"],
135 timeout: 2_700_000,
136 retry: 0,
137 },
138 );