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

main
ts 122 lines 4.31 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 clouddeploy from "@distilled.cloud/gcp/clouddeploy_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 waitUntilGone = (name: string) =>
15 clouddeploy.getProjectsLocationsDeliveryPipelines({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsDeliveryPipelines on a missing pipeline fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30
31 yield* stack.destroy();
32
33 const error = yield* Effect.flip(
34 clouddeploy.getProjectsLocationsDeliveryPipelines({
35 name: `projects/${project}/locations/us-central1/deliveryPipelines/alchemy-missing-pipeline`,
36 }),
37 );
38 expect(error._tag).toEqual("NotFound");
39
40 yield* stack.destroy();
41 }).pipe(logLevel),
42 {
43 tags: ["provider:gcp", "provider:gcp:clouddeploy", "live"],
44 timeout: 90_000,
45 },
46 );
47
48 test.provider(
49 "create, update, and delete a delivery pipeline",
50 (stack) =>
51 Effect.gen(function* () {
52 const { project } = yield* GcpEnvironment.current;
53
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 const target = yield* GCP.CloudDeploy.Target("Staging", {
59 run: {
60 location: `projects/${project}/locations/us-central1`,
61 },
62 labels: { env: "test" },
63 });
64 const pipeline = yield* GCP.CloudDeploy.DeliveryPipeline("App", {
65 serialPipeline: { stages: [{ targetId: target.targetId }] },
66 description: "alchemy-test-pipeline",
67 labels: { env: "test" },
68 });
69 return { target, pipeline };
70 }),
71 );
72
73 expect(created.pipeline.name).toContain("/deliveryPipelines/");
74 expect(created.pipeline.deliveryPipelineId).toEqual(expect.any(String));
75 expect(created.pipeline.location).toEqual("us-central1");
76 expect(created.pipeline.description).toEqual("alchemy-test-pipeline");
77 expect(created.pipeline.serialPipeline?.stages?.[0]?.targetId).toEqual(
78 created.target.targetId,
79 );
80 expect(created.pipeline.labels).toMatchObject({ env: "test" });
81 expect(created.pipeline.suspended).toEqual(false);
82
83 const fetched = yield* clouddeploy.getProjectsLocationsDeliveryPipelines({
84 name: created.pipeline.name,
85 });
86 expect(fetched.name).toEqual(created.pipeline.name);
87 expect(fetched.description).toEqual("alchemy-test-pipeline");
88 expect(fetched.labels?.env).toEqual("test");
89
90 const updated = yield* stack.deploy(
91 Effect.gen(function* () {
92 const target = yield* GCP.CloudDeploy.Target("Staging", {
93 targetId: created.target.targetId,
94 run: {
95 location: `projects/${project}/locations/us-central1`,
96 },
97 labels: { env: "test" },
98 });
99 const pipeline = yield* GCP.CloudDeploy.DeliveryPipeline("App", {
100 deliveryPipelineId: created.pipeline.deliveryPipelineId,
101 serialPipeline: { stages: [{ targetId: target.targetId }] },
102 description: "alchemy-prod-pipeline",
103 labels: { env: "prod", role: "deploy" },
104 });
105 return pipeline;
106 }),
107 );
108
109 expect(updated.name).toEqual(created.pipeline.name);
110 expect(updated.description).toEqual("alchemy-prod-pipeline");
111 expect(updated.labels).toMatchObject({ env: "prod", role: "deploy" });
112
113 yield* stack.destroy();
114
115 const gone = yield* waitUntilGone(created.pipeline.name);
116 expect(gone).toEqual("gone");
117 }).pipe(logLevel),
118 {
119 tags: ["provider:gcp", "provider:gcp:clouddeploy", "live"],
120 timeout: 90_000,
121 },
122 );