@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 142 lines 5.13 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 networkmanagement from "@distilled.cloud/gcp/networkmanagement_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { defaultNetworkSelfLink } 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 runLifecycle = !process.env.FAST;
16
17 const waitUntilGone = (name: string) =>
18 networkmanagement.getProjectsLocationsGlobalConnectivityTests({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("1 second"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider(
29 "getProjectsLocationsGlobalConnectivityTests on a missing test fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 networkmanagement.getProjectsLocationsGlobalConnectivityTests({
38 name: `projects/${project}/locations/global/connectivityTests/alchemy-missing`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 yield* stack.destroy();
44 }).pipe(logLevel),
45 {
46 tags: ["provider:gcp", "provider:gcp:networkmanagement", "live"],
47 timeout: 90_000,
48 },
49 );
50
51 test.provider.skipIf(!runLifecycle)(
52 "create, update, and delete a connectivity test",
53 (stack) =>
54 Effect.gen(function* () {
55 const { project } = yield* GcpEnvironment.current;
56
57 yield* stack.destroy();
58
59 const created = yield* stack.deploy(
60 Effect.gen(function* () {
61 const test = yield* GCP.NetworkManagement.ConnectivityTest("DnsPath", {
62 source: {
63 ipAddress: "10.8.0.1",
64 network: defaultNetworkSelfLink(project),
65 networkType: "GCP_NETWORK",
66 projectId: project,
67 },
68 destination: { ipAddress: "10.8.0.2", port: 443 },
69 protocol: "TCP",
70 description: "reach a",
71 labels: { env: "test" },
72 });
73 return { test };
74 }),
75 );
76
77 expect(created.test.name).toContain("/connectivityTests/");
78 expect(created.test.name).toContain("/locations/global/");
79 expect(created.test.testId).toEqual(expect.any(String));
80 expect(created.test.location).toEqual("global");
81 expect(created.test.description).toEqual("reach a");
82 expect(created.test.protocol).toEqual("TCP");
83 expect(created.test.source?.ipAddress).toEqual("10.8.0.1");
84 expect(created.test.destination?.ipAddress).toEqual("10.8.0.2");
85 expect(created.test.destination?.port).toEqual(443);
86 expect(created.test.labels).toMatchObject({ env: "test" });
87 expect(created.test.createTime).toEqual(expect.any(String));
88
89 const fetched = yield* networkmanagement.getProjectsLocationsGlobalConnectivityTests({
90 name: created.test.name,
91 });
92 expect(fetched.name).toEqual(created.test.name);
93 expect(fetched.labels?.env).toEqual("test");
94 expect(fetched.description).toEqual("reach a");
95 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
96 true,
97 );
98
99 const updated = yield* stack.deploy(
100 Effect.gen(function* () {
101 const test = yield* GCP.NetworkManagement.ConnectivityTest("DnsPath", {
102 testId: created.test.testId,
103 source: {
104 ipAddress: "10.8.0.1",
105 network: defaultNetworkSelfLink(project),
106 networkType: "GCP_NETWORK",
107 projectId: project,
108 },
109 destination: { ipAddress: "10.8.0.2", port: 80 },
110 protocol: "TCP",
111 description: "reach b",
112 labels: { env: "prod", role: "reach" },
113 bypassFirewallChecks: true,
114 });
115 return { test };
116 }),
117 );
118
119 expect(updated.test.name).toEqual(created.test.name);
120 expect(updated.test.description).toEqual("reach b");
121 expect(updated.test.destination?.port).toEqual(80);
122 expect(updated.test.bypassFirewallChecks).toEqual(true);
123 expect(updated.test.labels).toMatchObject({ env: "prod", role: "reach" });
124
125 const refetched = yield* networkmanagement.getProjectsLocationsGlobalConnectivityTests({
126 name: created.test.name,
127 });
128 expect(refetched.description).toEqual("reach b");
129 expect(refetched.destination?.port).toEqual(80);
130 expect(refetched.labels?.env).toEqual("prod");
131 expect(refetched.labels?.role).toEqual("reach");
132
133 yield* stack.destroy();
134
135 const gone = yield* waitUntilGone(created.test.name);
136 expect(gone).toEqual("gone");
137 }).pipe(logLevel),
138 {
139 tags: ["provider:gcp", "provider:gcp:networkmanagement", "live"],
140 timeout: 600_000,
141 },
142 );