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 | // The Schema Registry API refuses every call until a Kafka cluster exists in |
| 14 | // the region (`SchemaRegistryRequiresCluster`), so lifecycle tests deploy a |
| 15 | // cluster first and make the registry depend on it. Clusters take ~30 minutes. |
| 16 | const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST; |
| 17 | |
| 18 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 19 | |
| 20 | const waitUntilGone = (name: string) => |
| 21 | kafka.getProjectsLocationsSchemaRegistries({ name }).pipe( |
| 22 | Effect.as("found" as const), |
| 23 | Effect.catchTag(["NotFound", "SchemaRegistryRequiresCluster"], () => |
| 24 | Effect.succeed("gone" as const), |
| 25 | ), |
| 26 | Effect.repeat({ |
| 27 | schedule: Schedule.spaced("1 second"), |
| 28 | until: (status) => status === "gone", |
| 29 | times: 10, |
| 30 | }), |
| 31 | ); |
| 32 | |
| 33 | test.provider( |
| 34 | "getProjectsLocationsSchemaRegistries on a missing registry fails with a typed tag", |
| 35 | (stack) => |
| 36 | Effect.gen(function* () { |
| 37 | const { project } = yield* GcpEnvironment.current; |
| 38 | |
| 39 | yield* stack.destroy(); |
| 40 | |
| 41 | const error = yield* Effect.flip( |
| 42 | kafka.getProjectsLocationsSchemaRegistries({ |
| 43 | name: `projects/${project}/locations/us-central1/schemaRegistries/alchemy_missing_registry`, |
| 44 | }), |
| 45 | ); |
| 46 | // Without a cluster in the region every call is refused; with one |
| 47 | // (other suites create them concurrently) the registry is just missing. |
| 48 | expect(["SchemaRegistryRequiresCluster", "NotFound"]).toContain(error._tag); |
| 49 | |
| 50 | yield* stack.destroy(); |
| 51 | }).pipe(logLevel), |
| 52 | { |
| 53 | tags: ["provider:gcp", "provider:gcp:managedkafka", "live"], |
| 54 | timeout: 90_000, |
| 55 | }, |
| 56 | ); |
| 57 | |
| 58 | test.provider.skipIf(!runLifecycle)( |
| 59 | "create, refresh, and delete a schema registry", |
| 60 | (stack) => |
| 61 | Effect.gen(function* () { |
| 62 | yield* stack.destroy(); |
| 63 | |
| 64 | const deployed = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | const cluster = yield* GCP.ManagedKafka.Cluster("Brokers", { |
| 67 | location: "us-central1", |
| 68 | }); |
| 69 | const registry = yield* GCP.ManagedKafka.SchemaRegistry("Schemas", { |
| 70 | location: cluster.location, |
| 71 | }); |
| 72 | return { cluster, registry }; |
| 73 | }), |
| 74 | ); |
| 75 | const created = deployed.registry; |
| 76 | |
| 77 | expect(created.name).toContain("/schemaRegistries/"); |
| 78 | expect(created.schemaRegistryId).toEqual(expect.any(String)); |
| 79 | expect(created.location).toEqual("us-central1"); |
| 80 | |
| 81 | const fetched = yield* kafka.getProjectsLocationsSchemaRegistries({ |
| 82 | name: created.name, |
| 83 | }); |
| 84 | expect(fetched.name).toEqual(created.name); |
| 85 | |
| 86 | const updated = yield* stack.deploy( |
| 87 | Effect.gen(function* () { |
| 88 | const cluster = yield* GCP.ManagedKafka.Cluster("Brokers", { |
| 89 | clusterId: deployed.cluster.clusterId, |
| 90 | location: "us-central1", |
| 91 | }); |
| 92 | return yield* GCP.ManagedKafka.SchemaRegistry("Schemas", { |
| 93 | schemaRegistryId: created.schemaRegistryId, |
| 94 | location: cluster.location, |
| 95 | }); |
| 96 | }), |
| 97 | ); |
| 98 | expect(updated.name).toEqual(created.name); |
| 99 | |
| 100 | yield* stack.destroy(); |
| 101 | |
| 102 | const gone = yield* waitUntilGone(created.name); |
| 103 | expect(gone).toEqual("gone"); |
| 104 | }).pipe(logLevel, withKafkaClusterSlot), |
| 105 | { |
| 106 | tags: ["provider:gcp", "provider:gcp:managedkafka", "live"], |
| 107 | timeout: 10_800_000, |
| 108 | retry: 0, |
| 109 | }, |
| 110 | ); |