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 AVRO = JSON.stringify({ |
| 21 | type: "record", |
| 22 | name: "Shipment", |
| 23 | namespace: "alchemy", |
| 24 | fields: [{ name: "id", type: "string" }], |
| 25 | }); |
| 26 | |
| 27 | const waitUntilGone = (name: string) => |
| 28 | kafka.getProjectsLocationsSchemaRegistriesContextsSubjectsVersions({ name }).pipe( |
| 29 | Effect.as("found" as const), |
| 30 | // Once the parent registry is deleted too, the path itself is invalid. |
| 31 | Effect.catchTag( |
| 32 | ["NotFound", "SchemaRegistryRequiresCluster", "SchemaRegistryPathNotFound"], |
| 33 | () => Effect.succeed("gone" as const), |
| 34 | ), |
| 35 | Effect.repeat({ |
| 36 | schedule: Schedule.spaced("1 second"), |
| 37 | until: (status) => status === "gone", |
| 38 | times: 10, |
| 39 | }), |
| 40 | ); |
| 41 | |
| 42 | test.provider( |
| 43 | "getProjectsLocationsSchemaRegistriesContextsSubjectsVersions on a missing version fails with a typed tag", |
| 44 | (stack) => |
| 45 | Effect.gen(function* () { |
| 46 | const { project } = yield* GcpEnvironment.current; |
| 47 | |
| 48 | yield* stack.destroy(); |
| 49 | |
| 50 | const error = yield* Effect.flip( |
| 51 | kafka.getProjectsLocationsSchemaRegistriesContextsSubjectsVersions({ |
| 52 | name: `projects/${project}/locations/us-central1/schemaRegistries/alchemy_missing/contexts/dev/subjects/missing/versions/1`, |
| 53 | }), |
| 54 | ); |
| 55 | // Without a cluster in the region every call is refused; with one |
| 56 | // (other suites create them concurrently) the registry is just missing. |
| 57 | expect(["SchemaRegistryRequiresCluster", "NotFound"]).toContain(error._tag); |
| 58 | |
| 59 | yield* stack.destroy(); |
| 60 | }).pipe(logLevel), |
| 61 | { |
| 62 | tags: ["provider:gcp", "provider:gcp:managedkafka", "live"], |
| 63 | timeout: 90_000, |
| 64 | }, |
| 65 | ); |
| 66 | |
| 67 | test.provider.skipIf(!runLifecycle)( |
| 68 | "create and delete a context-scoped schema subject version", |
| 69 | (stack) => |
| 70 | Effect.gen(function* () { |
| 71 | yield* stack.destroy(); |
| 72 | |
| 73 | const created = yield* stack.deploy( |
| 74 | Effect.gen(function* () { |
| 75 | const cluster = yield* GCP.ManagedKafka.Cluster("Brokers", { |
| 76 | location: "us-central1", |
| 77 | }); |
| 78 | const registry = yield* GCP.ManagedKafka.SchemaRegistry("Schemas", { |
| 79 | location: cluster.location, |
| 80 | }); |
| 81 | const version = yield* GCP.ManagedKafka.SchemaRegistriesContextsSubjectsVersion( |
| 82 | "ShipSchema", |
| 83 | { |
| 84 | schemaRegistry: registry.name, |
| 85 | context: "dev", |
| 86 | subject: "shipments", |
| 87 | schemaType: "AVRO", |
| 88 | schema: AVRO, |
| 89 | }, |
| 90 | ); |
| 91 | return { registry, version }; |
| 92 | }), |
| 93 | ); |
| 94 | |
| 95 | expect(created.version.name).toContain("/contexts/"); |
| 96 | expect(created.version.context).toEqual("dev"); |
| 97 | expect(created.version.subject).toEqual("shipments"); |
| 98 | expect(created.version.version).toBeGreaterThan(0); |
| 99 | |
| 100 | const fetched = yield* kafka.getProjectsLocationsSchemaRegistriesContextsSubjectsVersions({ |
| 101 | name: created.version.name, |
| 102 | }); |
| 103 | // The API qualifies context-scoped subjects as `:.{context}:{subject}`. |
| 104 | expect(fetched.subject).toEqual(":.dev:shipments"); |
| 105 | |
| 106 | yield* stack.destroy(); |
| 107 | |
| 108 | const gone = yield* waitUntilGone(created.version.name); |
| 109 | expect(gone).toEqual("gone"); |
| 110 | }).pipe(logLevel, withKafkaClusterSlot), |
| 111 | { |
| 112 | tags: ["provider:gcp", "provider:gcp:managedkafka", "live"], |
| 113 | timeout: 10_800_000, |
| 114 | retry: 0, |
| 115 | }, |
| 116 | ); |