The best way to control Claude Code, Codex and more from any computer or phone

main
ts 113 lines 4.13 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 // ChannelConnection is created in a third-party provider project using
15 // a subscriber Channel activation token. The testing project is not an
16 // Eventarc SaaS partner; live create is gated.
17 const runLifecycle = !process.env.FAST && process.env.GCP_TEST_EVENTARC_PARTNER === "1";
18 const LOCATION = "us-central1";
19
20 const waitUntilGone = (name: string) =>
21 eventarc.getProjectsLocationsChannelConnections({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("2 seconds"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider(
32 "getProjectsLocationsChannelConnections on a missing connection fails with a typed tag",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36 yield* stack.destroy();
37
38 const error = yield* Effect.flip(
39 eventarc.getProjectsLocationsChannelConnections({
40 name: `projects/${project}/locations/${LOCATION}/channelConnections/alchemy-missing-connection`,
41 }),
42 );
43 expect(error._tag).toEqual("NotFound");
44
45 yield* stack.destroy();
46 }).pipe(logLevel),
47 { tags: ["provider:gcp", "provider:gcp:eventarc", "live"], timeout: 90_000 },
48 );
49
50 test.provider.skipIf(!runLifecycle)(
51 "create, update, and delete an Eventarc channel connection",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 const channel = yield* GCP.Eventarc.Channel("Events", {
59 location: LOCATION,
60 labels: { env: "test" },
61 });
62 const connection = yield* GCP.Eventarc.ChannelConnection("Partner", {
63 location: LOCATION,
64 channel: channel.name,
65 activationToken: channel.activationToken,
66 labels: { env: "test" },
67 });
68 return { channel, connection };
69 }),
70 );
71
72 expect(created.connection.name).toContain("/channelConnections/");
73 expect(created.connection.channelConnectionId).toEqual(expect.any(String));
74 expect(created.connection.location).toEqual(LOCATION);
75 expect(created.connection.channel).toEqual(created.channel.name);
76 expect(created.connection.labels).toMatchObject({ env: "test" });
77
78 const fetched = yield* eventarc.getProjectsLocationsChannelConnections({
79 name: created.connection.name,
80 });
81 expect(fetched.name).toEqual(created.connection.name);
82 expect(fetched.labels?.env).toEqual("test");
83 expect(fetched.channel).toEqual(created.channel.name);
84
85 const updated = yield* stack.deploy(
86 Effect.gen(function* () {
87 const channel = yield* GCP.Eventarc.Channel("Events", {
88 channelId: created.channel.channelId,
89 location: LOCATION,
90 labels: { env: "test" },
91 });
92 return yield* GCP.Eventarc.ChannelConnection("Partner", {
93 channelConnectionId: created.connection.channelConnectionId,
94 location: LOCATION,
95 channel: channel.name,
96 labels: { env: "prod", role: "connection" },
97 });
98 }),
99 );
100
101 expect(updated.channel).toEqual(created.channel.name);
102 expect(updated.labels).toMatchObject({
103 env: "prod",
104 role: "connection",
105 });
106
107 yield* stack.destroy();
108
109 const gone = yield* waitUntilGone(created.connection.name);
110 expect(gone).toEqual("gone");
111 }).pipe(logLevel),
112 { tags: ["provider:gcp", "provider:gcp:eventarc", "live"], timeout: 180_000 },
113 );