@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 129 lines 4.18 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.getProjectsLocationsClustersAcls({ 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 "getProjectsLocationsClustersAcls on a missing acl 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.getProjectsLocationsClustersAcls({
39 name: `projects/${project}/locations/us-central1/clusters/alchemy-missing/acls/cluster`,
40 }),
41 );
42 // GCP has answered a missing parent cluster with both 404 NOT_FOUND
43 // and 400 FAILED_PRECONDITION "cluster must exist"
44 // (AclClusterNotFound); both are typed.
45 expect(["NotFound", "AclClusterNotFound"]).toContain(error._tag);
46
47 yield* stack.destroy();
48 }).pipe(logLevel),
49 {
50 tags: ["provider:gcp", "provider:gcp:managedkafka", "live"],
51 timeout: 90_000,
52 },
53 );
54
55 test.provider.skipIf(!runLifecycle)(
56 "create, update, and delete a kafka acl",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 const cluster = yield* GCP.ManagedKafka.Cluster("Brokers", {
64 location: "us-central1",
65 labels: { env: "test" },
66 });
67 const acl = yield* GCP.ManagedKafka.ClustersAcl("OrdersAcl", {
68 cluster: cluster.name,
69 aclId: "topic/orders",
70 aclEntries: [
71 {
72 principal: "User:*",
73 operation: "DESCRIBE",
74 permissionType: "ALLOW",
75 host: "*",
76 },
77 ],
78 });
79 return { cluster, acl };
80 }),
81 );
82
83 expect(created.acl.name).toContain("/acls/");
84 expect(created.acl.aclId).toEqual("topic/orders");
85 expect(created.acl.aclEntries.length).toBeGreaterThan(0);
86
87 const fetched = yield* kafka.getProjectsLocationsClustersAcls({
88 name: created.acl.name,
89 });
90 expect(fetched.name).toEqual(created.acl.name);
91
92 const updated = yield* stack.deploy(
93 Effect.gen(function* () {
94 const cluster = yield* GCP.ManagedKafka.Cluster("Brokers", {
95 clusterId: created.cluster.clusterId,
96 location: "us-central1",
97 labels: { env: "test" },
98 });
99 const acl = yield* GCP.ManagedKafka.ClustersAcl("OrdersAcl", {
100 cluster: cluster.name,
101 aclId: "topic/orders",
102 aclEntries: [
103 {
104 principal: "User:*",
105 operation: "READ",
106 permissionType: "ALLOW",
107 host: "*",
108 },
109 ],
110 });
111 return { cluster, acl };
112 }),
113 );
114 expect(updated.acl.aclId).toEqual("topic/orders");
115 expect(
116 updated.acl.aclEntries.some((entry) => (entry.operation ?? "").toUpperCase() === "READ"),
117 ).toEqual(true);
118
119 yield* stack.destroy();
120
121 const gone = yield* waitUntilGone(created.acl.name);
122 expect(gone).toEqual("gone");
123 }).pipe(logLevel, withKafkaClusterSlot),
124 {
125 tags: ["provider:gcp", "provider:gcp:managedkafka", "live"],
126 timeout: 10_800_000,
127 retry: 0,
128 },
129 );