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

main
ts 92 lines 3.35 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as networksecurity from "@distilled.cloud/gcp/networksecurity_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (name: string) =>
14 networksecurity.getProjectsLocationsBackendAuthenticationConfigs({ name }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 test.provider(
25 "create, update, and delete a backend authentication config",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const created = yield* stack.deploy(
31 Effect.gen(function* () {
32 return yield* GCP.NetworkSecurity.BackendAuthenticationConfig("BackendTls", {
33 wellKnownRoots: "PUBLIC_ROOTS",
34 description: "backend auth a",
35 labels: { env: "test" },
36 });
37 }),
38 );
39
40 expect(created.name).toContain("/backendAuthenticationConfigs/");
41 expect(created.name).toContain("/locations/global/");
42 expect(created.backendAuthenticationConfigId).toEqual(expect.any(String));
43 expect(created.location).toEqual("global");
44 expect(created.wellKnownRoots).toEqual("PUBLIC_ROOTS");
45 expect(created.description).toEqual("backend auth a");
46 expect(created.labels).toMatchObject({ env: "test" });
47 expect(created.createTime).toEqual(expect.any(String));
48
49 const fetched = yield* networksecurity.getProjectsLocationsBackendAuthenticationConfigs({
50 name: created.name,
51 });
52 expect(fetched.name).toEqual(created.name);
53 expect(fetched.labels?.env).toEqual("test");
54 expect(fetched.wellKnownRoots).toEqual("PUBLIC_ROOTS");
55 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
56 true,
57 );
58
59 const updated = yield* stack.deploy(
60 Effect.gen(function* () {
61 return yield* GCP.NetworkSecurity.BackendAuthenticationConfig("BackendTls", {
62 backendAuthenticationConfigId: created.backendAuthenticationConfigId,
63 wellKnownRoots: "PUBLIC_ROOTS",
64 description: "backend auth b",
65 labels: { env: "prod", role: "backend-tls" },
66 });
67 }),
68 );
69
70 expect(updated.name).toEqual(created.name);
71 expect(updated.description).toEqual("backend auth b");
72 expect(updated.labels).toMatchObject({
73 env: "prod",
74 role: "backend-tls",
75 });
76
77 const refetched = yield* networksecurity.getProjectsLocationsBackendAuthenticationConfigs({
78 name: created.name,
79 });
80 expect(refetched.description).toEqual("backend auth b");
81 expect(refetched.labels?.env).toEqual("prod");
82
83 yield* stack.destroy();
84
85 const gone = yield* waitUntilGone(created.name);
86 expect(gone).toEqual("gone");
87 }).pipe(logLevel),
88 {
89 tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
90 timeout: 90_000,
91 },
92 );