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

main
ts 101 lines 3.48 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 const waitUntilGone = (name: string) =>
15 netapp.getProjectsLocationsHostGroups({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsHostGroups on a missing group fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30
31 yield* stack.destroy();
32
33 const error = yield* Effect.flip(
34 netapp.getProjectsLocationsHostGroups({
35 name: `projects/${project}/locations/us-central1/hostGroups/alchemy-netapp-missing`,
36 }),
37 );
38 expect(error._tag).toEqual("NotFound");
39
40 const page = yield* netapp.listProjectsLocationsHostGroups({
41 parent: `projects/${project}/locations/-`,
42 pageSize: 10,
43 });
44 expect((page.hostGroups ?? []).map((item) => item.name)).not.toContain(
45 `projects/${project}/locations/us-central1/hostGroups/alchemy-netapp-missing`,
46 );
47
48 yield* stack.destroy();
49 }).pipe(logLevel),
50 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 90_000 },
51 );
52
53 test.provider(
54 "create, update, and delete a host group",
55 (stack) =>
56 Effect.gen(function* () {
57 yield* stack.destroy();
58
59 const created = yield* stack.deploy(
60 Effect.gen(function* () {
61 return yield* GCP.NetApp.HostGroup("Initiators", {
62 hosts: ["iqn.1993-08.org.debian:01:alchemy"],
63 description: "alchemy-test-hosts",
64 labels: { env: "test" },
65 });
66 }),
67 );
68
69 expect(created.name).toContain("/hostGroups/");
70 expect(created.hosts).toContain("iqn.1993-08.org.debian:01:alchemy");
71 expect(created.labels).toMatchObject({ env: "test" });
72
73 const fetched = yield* netapp.getProjectsLocationsHostGroups({
74 name: created.name,
75 });
76 expect(fetched.name).toEqual(created.name);
77 expect(fetched.labels?.env).toEqual("test");
78
79 const updated = yield* stack.deploy(
80 Effect.gen(function* () {
81 return yield* GCP.NetApp.HostGroup("Initiators", {
82 hostGroupId: created.hostGroupId,
83 hosts: ["iqn.1993-08.org.debian:01:alchemy", "iqn.1993-08.org.debian:01:alchemy2"],
84 description: "alchemy-prod-hosts",
85 labels: { env: "prod", role: "iscsi" },
86 });
87 }),
88 );
89
90 expect(updated.name).toEqual(created.name);
91 expect(updated.description).toEqual("alchemy-prod-hosts");
92 expect(updated.labels).toMatchObject({ env: "prod", role: "iscsi" });
93 expect(updated.hosts).toHaveLength(2);
94
95 yield* stack.destroy();
96
97 const gone = yield* waitUntilGone(created.name);
98 expect(gone).toEqual("gone");
99 }).pipe(logLevel),
100 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 120_000 },
101 );