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

main
ts 144 lines 5.22 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.getProjectsLocationsAuthzExtensions({ 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 "getProjectsLocationsAuthzExtensions 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.getProjectsLocationsAuthzExtensions({
34 name: `projects/${project}/locations/us-central1/authzExtensions/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.skipIf(!!process.env.FAST)(
48 "create, update, and delete an authz extension",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const created = yield* stack.deploy(
54 Effect.gen(function* () {
55 const health = yield* GCP.Compute.RegionHealthCheck("AuthzHc", {
56 region: "us-central1",
57 type: "HTTP",
58 httpHealthCheck: { port: 80 },
59 });
60 const backend = yield* GCP.Compute.RegionBackendService("AuthzBe", {
61 region: "us-central1",
62 protocol: "HTTP2",
63 loadBalancingScheme: "INTERNAL_MANAGED",
64 healthChecks: [health.selfLink.as<string>()],
65 });
66 return yield* GCP.NetworkServices.AuthzExtension("Authz", {
67 location: "us-central1",
68 description: "authz extension a",
69 labels: { env: "test" },
70 service: backend.selfLink.as<string>(),
71 authority: "authz.example.com",
72 timeout: "0.1s",
73 loadBalancingScheme: "INTERNAL_MANAGED",
74 });
75 }),
76 );
77
78 expect(created.name).toContain("/authzExtensions/");
79 expect(created.authzExtensionId).toEqual(expect.any(String));
80 expect(created.location).toEqual("us-central1");
81 expect(created.authority).toEqual("authz.example.com");
82 expect(created.description).toEqual("authz extension a");
83 expect(created.labels).toMatchObject({ env: "test" });
84 expect(created.createTime).toEqual(expect.any(String));
85
86 const fetched = yield* networkservices.getProjectsLocationsAuthzExtensions({
87 name: created.name,
88 });
89 expect(fetched.name).toEqual(created.name);
90 expect(fetched.description).toEqual("authz extension a");
91 expect(fetched.labels?.env).toEqual("test");
92 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
93 true,
94 );
95
96 const updated = yield* stack.deploy(
97 Effect.gen(function* () {
98 const health = yield* GCP.Compute.RegionHealthCheck("AuthzHc", {
99 region: "us-central1",
100 type: "HTTP",
101 httpHealthCheck: { port: 80 },
102 });
103 const backend = yield* GCP.Compute.RegionBackendService("AuthzBe", {
104 region: "us-central1",
105 protocol: "HTTP2",
106 loadBalancingScheme: "INTERNAL_MANAGED",
107 healthChecks: [health.selfLink.as<string>()],
108 });
109 return yield* GCP.NetworkServices.AuthzExtension("Authz", {
110 authzExtensionId: created.authzExtensionId,
111 location: "us-central1",
112 description: "authz extension b",
113 labels: { env: "prod", role: "authz" },
114 service: backend.selfLink.as<string>(),
115 authority: "authz.example.com",
116 timeout: "0.2s",
117 failOpen: true,
118 loadBalancingScheme: "INTERNAL_MANAGED",
119 });
120 }),
121 );
122
123 expect(updated.name).toEqual(created.name);
124 expect(updated.description).toEqual("authz extension b");
125 expect(updated.failOpen).toEqual(true);
126 expect(updated.labels).toMatchObject({ env: "prod", role: "authz" });
127
128 const refetched = yield* networkservices.getProjectsLocationsAuthzExtensions({
129 name: created.name,
130 });
131 expect(refetched.description).toEqual("authz extension b");
132 expect(refetched.labels?.env).toEqual("prod");
133 expect(refetched.failOpen).toEqual(true);
134
135 yield* stack.destroy();
136
137 const gone = yield* waitUntilGone(created.name);
138 expect(gone).toEqual("gone");
139 }).pipe(logLevel),
140 {
141 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
142 timeout: 180_000,
143 },
144 );