The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 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.getProjectsLocationsClustersTopics({ name }).pipe( |
| 20 | Effect.as("found" as const), |
| 21 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 22 | Effect.repeat({ |
| 23 | schedule: Schedule.spaced("1 second"), |
| 24 | until: (status) => status === "gone", |
| 25 | times: 10, |
| 26 | }), |
| 27 | ); |
| 28 | |
| 29 | test.provider( |
| 30 | "getProjectsLocationsClustersTopics on a missing topic 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.getProjectsLocationsClustersTopics({ |
| 39 | name: `projects/${project}/locations/us-central1/clusters/alchemy-missing/topics/alchemy-missing`, |
| 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 topic", |
| 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 topic = yield* GCP.ManagedKafka.ClustersTopic("Events", { |
| 65 | cluster: cluster.name, |
| 66 | partitionCount: 1, |
| 67 | replicationFactor: 3, |
| 68 | configs: { "retention.ms": "86400000" }, |
| 69 | }); |
| 70 | return { cluster, topic }; |
| 71 | }), |
| 72 | ); |
| 73 | |
| 74 | expect(created.topic.name).toContain("/topics/"); |
| 75 | expect(created.topic.partitionCount).toEqual(1); |
| 76 | |
| 77 | const fetched = yield* kafka.getProjectsLocationsClustersTopics({ |
| 78 | name: created.topic.name, |
| 79 | }); |
| 80 | expect(fetched.name).toEqual(created.topic.name); |
| 81 | |
| 82 | const updated = yield* stack.deploy( |
| 83 | Effect.gen(function* () { |
| 84 | const cluster = yield* GCP.ManagedKafka.Cluster("Brokers", { |
| 85 | clusterId: created.cluster.clusterId, |
| 86 | location: "us-central1", |
| 87 | labels: { env: "test" }, |
| 88 | }); |
| 89 | const topic = yield* GCP.ManagedKafka.ClustersTopic("Events", { |
| 90 | cluster: cluster.name, |
| 91 | topicId: created.topic.topicId, |
| 92 | partitionCount: 3, |
| 93 | replicationFactor: 3, |
| 94 | configs: { "retention.ms": "172800000" }, |
| 95 | }); |
| 96 | return { cluster, topic }; |
| 97 | }), |
| 98 | ); |
| 99 | expect(updated.topic.topicId).toEqual(created.topic.topicId); |
| 100 | expect(updated.topic.partitionCount).toEqual(3); |
| 101 | |
| 102 | yield* stack.destroy(); |
| 103 | |
| 104 | const gone = yield* waitUntilGone(created.topic.name); |
| 105 | expect(gone).toEqual("gone"); |
| 106 | }).pipe(logLevel, withKafkaClusterSlot), |
| 107 | { |
| 108 | tags: ["provider:gcp", "provider:gcp:managedkafka", "live"], |
| 109 | timeout: 10_800_000, |
| 110 | retry: 0, |
| 111 | }, |
| 112 | ); |