@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 139 lines 5.06 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 networkconnectivity from "@distilled.cloud/gcp/networkconnectivity_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 runLifecycle = !process.env.FAST;
16
17 const waitUntilGone = (name: string) =>
18 networkconnectivity.getProjectsLocationsServiceConnectionPolicies({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("2 seconds"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider(
29 "getProjectsLocationsServiceConnectionPolicies on a missing policy fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 networkconnectivity.getProjectsLocationsServiceConnectionPolicies({
37 name: `projects/${project}/locations/us-central1/serviceConnectionPolicies/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:networkconnectivity", "live"],
46 timeout: 90_000,
47 },
48 );
49
50 test.provider.skipIf(!runLifecycle)(
51 "create, update, and delete a service connection policy",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 const network = yield* GCP.Compute.Network("ScpVpc", {
59 autoCreateSubnetworks: false,
60 });
61 const subnet = yield* GCP.Compute.Subnetwork("ScpSubnet", {
62 network: network.networkName,
63 ipCidrRange: "10.22.0.0/24",
64 privateIpGoogleAccess: true,
65 });
66 const policy = yield* GCP.NetworkConnectivity.ServiceConnectionPolicy("Redis", {
67 serviceClass: "gcp-memorystore-redis",
68 network: network.selfLink.as<string>(),
69 pscConfig: {
70 subnetworks: [subnet.selfLink.as<string>()],
71 },
72 description: "policy a",
73 labels: { env: "test" },
74 });
75 return { network, subnet, policy };
76 }),
77 );
78
79 expect(created.policy.name).toContain("/serviceConnectionPolicies/");
80 expect(created.policy.location).toEqual("us-central1");
81 expect(created.policy.serviceClass).toEqual("gcp-memorystore-redis");
82 expect(created.policy.description).toEqual("policy a");
83 expect(created.policy.labels).toMatchObject({ env: "test" });
84
85 const fetched = yield* networkconnectivity.getProjectsLocationsServiceConnectionPolicies({
86 name: created.policy.name,
87 });
88 expect(fetched.name).toEqual(created.policy.name);
89 expect(fetched.serviceClass).toEqual("gcp-memorystore-redis");
90 expect(fetched.labels?.env).toEqual("test");
91 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
92 true,
93 );
94
95 const updated = yield* stack.deploy(
96 Effect.gen(function* () {
97 const network = yield* GCP.Compute.Network("ScpVpc", {
98 networkName: created.network.networkName,
99 autoCreateSubnetworks: false,
100 });
101 const subnet = yield* GCP.Compute.Subnetwork("ScpSubnet", {
102 subnetworkName: created.subnet.subnetworkName,
103 network: network.networkName,
104 ipCidrRange: "10.22.0.0/24",
105 privateIpGoogleAccess: true,
106 });
107 const policy = yield* GCP.NetworkConnectivity.ServiceConnectionPolicy("Redis", {
108 serviceConnectionPolicyId: created.policy.serviceConnectionPolicyId,
109 location: created.policy.location,
110 serviceClass: "gcp-memorystore-redis",
111 network: network.selfLink.as<string>(),
112 pscConfig: {
113 subnetworks: [subnet.selfLink.as<string>()],
114 limit: "4",
115 },
116 description: "policy b",
117 labels: { env: "prod", role: "psc" },
118 });
119 return { network, subnet, policy };
120 }),
121 );
122
123 expect(updated.policy.name).toEqual(created.policy.name);
124 expect(updated.policy.description).toEqual("policy b");
125 expect(updated.policy.labels).toMatchObject({
126 env: "prod",
127 role: "psc",
128 });
129
130 yield* stack.destroy();
131
132 const gone = yield* waitUntilGone(created.policy.name);
133 expect(gone).toEqual("gone");
134 }).pipe(logLevel, withNetworkSlot),
135 {
136 tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"],
137 timeout: 600_000,
138 },
139 );