The best way to control Claude Code, Codex and more from any computer or phone

main
ts 123 lines 4.4 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_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.getProjectsLocationsInstances({ 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 "getProjectsLocationsInstances on a missing instance fails with NotFound",
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.getProjectsLocationsInstances({
39 name: `projects/${project}/locations/us-central1-a/instances/alchemy-filestore-missing`,
40 }),
41 );
42 expect(error._tag).toBe("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 instance",
51 (stack) =>
52 Effect.gen(function* () {
53 yield* stack.destroy();
54
55 const created = yield* stack.deploy(
56 Effect.gen(function* () {
57 return 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 description: "alchemy-test-nfs",
63 labels: { env: "test" },
64 });
65 }),
66 );
67
68 expect(created.name).toContain("/instances/");
69 expect(created.instanceId).toEqual(expect.any(String));
70 expect(created.location).toEqual(CAPACITY_ZONE);
71 expect(created.tier).toEqual("BASIC_HDD");
72 expect(created.description).toEqual("alchemy-test-nfs");
73 expect(created.labels).toMatchObject({ env: "test" });
74 expect(created.state).toEqual("READY");
75 expect(created.fileShares[0]?.name).toEqual("share1");
76 expect(created.fileShares[0]?.capacityGb).toEqual(1024);
77
78 const fetched = yield* file.getProjectsLocationsInstances({
79 name: created.name,
80 });
81 expect(fetched.name).toEqual(created.name);
82 expect(fetched.tier).toEqual("BASIC_HDD");
83 expect(fetched.description).toEqual("alchemy-test-nfs");
84 expect(fetched.labels?.env).toEqual("test");
85 expect(fetched.fileShares?.[0]?.name).toEqual("share1");
86 expect(fetched.fileShares?.[0]?.capacityGb).toEqual("1024");
87
88 const updated = yield* stack.deploy(
89 Effect.gen(function* () {
90 return yield* GCP.Filestore.Instance("Nfs", {
91 instanceId: created.instanceId,
92 location: CAPACITY_ZONE,
93 tier: "BASIC_HDD",
94 fileShares: [{ name: "share1", capacityGb: 1024 }],
95 networks: [{ network: "default", modes: ["MODE_IPV4"] }],
96 description: "alchemy-prod-nfs",
97 labels: { env: "prod", role: "nfs" },
98 });
99 }),
100 );
101
102 expect(updated.name).toEqual(created.name);
103 expect(updated.description).toEqual("alchemy-prod-nfs");
104 expect(updated.labels).toMatchObject({ env: "prod", role: "nfs" });
105
106 const refetched = yield* file.getProjectsLocationsInstances({
107 name: created.name,
108 });
109 expect(refetched.description).toEqual("alchemy-prod-nfs");
110 expect(refetched.labels?.env).toEqual("prod");
111 expect(refetched.labels?.role).toEqual("nfs");
112
113 yield* stack.destroy();
114
115 const gone = yield* waitUntilGone(created.name);
116 expect(gone).toEqual("gone");
117 }).pipe(logLevel),
118 {
119 tags: ["provider:gcp", "provider:gcp:filestore", "live"],
120 timeout: 2_700_000,
121 retry: 0,
122 },
123 );