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

main
ts 100 lines 3.51 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 iap from "@distilled.cloud/gcp/iap_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 iap.getProjectsIap_tunnelLocationsDestGroups({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsIap_tunnelLocationsDestGroups on a missing group fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 iap.getProjectsIap_tunnelLocationsDestGroups({
34 name: `projects/${project}/iap_tunnel/locations/us-central1/destGroups/alchemy-missing`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 { tags: ["provider:gcp", "provider:gcp:iap", "live"], timeout: 90_000 },
42 );
43
44 test.provider(
45 "create, update, and delete an IAP tunnel dest group",
46 (stack) =>
47 Effect.gen(function* () {
48 const { project } = yield* GcpEnvironment.current;
49 yield* stack.destroy();
50
51 const created = yield* stack.deploy(
52 Effect.gen(function* () {
53 return yield* GCP.IAP.IapDestGroup("SshHosts", {
54 location: "us-central1",
55 cidrs: ["10.241.0.0/24"],
56 });
57 }),
58 );
59
60 expect(created.name).toContain("/destGroups/");
61 expect(created.destGroupId.length).toBeGreaterThanOrEqual(4);
62 expect(created.location).toEqual("us-central1");
63 expect(created.project).toEqual(project);
64 expect(created.cidrs).toEqual(["10.241.0.0/24"]);
65 expect(created.fqdns).toEqual([]);
66
67 const fetched = yield* iap.getProjectsIap_tunnelLocationsDestGroups({
68 name: created.name,
69 });
70 expect(fetched.name).toEqual(created.name);
71 expect(fetched.cidrs).toContain("10.241.0.0/24");
72 expect(fetched.fqdns ?? []).toEqual([]);
73
74 const updated = yield* stack.deploy(
75 Effect.gen(function* () {
76 return yield* GCP.IAP.IapDestGroup("SshHosts", {
77 location: "us-central1",
78 cidrs: ["10.241.0.0/24", "10.241.1.0/24"],
79 fqdns: ["db.internal.example.com"],
80 });
81 }),
82 );
83
84 expect(updated.name).toEqual(created.name);
85 expect(updated.cidrs.sort()).toEqual(["10.241.0.0/24", "10.241.1.0/24"].sort());
86 expect(updated.fqdns).toEqual(["db.internal.example.com"]);
87
88 const fetchedUpdate = yield* iap.getProjectsIap_tunnelLocationsDestGroups({
89 name: created.name,
90 });
91 expect(fetchedUpdate.cidrs?.sort()).toEqual(["10.241.0.0/24", "10.241.1.0/24"].sort());
92 expect(fetchedUpdate.fqdns).toEqual(["db.internal.example.com"]);
93
94 yield* stack.destroy();
95
96 const gone = yield* waitUntilGone(created.name);
97 expect(gone).toEqual("gone");
98 }).pipe(logLevel),
99 { tags: ["provider:gcp", "provider:gcp:iap", "live"], timeout: 90_000 },
100 );