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

main
ts 96 lines 3.47 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 compute from "@distilled.cloud/gcp/compute_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 = (project: string, name: string) =>
14 compute.getBackendServices({ project, backendService: 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 service",
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.Compute.BackendService("Web", {
33 protocol: "HTTP",
34 loadBalancingScheme: "EXTERNAL",
35 description: "alchemy test",
36 labels: { env: "test" },
37 });
38 }),
39 );
40
41 expect(created.name).toEqual(expect.any(String));
42 expect(created.protocol).toEqual("HTTP");
43 expect(created.loadBalancingScheme).toEqual("EXTERNAL");
44 expect(created.timeoutSec).toEqual(30);
45 expect(created.enableCDN).toEqual(false);
46 expect(created.description).toEqual("alchemy test");
47 expect(created.labels).toMatchObject({ env: "test" });
48
49 const fetched = yield* compute.getBackendServices({
50 project: created.project,
51 backendService: created.name,
52 });
53 expect(fetched.name).toEqual(created.name);
54 expect(fetched.protocol).toEqual("HTTP");
55 expect(fetched.description).toContain("alchemy-id=");
56 expect(fetched.description).toContain("env=test");
57 expect(fetched.description).toContain("alchemy test");
58 expect(fetched.timeoutSec).toEqual(30);
59
60 const updated = yield* stack.deploy(
61 Effect.gen(function* () {
62 return yield* GCP.Compute.BackendService("Web", {
63 name: created.name,
64 protocol: "HTTP",
65 loadBalancingScheme: "EXTERNAL",
66 timeoutSec: 60,
67 enableCDN: true,
68 description: "updated",
69 labels: { env: "prod", role: "lb" },
70 });
71 }),
72 );
73
74 expect(updated.name).toEqual(created.name);
75 expect(updated.timeoutSec).toEqual(60);
76 expect(updated.enableCDN).toEqual(true);
77 expect(updated.description).toEqual("updated");
78 expect(updated.labels).toMatchObject({ env: "prod", role: "lb" });
79
80 const fetchedUpdate = yield* compute.getBackendServices({
81 project: created.project,
82 backendService: created.name,
83 });
84 expect(fetchedUpdate.timeoutSec).toEqual(60);
85 expect(fetchedUpdate.enableCDN).toEqual(true);
86 expect(fetchedUpdate.description).toContain("env=prod");
87 expect(fetchedUpdate.description).toContain("role=lb");
88 expect(fetchedUpdate.description).toContain("updated");
89
90 yield* stack.destroy();
91
92 const gone = yield* waitUntilGone(created.project, created.name);
93 expect(gone).toEqual("gone");
94 }).pipe(logLevel),
95 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 120_000 },
96 );