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

main
ts 127 lines 4.61 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 networksecurity from "@distilled.cloud/gcp/networksecurity_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { withNetworkSlot } from "../networkQuota.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 const waitUntilGone = (name: string) =>
16 networksecurity.getProjectsLocationsMirroringDeploymentGroups({ name }).pipe(
17 Effect.as("found" as const),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.repeat({
20 schedule: Schedule.spaced("2 seconds"),
21 until: (status) => status === "gone",
22 times: 10,
23 }),
24 );
25
26 test.provider(
27 "getProjectsLocationsMirroringDeploymentGroups on a missing group fails with a typed tag",
28 (stack) =>
29 Effect.gen(function* () {
30 yield* stack.destroy();
31
32 const { project } = yield* GcpEnvironment.current;
33 const error = yield* Effect.flip(
34 networksecurity.getProjectsLocationsMirroringDeploymentGroups({
35 name: `projects/${project}/locations/global/mirroringDeploymentGroups/alchemy-missing`,
36 }),
37 );
38 expect(error._tag).toEqual("NotFound");
39
40 yield* stack.destroy();
41 }).pipe(logLevel),
42 {
43 tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
44 timeout: 90_000,
45 },
46 );
47
48 test.provider.skipIf(!!process.env.FAST)(
49 "create, update, and delete a mirroring deployment group",
50 (stack) =>
51 Effect.gen(function* () {
52 yield* stack.destroy();
53
54 const created = yield* stack.deploy(
55 Effect.gen(function* () {
56 const vpc = yield* GCP.Compute.Network("Vpc", {
57 autoCreateSubnetworks: false,
58 description: "mirroring group vpc",
59 });
60 const group = yield* GCP.NetworkSecurity.MirroringDeploymentGroup("Collectors", {
61 location: "global",
62 network: vpc.selfLink.as<string>(),
63 description: "mirroring group a",
64 labels: { env: "test" },
65 });
66 return { vpc, group };
67 }),
68 );
69
70 expect(created.group.name).toContain("/mirroringDeploymentGroups/");
71 expect(created.group.location).toEqual("global");
72 expect(created.group.description).toEqual("mirroring group a");
73 expect(created.group.labels).toMatchObject({ env: "test" });
74 expect(created.group.network).toContain(`/global/networks/${created.vpc.networkName}`);
75
76 const fetched = yield* networksecurity.getProjectsLocationsMirroringDeploymentGroups({
77 name: created.group.name,
78 });
79 expect(fetched.name).toEqual(created.group.name);
80 expect(fetched.description).toEqual("mirroring group a");
81 expect(fetched.labels?.env).toEqual("test");
82 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
83 true,
84 );
85
86 const updated = yield* stack.deploy(
87 Effect.gen(function* () {
88 const vpc = yield* GCP.Compute.Network("Vpc", {
89 networkName: created.vpc.networkName,
90 autoCreateSubnetworks: false,
91 description: "mirroring group vpc",
92 });
93 const group = yield* GCP.NetworkSecurity.MirroringDeploymentGroup("Collectors", {
94 mirroringDeploymentGroupId: created.group.mirroringDeploymentGroupId,
95 location: "global",
96 network: vpc.selfLink.as<string>(),
97 description: "mirroring group b",
98 labels: { env: "prod", role: "nsi" },
99 });
100 return { vpc, group };
101 }),
102 );
103
104 expect(updated.group.name).toEqual(created.group.name);
105 expect(updated.group.description).toEqual("mirroring group b");
106 expect(updated.group.labels).toMatchObject({
107 env: "prod",
108 role: "nsi",
109 });
110
111 const refetched = yield* networksecurity.getProjectsLocationsMirroringDeploymentGroups({
112 name: created.group.name,
113 });
114 expect(refetched.description).toEqual("mirroring group b");
115 expect(refetched.labels?.env).toEqual("prod");
116 expect(refetched.labels?.role).toEqual("nsi");
117
118 yield* stack.destroy();
119
120 const gone = yield* waitUntilGone(created.group.name);
121 expect(gone).toEqual("gone");
122 }).pipe(logLevel, withNetworkSlot),
123 {
124 tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
125 timeout: 600_000,
126 },
127 );