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

main
ts 117 lines 3.9 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.getProjectsLocationsMeshes({ 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 "getProjectsLocationsMeshes on a missing mesh 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.getProjectsLocationsMeshes({
34 name: `projects/${project}/locations/global/meshes/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 mesh",
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.Mesh("Sidecar", {
56 location: "global",
57 description: "mesh a",
58 labels: { env: "test" },
59 interceptionPort: 15001,
60 });
61 }),
62 );
63
64 expect(created.name).toContain("/meshes/");
65 expect(created.meshId).toEqual(expect.any(String));
66 expect(created.location).toEqual("global");
67 expect(created.description).toEqual("mesh a");
68 expect(created.interceptionPort).toEqual(15001);
69 expect(created.labels).toMatchObject({ env: "test" });
70 expect(created.createTime).toEqual(expect.any(String));
71
72 const fetched = yield* networkservices.getProjectsLocationsMeshes({
73 name: created.name,
74 });
75 expect(fetched.name).toEqual(created.name);
76 expect(fetched.description).toEqual("mesh a");
77 expect(fetched.interceptionPort).toEqual(15001);
78 expect(fetched.labels?.env).toEqual("test");
79 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
80 true,
81 );
82
83 const updated = yield* stack.deploy(
84 Effect.gen(function* () {
85 return yield* GCP.NetworkServices.Mesh("Sidecar", {
86 meshId: created.meshId,
87 location: "global",
88 description: "mesh b",
89 labels: { env: "prod", role: "mesh" },
90 interceptionPort: 15006,
91 });
92 }),
93 );
94
95 expect(updated.name).toEqual(created.name);
96 expect(updated.description).toEqual("mesh b");
97 expect(updated.interceptionPort).toEqual(15006);
98 expect(updated.labels).toMatchObject({ env: "prod", role: "mesh" });
99
100 const refetched = yield* networkservices.getProjectsLocationsMeshes({
101 name: created.name,
102 });
103 expect(refetched.description).toEqual("mesh b");
104 expect(refetched.interceptionPort).toEqual(15006);
105 expect(refetched.labels?.env).toEqual("prod");
106 expect(refetched.labels?.role).toEqual("mesh");
107
108 yield* stack.destroy();
109
110 const gone = yield* waitUntilGone(created.name);
111 expect(gone).toEqual("gone");
112 }).pipe(logLevel),
113 {
114 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
115 timeout: 90_000,
116 },
117 );