@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 134 lines 5 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.getProjectsLocationsInterceptEndpointGroups({ 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 "getProjectsLocationsInterceptEndpointGroups 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.getProjectsLocationsInterceptEndpointGroups({
35 name: `projects/${project}/locations/global/interceptEndpointGroups/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 an intercept endpoint 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: "intercept endpoint vpc",
59 });
60 const collectors = yield* GCP.NetworkSecurity.InterceptDeploymentGroup("Inspect", {
61 network: vpc.selfLink.as<string>(),
62 description: "collectors",
63 });
64 const group = yield* GCP.NetworkSecurity.InterceptEndpointGroup("Front", {
65 interceptDeploymentGroup: collectors.name,
66 description: "intercept eg a",
67 labels: { env: "test" },
68 });
69 return { vpc, collectors, group };
70 }),
71 );
72
73 expect(created.group.name).toContain("/interceptEndpointGroups/");
74 expect(created.group.location).toEqual("global");
75 expect(created.group.description).toEqual("intercept eg a");
76 expect(created.group.labels).toMatchObject({ env: "test" });
77 expect(created.group.interceptDeploymentGroup).toEqual(created.collectors.name);
78
79 const fetched = yield* networksecurity.getProjectsLocationsInterceptEndpointGroups({
80 name: created.group.name,
81 });
82 expect(fetched.name).toEqual(created.group.name);
83 expect(fetched.description).toEqual("intercept eg a");
84 expect(fetched.labels?.env).toEqual("test");
85 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
86 true,
87 );
88
89 const updated = yield* stack.deploy(
90 Effect.gen(function* () {
91 const vpc = yield* GCP.Compute.Network("Vpc", {
92 networkName: created.vpc.networkName,
93 autoCreateSubnetworks: false,
94 description: "intercept endpoint vpc",
95 });
96 const collectors = yield* GCP.NetworkSecurity.InterceptDeploymentGroup("Inspect", {
97 interceptDeploymentGroupId: created.collectors.interceptDeploymentGroupId,
98 network: vpc.selfLink.as<string>(),
99 description: "collectors",
100 });
101 const group = yield* GCP.NetworkSecurity.InterceptEndpointGroup("Front", {
102 interceptEndpointGroupId: created.group.interceptEndpointGroupId,
103 interceptDeploymentGroup: collectors.name,
104 description: "intercept eg b",
105 labels: { env: "prod", role: "nsi" },
106 });
107 return { vpc, collectors, group };
108 }),
109 );
110
111 expect(updated.group.name).toEqual(created.group.name);
112 expect(updated.group.description).toEqual("intercept eg b");
113 expect(updated.group.labels).toMatchObject({
114 env: "prod",
115 role: "nsi",
116 });
117
118 const refetched = yield* networksecurity.getProjectsLocationsInterceptEndpointGroups({
119 name: created.group.name,
120 });
121 expect(refetched.description).toEqual("intercept eg b");
122 expect(refetched.labels?.env).toEqual("prod");
123 expect(refetched.labels?.role).toEqual("nsi");
124
125 yield* stack.destroy();
126
127 const gone = yield* waitUntilGone(created.group.name);
128 expect(gone).toEqual("gone");
129 }).pipe(logLevel, withNetworkSlot),
130 {
131 tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
132 timeout: 600_000,
133 },
134 );