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

main
ts 108 lines 3.63 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.getProjectsLocationsConnectClusters({ 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 "getProjectsLocationsConnectClusters 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.getProjectsLocationsConnectClusters({
39 name: `projects/${project}/locations/us-central1/connectClusters/alchemy-missing-connect`,
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 kafka connect cluster",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const created = yield* stack.deploy(
59 Effect.gen(function* () {
60 const cluster = yield* GCP.ManagedKafka.Cluster("Brokers", {
61 location: "us-central1",
62 labels: { env: "test" },
63 });
64 const connect = yield* GCP.ManagedKafka.ConnectCluster("Connect", {
65 kafkaCluster: cluster.name,
66 labels: { env: "test" },
67 });
68 return { cluster, connect };
69 }),
70 );
71
72 expect(created.connect.name).toContain("/connectClusters/");
73 expect(created.connect.kafkaCluster).toEqual(created.cluster.name);
74
75 const fetched = yield* kafka.getProjectsLocationsConnectClusters({
76 name: created.connect.name,
77 });
78 expect(fetched.name).toEqual(created.connect.name);
79
80 const updated = yield* stack.deploy(
81 Effect.gen(function* () {
82 const cluster = yield* GCP.ManagedKafka.Cluster("Brokers", {
83 clusterId: created.cluster.clusterId,
84 location: "us-central1",
85 labels: { env: "test" },
86 });
87 const connect = yield* GCP.ManagedKafka.ConnectCluster("Connect", {
88 connectClusterId: created.connect.connectClusterId,
89 kafkaCluster: cluster.name,
90 labels: { env: "prod" },
91 });
92 return { cluster, connect };
93 }),
94 );
95 expect(updated.connect.connectClusterId).toEqual(created.connect.connectClusterId);
96 expect(updated.connect.labels).toMatchObject({ env: "prod" });
97
98 yield* stack.destroy();
99
100 const gone = yield* waitUntilGone(created.connect.name);
101 expect(gone).toEqual("gone");
102 }).pipe(logLevel, withKafkaClusterSlot),
103 {
104 tags: ["provider:gcp", "provider:gcp:managedkafka", "live"],
105 timeout: 10_800_000,
106 retry: 0,
107 },
108 );