@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 183 lines 6.51 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.getProjectsLocationsLbEdgeExtensions({ 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 "getProjectsLocationsLbEdgeExtensions on a missing extension fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 const { project } = yield* GcpEnvironment.current;
32 const error = yield* Effect.flip(
33 networkservices.getProjectsLocationsLbEdgeExtensions({
34 name: `projects/${project}/locations/global/lbEdgeExtensions/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 // Edge extensions need a WasmPlugin with a main version; the fixture's
48 // bare plugin makes create fail with BadRequest "MAIN_VERSION_ID_EMPTY: Main
49 // version ID must not be empty." Set GCP_TEST_LB_EDGE_EXTENSION=1 once the
50 // fixture publishes a plugin version.
51 test.provider.skipIf(!!process.env.FAST || !process.env.GCP_TEST_LB_EDGE_EXTENSION)(
52 "create, update, and delete an lb edge extension",
53 (stack) =>
54 Effect.gen(function* () {
55 yield* stack.destroy();
56
57 const created = yield* stack.deploy(
58 Effect.gen(function* () {
59 const plugin = yield* GCP.NetworkServices.WasmPlugin("EdgePlugin", {
60 location: "global",
61 description: "edge wasm",
62 });
63 const map = yield* GCP.Compute.UrlMap("EdgeMap", {
64 defaultUrlRedirect: {
65 httpsRedirect: true,
66 hostRedirect: "example.com",
67 stripQuery: false,
68 },
69 });
70 const proxy = yield* GCP.Compute.TargetHttpProxy("EdgeProxy", {
71 urlMap: map.urlMapName,
72 });
73 const rule = yield* GCP.Compute.GlobalForwardingRule("EdgeFr", {
74 target: proxy.selfLink.as<string>(),
75 portRange: "80",
76 loadBalancingScheme: "EXTERNAL_MANAGED",
77 });
78 return yield* GCP.NetworkServices.LbEdgeExtension("Edge", {
79 location: "global",
80 description: "lb edge a",
81 labels: { env: "test" },
82 loadBalancingScheme: "EXTERNAL_MANAGED",
83 forwardingRules: [rule.selfLink.as<string>()],
84 extensionChains: [
85 {
86 name: "chain1",
87 matchCondition: { celExpression: "true" },
88 extensions: [
89 {
90 name: "ext1",
91 service: plugin.name,
92 supportedEvents: ["REQUEST_HEADERS"],
93 },
94 ],
95 },
96 ],
97 });
98 }),
99 );
100
101 expect(created.name).toContain("/lbEdgeExtensions/");
102 expect(created.lbEdgeExtensionId).toEqual(expect.any(String));
103 expect(created.location).toEqual("global");
104 expect(created.description).toEqual("lb edge a");
105 expect(created.labels).toMatchObject({ env: "test" });
106 expect(created.createTime).toEqual(expect.any(String));
107
108 const fetched = yield* networkservices.getProjectsLocationsLbEdgeExtensions({
109 name: created.name,
110 });
111 expect(fetched.name).toEqual(created.name);
112 expect(fetched.description).toEqual("lb edge a");
113 expect(fetched.labels?.env).toEqual("test");
114 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
115 true,
116 );
117
118 const updated = yield* stack.deploy(
119 Effect.gen(function* () {
120 const plugin = yield* GCP.NetworkServices.WasmPlugin("EdgePlugin", {
121 location: "global",
122 description: "edge wasm",
123 });
124 const map = yield* GCP.Compute.UrlMap("EdgeMap", {
125 defaultUrlRedirect: {
126 httpsRedirect: true,
127 hostRedirect: "example.com",
128 stripQuery: false,
129 },
130 });
131 const proxy = yield* GCP.Compute.TargetHttpProxy("EdgeProxy", {
132 urlMap: map.urlMapName,
133 });
134 const rule = yield* GCP.Compute.GlobalForwardingRule("EdgeFr", {
135 target: proxy.selfLink.as<string>(),
136 portRange: "80",
137 loadBalancingScheme: "EXTERNAL_MANAGED",
138 });
139 return yield* GCP.NetworkServices.LbEdgeExtension("Edge", {
140 lbEdgeExtensionId: created.lbEdgeExtensionId,
141 location: "global",
142 description: "lb edge b",
143 labels: { env: "prod", role: "edge" },
144 loadBalancingScheme: "EXTERNAL_MANAGED",
145 forwardingRules: [rule.selfLink.as<string>()],
146 extensionChains: [
147 {
148 name: "chain1",
149 matchCondition: { celExpression: "true" },
150 extensions: [
151 {
152 name: "ext1",
153 service: plugin.name,
154 failOpen: true,
155 supportedEvents: ["REQUEST_HEADERS"],
156 },
157 ],
158 },
159 ],
160 });
161 }),
162 );
163
164 expect(updated.name).toEqual(created.name);
165 expect(updated.description).toEqual("lb edge b");
166 expect(updated.labels).toMatchObject({ env: "prod", role: "edge" });
167
168 const refetched = yield* networkservices.getProjectsLocationsLbEdgeExtensions({
169 name: created.name,
170 });
171 expect(refetched.description).toEqual("lb edge b");
172 expect(refetched.labels?.env).toEqual("prod");
173
174 yield* stack.destroy();
175
176 const gone = yield* waitUntilGone(created.name);
177 expect(gone).toEqual("gone");
178 }).pipe(logLevel),
179 {
180 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
181 timeout: 120_000,
182 },
183 );