@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 143 lines 4.67 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.getProjectsLocationsGrpcRoutes({ 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 "getProjectsLocationsGrpcRoutes on a missing route 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.getProjectsLocationsGrpcRoutes({
34 name: `projects/${project}/locations/global/grpcRoutes/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 "create, update, and delete a grpc route",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const created = yield* stack.deploy(
54 Effect.gen(function* () {
55 return yield* GCP.NetworkServices.GrpcRoute("Api", {
56 location: "global",
57 hostnames: ["alchemy-grpc.example.com"],
58 description: "grpc route a",
59 labels: { env: "test" },
60 rules: [
61 {
62 action: {
63 retryPolicy: {
64 retryConditions: ["cancelled"],
65 numRetries: 1,
66 },
67 },
68 },
69 ],
70 });
71 }),
72 );
73
74 expect(created.name).toContain("/grpcRoutes/");
75 expect(created.grpcRouteId).toEqual(expect.any(String));
76 expect(created.location).toEqual("global");
77 expect(created.hostnames).toContain("alchemy-grpc.example.com");
78 expect(created.description).toEqual("grpc route a");
79 expect(created.labels).toMatchObject({ env: "test" });
80 expect(created.createTime).toEqual(expect.any(String));
81
82 const fetched = yield* networkservices.getProjectsLocationsGrpcRoutes({
83 name: created.name,
84 });
85 expect(fetched.name).toEqual(created.name);
86 expect(fetched.description).toEqual("grpc route a");
87 expect(fetched.labels?.env).toEqual("test");
88 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
89 true,
90 );
91
92 const updated = yield* stack.deploy(
93 Effect.gen(function* () {
94 return yield* GCP.NetworkServices.GrpcRoute("Api", {
95 grpcRouteId: created.grpcRouteId,
96 location: "global",
97 hostnames: ["alchemy-grpc.example.com"],
98 description: "grpc route b",
99 labels: { env: "prod", role: "grpc" },
100 rules: [
101 {
102 matches: [
103 {
104 method: {
105 grpcService: "api.v1.Orders",
106 grpcMethod: "Get",
107 },
108 },
109 ],
110 action: {
111 retryPolicy: {
112 retryConditions: ["unavailable"],
113 numRetries: 2,
114 },
115 },
116 },
117 ],
118 });
119 }),
120 );
121
122 expect(updated.name).toEqual(created.name);
123 expect(updated.description).toEqual("grpc route b");
124 expect(updated.labels).toMatchObject({ env: "prod", role: "grpc" });
125 expect(updated.rules[0]?.action?.retryPolicy?.numRetries).toEqual(2);
126
127 const refetched = yield* networkservices.getProjectsLocationsGrpcRoutes({
128 name: created.name,
129 });
130 expect(refetched.description).toEqual("grpc route b");
131 expect(refetched.labels?.env).toEqual("prod");
132 expect(refetched.labels?.role).toEqual("grpc");
133
134 yield* stack.destroy();
135
136 const gone = yield* waitUntilGone(created.name);
137 expect(gone).toEqual("gone");
138 }).pipe(logLevel),
139 {
140 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
141 timeout: 90_000,
142 },
143 );