@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 143 lines 5.23 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 eventarc from "@distilled.cloud/gcp/eventarc_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 // Enrollment depends on a Pipeline, whose create/update/delete LROs take
15 // over 15 minutes end to end.
16 const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST;
17 const LOCATION = "europe-west1";
18
19 const waitUntilGone = (name: string) =>
20 eventarc.getProjectsLocationsEnrollments({ name }).pipe(
21 Effect.as("found" as const),
22 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
23 Effect.repeat({
24 schedule: Schedule.spaced("2 seconds"),
25 until: (status) => status === "gone",
26 times: 10,
27 }),
28 );
29
30 test.provider(
31 "getProjectsLocationsEnrollments on a missing enrollment fails with a typed tag",
32 (stack) =>
33 Effect.gen(function* () {
34 const { project } = yield* GcpEnvironment.current;
35 yield* stack.destroy();
36
37 const error = yield* Effect.flip(
38 eventarc.getProjectsLocationsEnrollments({
39 name: `projects/${project}/locations/${LOCATION}/enrollments/alchemy-missing-enrollment`,
40 }),
41 );
42 expect(error._tag).toEqual("NotFound");
43
44 yield* stack.destroy();
45 }).pipe(logLevel),
46 { tags: ["provider:gcp", "provider:gcp:eventarc", "live"], timeout: 90_000 },
47 );
48
49 test.provider.skipIf(!runLifecycle)(
50 "create, update, and delete an Eventarc enrollment",
51 (stack) =>
52 Effect.gen(function* () {
53 yield* stack.destroy();
54
55 const created = yield* stack.deploy(
56 Effect.gen(function* () {
57 const bus = yield* GCP.Eventarc.MessageBus("Events", {
58 location: LOCATION,
59 labels: { env: "test" },
60 });
61 const pipeline = yield* GCP.Eventarc.Pipeline("Forward", {
62 location: LOCATION,
63 destinations: [{ messageBus: bus.name }],
64 labels: { env: "test" },
65 });
66 const enrollment = yield* GCP.Eventarc.Enrollment("All", {
67 location: LOCATION,
68 messageBus: bus.name,
69 destination: pipeline.name,
70 celMatch: "true",
71 displayName: "all events",
72 labels: { env: "test" },
73 });
74 return { bus, pipeline, enrollment };
75 }),
76 );
77
78 expect(created.enrollment.name).toContain("/enrollments/");
79 expect(created.enrollment.enrollmentId).toEqual(expect.any(String));
80 expect(created.enrollment.location).toEqual(LOCATION);
81 expect(created.enrollment.celMatch).toEqual("true");
82 expect(created.enrollment.messageBus).toEqual(created.bus.name);
83 expect(created.enrollment.destination).toEqual(created.pipeline.name);
84 expect(created.enrollment.labels).toMatchObject({ env: "test" });
85
86 const fetched = yield* eventarc.getProjectsLocationsEnrollments({
87 name: created.enrollment.name,
88 });
89 expect(fetched.name).toEqual(created.enrollment.name);
90 expect(fetched.labels?.env).toEqual("test");
91 expect(fetched.celMatch).toEqual("true");
92
93 const updated = yield* stack.deploy(
94 Effect.gen(function* () {
95 const bus = yield* GCP.Eventarc.MessageBus("Events", {
96 messageBusId: created.bus.messageBusId,
97 location: LOCATION,
98 labels: { env: "test" },
99 });
100 const pipeline = yield* GCP.Eventarc.Pipeline("Forward", {
101 pipelineId: created.pipeline.pipelineId,
102 location: LOCATION,
103 destinations: [{ messageBus: bus.name }],
104 labels: { env: "test" },
105 });
106 return yield* GCP.Eventarc.Enrollment("All", {
107 enrollmentId: created.enrollment.enrollmentId,
108 location: LOCATION,
109 messageBus: bus.name,
110 destination: pipeline.name,
111 celMatch: "message.type == 'google.cloud.pubsub.topic.v1.messagePublished'",
112 displayName: "pubsub only",
113 labels: { env: "prod", role: "enrollment" },
114 });
115 }),
116 );
117
118 expect(updated.name).toEqual(created.enrollment.name);
119 expect(updated.enrollmentId).toEqual(created.enrollment.enrollmentId);
120 expect(updated.displayName).toEqual("pubsub only");
121 expect(updated.labels).toMatchObject({
122 env: "prod",
123 role: "enrollment",
124 });
125 expect(updated.celMatch).toContain("messagePublished");
126
127 const refetched = yield* eventarc.getProjectsLocationsEnrollments({
128 name: created.enrollment.name,
129 });
130 expect(refetched.labels?.env).toEqual("prod");
131 expect(refetched.labels?.role).toEqual("enrollment");
132 expect(refetched.displayName).toEqual("pubsub only");
133
134 yield* stack.destroy();
135
136 const gone = yield* waitUntilGone(created.enrollment.name);
137 expect(gone).toEqual("gone");
138 }).pipe(logLevel),
139 {
140 tags: ["provider:gcp", "provider:gcp:eventarc", "live"],
141 timeout: 2_400_000,
142 },
143 );