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

main
ts 179 lines 6.01 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 networkservices from "@distilled.cloud/gcp/networkservices_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const waitUntilGone = (name: string) =>
15 networkservices.getProjectsLocationsLbRouteExtensions({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsLbRouteExtensions on a missing extension fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 networkservices.getProjectsLocationsLbRouteExtensions({
34 name: `projects/${project}/locations/us-central1/lbRouteExtensions/alchemy-missing`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 test.provider(
48 "createProjectsLocationsLbRouteExtensions without a forwarding rule fails with BadRequest",
49 (stack) =>
50 Effect.gen(function* () {
51 const { project } = yield* GcpEnvironment.current;
52 yield* stack.destroy();
53
54 const error = yield* Effect.flip(
55 networkservices.createProjectsLocationsLbRouteExtensions({
56 parent: `projects/${project}/locations/us-central1`,
57 lbRouteExtensionId: "alchemy-missing-lb-route",
58 body: {
59 loadBalancingScheme: "INTERNAL_MANAGED",
60 forwardingRules: [
61 `//compute.googleapis.com/projects/${project}/regions/us-central1/forwardingRules/alchemy-missing-fr`,
62 ],
63 extensionChains: [
64 {
65 name: "chain1",
66 matchCondition: { celExpression: "true" },
67 extensions: [
68 {
69 name: "ext1",
70 authority: "ext1.example.com",
71 service: `https://www.googleapis.com/compute/v1/projects/${project}/regions/us-central1/backendServices/alchemy-missing-be`,
72 timeout: "0.1s",
73 supportedEvents: ["REQUEST_HEADERS"],
74 },
75 ],
76 },
77 ],
78 },
79 }),
80 );
81 expect(error._tag).toBe("BadRequest");
82
83 yield* stack.destroy();
84 }).pipe(logLevel),
85 {
86 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
87 timeout: 90_000,
88 },
89 );
90
91 test.provider.skipIf(!!process.env.FAST || !process.env.GCP_TEST_LB_ROUTE_EXTENSION)(
92 "create, update, and delete an lb route extension",
93 (stack) =>
94 Effect.gen(function* () {
95 yield* stack.destroy();
96
97 const forwardingRule = process.env.GCP_TEST_LB_ROUTE_EXTENSION_TARGET!;
98 const service = process.env.GCP_TEST_LB_ROUTE_EXTENSION_SERVICE!;
99
100 const created = yield* stack.deploy(
101 Effect.gen(function* () {
102 return yield* GCP.NetworkServices.LbRouteExtension("Route", {
103 location: "us-central1",
104 description: "lb route a",
105 labels: { env: "test" },
106 loadBalancingScheme: "INTERNAL_MANAGED",
107 forwardingRules: [forwardingRule],
108 extensionChains: [
109 {
110 name: "chain1",
111 matchCondition: { celExpression: "true" },
112 extensions: [
113 {
114 name: "ext1",
115 authority: "ext1.example.com",
116 service,
117 timeout: "0.1s",
118 supportedEvents: ["REQUEST_HEADERS"],
119 },
120 ],
121 },
122 ],
123 });
124 }),
125 );
126
127 expect(created.name).toContain("/lbRouteExtensions/");
128 expect(created.location).toEqual("us-central1");
129 expect(created.labels).toMatchObject({ env: "test" });
130
131 const fetched = yield* networkservices.getProjectsLocationsLbRouteExtensions({
132 name: created.name,
133 });
134 expect(fetched.name).toEqual(created.name);
135 expect(fetched.labels?.env).toEqual("test");
136
137 const updated = yield* stack.deploy(
138 Effect.gen(function* () {
139 return yield* GCP.NetworkServices.LbRouteExtension("Route", {
140 lbRouteExtensionId: created.lbRouteExtensionId,
141 location: "us-central1",
142 description: "lb route b",
143 labels: { env: "prod", role: "route" },
144 loadBalancingScheme: "INTERNAL_MANAGED",
145 forwardingRules: [forwardingRule],
146 extensionChains: [
147 {
148 name: "chain1",
149 matchCondition: { celExpression: "true" },
150 extensions: [
151 {
152 name: "ext1",
153 authority: "ext1.example.com",
154 service,
155 timeout: "0.2s",
156 failOpen: true,
157 supportedEvents: ["REQUEST_HEADERS"],
158 },
159 ],
160 },
161 ],
162 });
163 }),
164 );
165
166 expect(updated.name).toEqual(created.name);
167 expect(updated.description).toEqual("lb route b");
168 expect(updated.labels).toMatchObject({ env: "prod", role: "route" });
169
170 yield* stack.destroy();
171
172 const gone = yield* waitUntilGone(created.name);
173 expect(gone).toEqual("gone");
174 }).pipe(logLevel),
175 {
176 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
177 timeout: 120_000,
178 },
179 );