@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 111 lines 3.87 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 // 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: "Order",
23 namespace: "alchemy",
24 fields: [{ name: "id", type: "string" }],
25 });
26
27 const waitUntilGone = (name: string) =>
28 kafka.getProjectsLocationsSchemaRegistriesSubjectsVersions({ 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 "getProjectsLocationsSchemaRegistriesSubjectsVersions 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.getProjectsLocationsSchemaRegistriesSubjectsVersions({
52 name: `projects/${project}/locations/us-central1/schemaRegistries/alchemy_missing/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 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.SchemaRegistriesSubjectsVersion("OrderSchema", {
82 schemaRegistry: registry.name,
83 subject: "orders",
84 schemaType: "AVRO",
85 schema: AVRO,
86 });
87 return { registry, version };
88 }),
89 );
90
91 expect(created.version.name).toContain("/subjects/");
92 expect(created.version.subject).toEqual("orders");
93 expect(created.version.version).toBeGreaterThan(0);
94
95 const fetched = yield* kafka.getProjectsLocationsSchemaRegistriesSubjectsVersions({
96 name: created.version.name,
97 });
98 expect(fetched.subject).toEqual("orders");
99 expect(fetched.schema).toContain("Order");
100
101 yield* stack.destroy();
102
103 const gone = yield* waitUntilGone(created.version.name);
104 expect(gone).toEqual("gone");
105 }).pipe(logLevel, withKafkaClusterSlot),
106 {
107 tags: ["provider:gcp", "provider:gcp:managedkafka", "live"],
108 timeout: 10_800_000,
109 retry: 0,
110 },
111 );