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

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