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

main
ts 129 lines 4.12 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as ssm from "@distilled.cloud/gcp/securesourcemanager_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { currentProject, logLevel, missingPullRequestOf, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 ssm
13 .getProjectsLocationsRepositoriesPullRequestsPullRequestComments({
14 name,
15 })
16 .pipe(
17 Effect.as("found" as const),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.repeat({
20 schedule: Schedule.spaced("2 seconds"),
21 until: (status) => status === "gone",
22 times: 10,
23 }),
24 );
25
26 test.provider(
27 "getProjectsLocationsRepositoriesPullRequestsPullRequestComments on a missing comment fails with a typed tag",
28 (stack) =>
29 Effect.gen(function* () {
30 const project = yield* currentProject;
31 const missingPullRequest = missingPullRequestOf(project);
32 yield* stack.destroy();
33
34 const error = yield* Effect.flip(
35 ssm.getProjectsLocationsRepositoriesPullRequestsPullRequestComments({
36 name: `${missingPullRequest}/pullRequestComments/12345`,
37 }),
38 );
39 expect(error._tag).toEqual("NotFound");
40
41 yield* stack.destroy();
42 }).pipe(logLevel),
43 {
44 tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"],
45 timeout: 90_000,
46 },
47 );
48
49 test.provider(
50 "create against a missing pull request is rejected with a typed tag",
51 (stack) =>
52 Effect.gen(function* () {
53 const project = yield* currentProject;
54 const missingPullRequest = missingPullRequestOf(project);
55 yield* stack.destroy();
56
57 const error = yield* Effect.flip(
58 stack.deploy(
59 Effect.gen(function* () {
60 return yield* GCP.SecureSourceManager.RepositoriesPullRequestsPullRequestComment(
61 "Note",
62 {
63 pullRequest: missingPullRequest,
64 comment: { body: "looks good" },
65 },
66 );
67 }),
68 ),
69 );
70 expect(error._tag).toEqual("NotFound");
71
72 yield* stack.destroy();
73 }).pipe(logLevel),
74 {
75 tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"],
76 timeout: 90_000,
77 },
78 );
79
80 test.provider.skipIf(!runLifecycle)(
81 "create, update, and delete a pull request comment",
82 (stack) =>
83 Effect.gen(function* () {
84 const project = yield* currentProject;
85 const missingPullRequest = missingPullRequestOf(project);
86 yield* stack.destroy();
87
88 const created = yield* stack.deploy(
89 Effect.gen(function* () {
90 return yield* GCP.SecureSourceManager.RepositoriesPullRequestsPullRequestComment("Note", {
91 pullRequest:
92 process.env.GCP_TEST_SECURE_SOURCE_MANAGER_PULL_REQUEST ?? missingPullRequest,
93 comment: { body: "looks good" },
94 });
95 }),
96 );
97
98 expect(created.name).toContain("/pullRequestComments/");
99 expect(created.comment?.body).toEqual("looks good");
100
101 const fetched = yield* ssm.getProjectsLocationsRepositoriesPullRequestsPullRequestComments({
102 name: created.name,
103 });
104 expect(fetched.name).toEqual(created.name);
105 expect(fetched.comment?.body).toEqual("looks good");
106
107 const updated = yield* stack.deploy(
108 Effect.gen(function* () {
109 return yield* GCP.SecureSourceManager.RepositoriesPullRequestsPullRequestComment("Note", {
110 pullRequest: created.pullRequest,
111 commentId: created.commentId,
112 comment: { body: "looks good after the rebase" },
113 });
114 }),
115 );
116
117 expect(updated.commentId).toEqual(created.commentId);
118 expect(updated.comment?.body).toEqual("looks good after the rebase");
119
120 yield* stack.destroy();
121
122 const gone = yield* waitUntilGone(created.name);
123 expect(gone).toEqual("gone");
124 }).pipe(logLevel),
125 {
126 tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"],
127 timeout: 120_000,
128 },
129 );