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

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