@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.12 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 Output from "alchemy/Output";
7 import * as Effect from "effect/Effect";
8 import { MinimumLogLevel } from "effect/References";
9 import * as Schedule from "effect/Schedule";
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 networksecurity.getProjectsLocationsTlsInspectionPolicies({ 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 "getProjectsLocationsTlsInspectionPolicies on a missing policy fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 yield* stack.destroy();
33
34 const { project } = yield* GcpEnvironment.current;
35 const error = yield* Effect.flip(
36 networksecurity.getProjectsLocationsTlsInspectionPolicies({
37 name: `projects/${project}/locations/us-central1/tlsInspectionPolicies/alchemy-missing`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41
42 yield* stack.destroy();
43 }).pipe(logLevel),
44 {
45 tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
46 timeout: 90_000,
47 },
48 );
49
50 test.provider.skipIf(!runLifecycle)(
51 "create, update, and delete a tls inspection policy",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 const pool = yield* GCP.PrivateCA.CaPool("InspectPool", {
59 location: "us-central1",
60 tier: "DEVOPS",
61 labels: { env: "test" },
62 });
63 const ca = yield* GCP.PrivateCA.CertificateAuthority("InspectRoot", {
64 caPool: pool.name,
65 location: "us-central1",
66 type: "SELF_SIGNED",
67 desiredState: "ENABLED",
68 labels: { env: "test" },
69 });
70 return yield* GCP.NetworkSecurity.TlsInspectionPolicy("Inspect", {
71 location: "us-central1",
72 caPool: pool.name,
73 description: Output.interpolate`inspect a ${ca.certificateAuthorityId}`,
74 excludePublicCaSet: true,
75 });
76 }),
77 );
78
79 expect(created.name).toContain("/tlsInspectionPolicies/");
80 expect(created.name).toContain("/locations/us-central1/");
81 expect(created.tlsInspectionPolicyId).toEqual(expect.any(String));
82 expect(created.location).toEqual("us-central1");
83 expect(created.description).toContain("inspect a");
84 expect(created.caPool).toContain("/caPools/");
85 expect(created.excludePublicCaSet).toEqual(true);
86 expect(created.createTime).toEqual(expect.any(String));
87
88 const fetched = yield* networksecurity.getProjectsLocationsTlsInspectionPolicies({
89 name: created.name,
90 });
91 expect(fetched.name).toEqual(created.name);
92 expect(fetched.caPool).toEqual(created.caPool);
93 expect(fetched.excludePublicCaSet).toEqual(true);
94 expect(fetched.description ?? "").toContain("[alchemy ");
95 expect(fetched.description ?? "").toContain("inspect a");
96
97 const updated = yield* stack.deploy(
98 Effect.gen(function* () {
99 const pool = yield* GCP.PrivateCA.CaPool("InspectPool", {
100 location: "us-central1",
101 caPoolId: created.caPool?.split("/").pop(),
102 tier: "DEVOPS",
103 labels: { env: "test" },
104 });
105 const ca = yield* GCP.PrivateCA.CertificateAuthority("InspectRoot", {
106 caPool: pool.name,
107 location: "us-central1",
108 type: "SELF_SIGNED",
109 desiredState: "ENABLED",
110 labels: { env: "test" },
111 });
112 return yield* GCP.NetworkSecurity.TlsInspectionPolicy("Inspect", {
113 tlsInspectionPolicyId: created.tlsInspectionPolicyId,
114 location: "us-central1",
115 caPool: pool.name,
116 description: Output.interpolate`inspect b ${ca.certificateAuthorityId}`,
117 excludePublicCaSet: true,
118 minTlsVersion: "TLS_1_2",
119 });
120 }),
121 );
122
123 expect(updated.name).toEqual(created.name);
124 expect(updated.description).toContain("inspect b");
125 expect(updated.minTlsVersion).toEqual("TLS_1_2");
126
127 const refetched = yield* networksecurity.getProjectsLocationsTlsInspectionPolicies({
128 name: created.name,
129 });
130 expect(refetched.description ?? "").toContain("inspect b");
131 expect(refetched.minTlsVersion).toEqual("TLS_1_2");
132
133 yield* stack.destroy();
134
135 const gone = yield* waitUntilGone(created.name);
136 expect(gone).toEqual("gone");
137 }).pipe(logLevel),
138 {
139 tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
140 timeout: 180_000,
141 },
142 );