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

main
ts 102 lines 3.32 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 kafka from "@distilled.cloud/gcp/managedkafka_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { withKafkaClusterSlot } from "./quota.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 // Kafka and Connect clusters take ~30 minutes to provision.
16 const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST;
17
18 const waitUntilGone = (name: string) =>
19 kafka.getProjectsLocationsClusters({ name }).pipe(
20 Effect.as("found" as const),
21 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
22 Effect.repeat({
23 schedule: Schedule.spaced("2 seconds"),
24 until: (status) => status === "gone",
25 times: 10,
26 }),
27 );
28
29 test.provider(
30 "getProjectsLocationsClusters on a missing cluster fails with a typed tag",
31 (stack) =>
32 Effect.gen(function* () {
33 const { project } = yield* GcpEnvironment.current;
34
35 yield* stack.destroy();
36
37 const error = yield* Effect.flip(
38 kafka.getProjectsLocationsClusters({
39 name: `projects/${project}/locations/us-central1/clusters/alchemy-missing-kafka`,
40 }),
41 );
42 expect(error._tag).toEqual("NotFound");
43
44 yield* stack.destroy();
45 }).pipe(logLevel),
46 {
47 tags: ["provider:gcp", "provider:gcp:managedkafka", "live"],
48 timeout: 90_000,
49 },
50 );
51
52 test.provider.skipIf(!runLifecycle)(
53 "create, update, and delete a managed kafka cluster",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const created = yield* stack.deploy(
59 Effect.gen(function* () {
60 return yield* GCP.ManagedKafka.Cluster("Brokers", {
61 location: "us-central1",
62 capacityConfig: { vcpuCount: 3, memoryBytes: 3_221_225_472 },
63 labels: { env: "test" },
64 });
65 }),
66 );
67
68 expect(created.name).toContain("/clusters/");
69 expect(created.state).toEqual("ACTIVE");
70 expect(created.labels).toMatchObject({ env: "test" });
71
72 const fetched = yield* kafka.getProjectsLocationsClusters({
73 name: created.name,
74 });
75 expect(fetched.name).toEqual(created.name);
76 expect(fetched.labels?.env).toEqual("test");
77
78 const updated = yield* stack.deploy(
79 Effect.gen(function* () {
80 return yield* GCP.ManagedKafka.Cluster("Brokers", {
81 clusterId: created.clusterId,
82 location: "us-central1",
83 capacityConfig: { vcpuCount: 3, memoryBytes: 3_221_225_472 },
84 rebalanceConfig: { mode: "AUTO_REBALANCE_ON_SCALE_UP" },
85 labels: { env: "prod" },
86 });
87 }),
88 );
89 expect(updated.clusterId).toEqual(created.clusterId);
90 expect(updated.labels).toMatchObject({ env: "prod" });
91
92 yield* stack.destroy();
93
94 const gone = yield* waitUntilGone(created.name);
95 expect(gone).toEqual("gone");
96 }).pipe(logLevel, withKafkaClusterSlot),
97 {
98 tags: ["provider:gcp", "provider:gcp:managedkafka", "live"],
99 timeout: 10_800_000,
100 retry: 0,
101 },
102 );