Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GitHubPullRequestProvider.test.ts

949 lines30.2 KB

1import { describe, expect, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as Redacted from "effect/Redacted";
5import * as TestClock from "effect/testing/TestClock";
6import type { PullRequestReaction } from "@t3tools/contracts";
7​
8import * as GitHubRequestPolicy from "./GitHubRequestPolicy.ts";
9import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
10import * as GitHubPullRequestApi from "./GitHubPullRequestApi.ts";
11import type {
12 GitHubPullRequestCore,
13 GitHubPullRequestSearchItem,
14} from "./gitHubPullRequestJson.ts";
15import { gitHubViewerPermissions, loginAvatarUrl, make } from "./GitHubPullRequestProvider.ts";
16import type { GitHubReviewThreadComments } from "./gitHubPullRequestJson.ts";
17​
18const coreFields = {
19 reviewRequestTeams: [],
20 checksTruncated: false,
21 comparison: { behindBy: 0, viewerCanUpdate: true },
22 viewerAccess: {
23 canWrite: true,
24 canTriage: true,
25 canUpdate: true,
26 didAuthor: false,
27 mergeCapabilities: { merge: true, squash: true, rebase: true },
28 autoMergeAllowed: true,
29 },
30};
31​
32it.effect("maps credential verification failures without relabeling operation failures", () =>
33 Effect.gen(function* () {
34 let verificationFails = true;
35 let operations = 0;
36 const provider = yield* make.pipe(
37 Effect.provide(
38 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
39 revalidateChecks: (_input, read) => read,
40 withVerifiedCredential: (_input, use) =>
41 verificationFails
42 ? Effect.fail(
43 new GitHubPullRequestApi.GitHubViewerLoginUnavailableError({
44 cwd: "/w",
45 }),
46 )
47 : use({ accountId: "123", viewer: "viewer", credentialFingerprint: "fingerprint" }),
48 }),
49 ),
50 );
51 const verify = provider.withVerifiedCredential;
52 if (verify === undefined)
53 return yield* Effect.die("credential verification was not implemented");
54 const input = { cwd: "/w", host: "github.com" };
55 const operation = () =>
56 Effect.sync(() => {
57 operations++;
58 }).pipe(Effect.andThen(Effect.fail("operation-failed")));
59 expect(yield* verify(input, operation).pipe(Effect.flip)).toMatchObject({
60 _tag: "PullRequestProviderError",
61 operation: "routeIdentity",
62 });
63 expect(operations).toBe(0);
64 verificationFails = false;
65 expect(yield* verify(input, operation).pipe(Effect.flip)).toBe("operation-failed");
66 expect(operations).toBe(1);
67 }),
68);
69​
70it.effect("advertises standalone branch deletion for source repository writers", () =>
71 Effect.gen(function* () {
72 let action: string | undefined;
73 const provider = yield* make.pipe(
74 Effect.provide(
75 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
76 runPullRequestAction: (input) =>
77 Effect.sync(() => {
78 action = input.action;
79 }),
80 }),
81 ),
82 );
83 expect(provider.capabilities.deleteBranch).toBe(true);
84 expect(provider.capabilities.actions).toContain("delete-branch");
85 yield* provider.runAction({
86 cwd: "/w",
87 repository: "acme/web",
88 host: "github.com",
89 number: 7,
90 action: "delete-branch",
91 });
92 expect(action).toBe("delete-branch");
93 const access = {
94 canWrite: false,
95 canTriage: false,
96 canUpdate: false,
97 didAuthor: false,
98 canDeleteBranch: true,
99 autoMergeAllowed: true,
100 };
101 expect(gitHubViewerPermissions(access).actions).toContain("delete-branch");
102 expect(
103 gitHubViewerPermissions({
104 ...access,
105 canWrite: true,
106 didAuthor: true,
107 canDeleteBranch: false,
108 }).actions,
109 ).not.toContain("delete-branch");
110 }),
111);
112​
113describe("gitHubViewerPermissions", () => {
114 it("offers everything to a viewer who can write to the repository", () => {
115 expect(
116 gitHubViewerPermissions({
117 canWrite: true,
118 canDeleteBranch: true,
119 canTriage: true,
120 canUpdate: true,
121 didAuthor: false,
122 autoMergeAllowed: true,
123 }),
124 ).toEqual({
125 actions: [
126 "delete-branch",
127 "merge",
128 "enable-auto-merge",
129 "disable-auto-merge",
130 "revert",
131 "approve-workflows",
132 "ready",
133 "draft",
134 "close",
135 "reopen",
136 ],
137 comment: true,
138 resolve: true,
139 stackRebase: true,
140 verdicts: ["comment", "approve", "request-changes"],
141 requestReviewers: true,
142 labels: true,
143 });
144 });
145​
146 it("leaves a passer-by on a repository they can only read nothing but the review", () => {
147 expect(
148 gitHubViewerPermissions({
149 canWrite: false,
150 canTriage: false,
151 canUpdate: false,
152 didAuthor: false,
153 autoMergeAllowed: true,
154 }),
155 ).toEqual({
156 actions: [],
157 comment: true,
158 resolve: false,
159 verdicts: ["comment", "approve", "request-changes"],
160 requestReviewers: false,
161 labels: false,
162 });
163 });
164​
165 it("lets a triager label without letting them merge or ask for a review", () => {
166 const permissions = gitHubViewerPermissions({
167 canWrite: false,
168 canTriage: true,
169 canUpdate: false,
170 didAuthor: false,
171 autoMergeAllowed: true,
172 });
173 expect(permissions.labels).toBe(true);
174 expect(permissions.requestReviewers).toBe(false);
175 expect(permissions.actions).toEqual([]);
176 });
177​
178 it("keeps an author's own pull request theirs to close, with read access and no more", () => {
179 expect(
180 gitHubViewerPermissions({
181 canWrite: false,
182 canTriage: false,
183 canUpdate: true,
184 didAuthor: true,
185 autoMergeAllowed: true,
186 }),
187 ).toEqual({
188 actions: ["ready", "draft", "close", "reopen"],
189 comment: true,
190 resolve: true,
191 verdicts: ["comment"],
192 requestReviewers: false,
193 labels: false,
194 });
195 });
196​
197 it.effect("uses the permissions carried by the core read without a second request", () =>
198 Effect.gen(function* () {
199 const provider = yield* make;
200 const detail = yield* provider.getChangeRequest({
201 cwd: "/w",
202 repository: "acme/web",
203 host: "github.com",
204 number: 7,
205 });
206​
207 expect(detail.viewerPermissions).toEqual({
208 actions: ["ready", "draft", "close", "reopen"],
209 comment: true,
210 resolve: false,
211 verdicts: ["comment", "approve", "request-changes"],
212 requestReviewers: false,
213 labels: false,
214 });
215 expect(detail.workflowApprovalsRequired).toBeUndefined();
216 expect(detail.checks).toContainEqual({
217 name: "Workflow approval status",
218 status: "action-required",
219 description: "GitHub could not determine whether workflows are awaiting approval.",
220 url: null,
221 });
222 for (const fingerprint of ["broad", "restricted", "broad"]) {
223 const scoped = yield* provider
224 .getChangeRequest({
225 cwd: "/w",
226 repository: "acme/web",
227 host: "github.com",
228 number: 7,
229 })
230 .pipe(
231 Effect.provideService(GitHubRequestPolicy.PinnedGitHubCredential, {
232 host: "github.com",
233 token: Redacted.make("credential"),
234 credentialFingerprint: fingerprint,
235 }),
236 );
237 expect(scoped.mergeCapabilities.squash).toBe(fingerprint !== "restricted");
238 }
239 }).pipe(
240 Effect.provide(
241 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
242 revalidateChecks: (_input, read) => read,
243 getPullRequestDetail: () =>
244 Effect.succeed({
245 ...coreFields,
246 comparison: null,
247 viewerAccess: { ...coreFields.viewerAccess, canWrite: false, canTriage: false },
248 authorId: null,
249 number: 7,
250 title: "Pull request 7",
251 url: "https://github.com/acme/web/pull/7",
252 author: null,
253 isCrossRepository: true,
254 headRepositoryOwner: null,
255 headBranch: "feat/page",
256 baseBranch: "main",
257 state: "open" as const,
258 isDraft: false,
259 mergeability: "mergeable" as const,
260 reviewDecision: null,
261 additions: 1,
262 deletions: 1,
263 createdAt: "2026-07-01T00:00:00Z",
264 updatedAt: "2026-07-02T00:00:00Z",
265 reviewRequestLogins: [],
266 hasTeamReviewRequest: false,
267 checksState: null,
268 labels: [],
269 body: "",
270 changedFiles: 1,
271 mergedAt: null,
272 closedAt: null,
273 checks: [],
274 comments: [],
275 commits: [],
276 }).pipe(
277 Effect.flatMap((detail) =>
278 GitHubRequestPolicy.PinnedGitHubCredential.pipe(
279 Effect.map((credential) => ({
280 ...detail,
281 viewerAccess: {
282 ...detail.viewerAccess,
283 mergeCapabilities: {
284 ...detail.viewerAccess.mergeCapabilities,
285 squash: credential?.credentialFingerprint !== "restricted",
286 },
287 },
288 })),
289 ),
290 ),
291 ),
292 }),
293 ),
294 ),
295 );
296​
297 it.effect("keeps fork workflows awaiting approval out of the passing state", () =>
298 Effect.gen(function* () {
299 const provider = yield* make;
300 const detail = yield* provider.getChangeRequest({
301 cwd: "/w",
302 repository: "acme/web",
303 host: "github.com",
304 number: 7,
305 });
306​
307 const readChecks = provider.getChangeRequestChecks;
308 if (readChecks === undefined) return yield* Effect.die("checks read missing");
309 expect(
310 yield* readChecks({ cwd: "/w", repository: "acme/web", host: "github.com", number: 7 }),
311 ).toEqual({ state: detail.state, checks: detail.checks });
312 expect(detail.workflowApprovalsRequired).toBe(1);
313 expect(detail.checks).toEqual([
314 {
315 name: "manual gate",
316 status: "action-required",
317 description: null,
318 url: "https://example.com/manual-gate",
319 },
320 {
321 name: "build",
322 status: "success",
323 description: null,
324 url: null,
325 },
326 {
327 name: "contributor tests",
328 status: "action-required",
329 description: "A maintainer must approve this workflow before it can run.",
330 url: "https://github.com/acme/web/actions/runs/123",
331 },
332 ]);
333 }).pipe(
334 Effect.provide(
335 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
336 revalidateChecks: (_input, read) => read,
337 getPullRequestDetail: () =>
338 Effect.succeed({
339 ...coreFields,
340 authorId: null,
341 number: 7,
342 title: "Pull request 7",
343 url: "https://github.com/acme/web/pull/7",
344 author: null,
345 isCrossRepository: true,
346 headRepositoryOwner: "octocat",
347 headSha: "abc123",
348 headBranch: "feat/page",
349 baseBranch: "main",
350 state: "open",
351 isDraft: false,
352 mergeability: "mergeable",
353 reviewDecision: null,
354 additions: 1,
355 deletions: 1,
356 createdAt: "2026-07-01T00:00:00Z",
357 updatedAt: "2026-07-02T00:00:00Z",
358 reviewRequestLogins: [],
359 hasTeamReviewRequest: false,
360 checksState: "passing",
361 labels: [],
362 body: "",
363 changedFiles: 1,
364 mergedAt: null,
365 closedAt: null,
366 checks: [
367 {
368 name: "manual gate",
369 status: "action-required",
370 description: null,
371 url: "https://example.com/manual-gate",
372 },
373 { name: "build", status: "success", description: null, url: null },
374 ],
375 comments: [],
376 commits: [],
377 }),
378 listWorkflowRunsRequiringApproval: () =>
379 Effect.succeed([
380 {
381 id: 123,
382 name: "contributor tests",
383 url: "https://github.com/acme/web/actions/runs/123",
384 },
385 ]),
386 getViewerAccess: () =>
387 Effect.succeed({
388 canWrite: true,
389 canTriage: true,
390 canUpdate: true,
391 didAuthor: false,
392 mergeCapabilities: { merge: true, squash: true, rebase: true },
393 autoMergeAllowed: true,
394 }),
395 }),
396 ),
397 ),
398 );
399});
400​
401const openDetail = {
402 ...coreFields,
403 authorId: null,
404 number: 7,
405 title: "Pull request 7",
406 url: "https://github.com/acme/web/pull/7",
407 author: null,
408 isCrossRepository: true,
409 headRepositoryOwner: "acme",
410 headSha: "abc123",
411 headBranch: "feat/page",
412 baseBranch: "main",
413 state: "open" as const,
414 isDraft: false,
415 mergeability: "mergeable" as const,
416 reviewDecision: null,
417 additions: 1,
418 deletions: 1,
419 createdAt: "2026-07-01T00:00:00Z",
420 updatedAt: "2026-07-02T00:00:00Z",
421 reviewRequestLogins: [],
422 hasTeamReviewRequest: false,
423 checksState: null,
424 labels: [],
425 body: "",
426 changedFiles: 1,
427 mergedAt: null,
428 closedAt: null,
429 checks: [],
430 comments: [],
431 commits: [],
432};
433​
434it.effect("does not classify same-repository gates as fork workflow approvals", () =>
435 Effect.gen(function* () {
436 const provider = yield* make;
437 const detail = yield* provider.getChangeRequest({
438 cwd: "/w",
439 repository: "acme/web",
440 host: "github.com",
441 number: 7,
442 });
443​
444 expect(detail.workflowApprovalsRequired).toBe(0);
445 expect(detail.checks).toEqual([]);
446 }).pipe(
447 Effect.provide(
448 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
449 revalidateChecks: (_input, read) => read,
450 getPullRequestDetail: () => Effect.succeed({ ...openDetail, isCrossRepository: false }),
451 listWorkflowRunsRequiringApproval: () =>
452 Effect.die("same-repository pull requests must not probe fork workflow approvals"),
453 getViewerAccess: () =>
454 Effect.succeed({
455 canWrite: true,
456 canTriage: true,
457 canUpdate: true,
458 didAuthor: false,
459 mergeCapabilities: { merge: true, squash: true, rebase: true },
460 autoMergeAllowed: true,
461 }),
462 }),
463 ),
464 ),
465);
466​
467it.effect("keeps an unsafe workflow approval scope visible as unknown", () =>
468 Effect.gen(function* () {
469 const provider = yield* make;
470 const detail = yield* provider.getChangeRequest({
471 cwd: "/w",
472 repository: "acme/web",
473 host: "github.com",
474 number: 7,
475 });
476​
477 expect(detail.workflowApprovalsRequired).toBeUndefined();
478 expect(detail.checks).toEqual([
479 {
480 name: "Workflow approval status",
481 status: "action-required",
482 description: "GitHub could not determine whether workflows are awaiting approval.",
483 url: null,
484 },
485 ]);
486 }).pipe(
487 Effect.provide(
488 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
489 revalidateChecks: (_input, read) => read,
490 getPullRequestDetail: () => Effect.succeed(openDetail),
491 listWorkflowRunsRequiringApproval: () =>
492 Effect.fail(
493 new GitHubPullRequestApi.GitHubWorkflowApprovalRefusedError({
494 cwd: "/w",
495 number: 7,
496 reason: "head-not-unique",
497 observedCount: 2,
498 limit: 1_000,
499 }),
500 ),
501 getViewerAccess: () =>
502 Effect.succeed({
503 canWrite: true,
504 canTriage: true,
505 canUpdate: true,
506 didAuthor: false,
507 mergeCapabilities: { merge: true, squash: true, rebase: true },
508 autoMergeAllowed: true,
509 }),
510 }),
511 ),
512 ),
513);
514​
515describe("getViewerPermissions", () => {
516 const access = {
517 canWrite: true,
518 canTriage: true,
519 canUpdate: true,
520 didAuthor: false,
521 mergeCapabilities: { merge: true, squash: true, rebase: true },
522 autoMergeAllowed: true,
523 };
524​
525 const layerWithDetail = (
526 detail: Effect.Effect<GitHubPullRequestCore, GitHubPullRequestApi.GitHubPullRequestApiError>,
527 onDetail: (allowReserve: boolean) => void = () => {},
528 ) =>
529 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
530 revalidateChecks: (_input, read) => read,
531 getPullRequestDetail: () =>
532 SourceControlRateLimit.Interactive.pipe(
533 Effect.tap((allowReserve) => Effect.sync(() => onDetail(allowReserve))),
534 Effect.flatMap(() => detail),
535 ),
536 getViewerAccess: () => Effect.die("Unexpected access read"),
537 });
538​
539 it.effect("answers access and update-branch from the one detail read", () =>
540 Effect.gen(function* () {
541 const provider = yield* make;
542 const permissions = yield* provider.getViewerPermissions({
543 cwd: "/w",
544 repository: "acme/web",
545 host: "github.com",
546 number: 7,
547 });
548​
549 expect(permissions.actions).toContain("merge");
550 expect(permissions.actions).toContain("update-branch");
551 expect(permissions.updateMethods).toEqual(["merge", "rebase"]);
552 }).pipe(
553 Effect.provide(
554 layerWithDetail(
555 Effect.succeed({ ...openDetail, comparison: { behindBy: 3, viewerCanUpdate: true } }),
556 ),
557 ),
558 ),
559 );
560​
561 it.effect("still answers from the light access read when the detail read fails", () =>
562 Effect.gen(function* () {
563 const provider = yield* make;
564 const permissions = yield* provider.getViewerPermissions({
565 cwd: "/w",
566 repository: "acme/web",
567 host: "github.com",
568 number: 7,
569 });
570 expect(permissions.actions).toContain("merge");
571 expect(permissions.actions).not.toContain("update-branch");
572 }).pipe(
573 Effect.provide(
574 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
575 revalidateChecks: (_input, read) => read,
576 getPullRequestDetail: () =>
577 Effect.fail(
578 new GitHubPullRequestApi.GitHubPullRequestReadError({
579 cwd: "/w",
580 operation: "getPullRequestDetail",
581 cause: new Error("head changed"),
582 }),
583 ),
584 getViewerAccess: () => Effect.succeed(access),
585 }),
586 ),
587 ),
588 );
589​
590 it.effect("withholds update-branch where GitHub could not compare the branch", () =>
591 Effect.gen(function* () {
592 const provider = yield* make;
593 const permissions = yield* provider.getViewerPermissions({
594 cwd: "/w",
595 repository: "acme/web",
596 host: "github.com",
597 number: 7,
598 });
599​
600 expect(permissions.actions).not.toContain("update-branch");
601 expect(permissions.updateMethods).toBeUndefined();
602 expect(permissions.actions).toContain("merge");
603 }).pipe(Effect.provide(layerWithDetail(Effect.succeed({ ...openDetail, comparison: null })))),
604 );
605});
606​
607describe("getChangeRequest commits", () => {
608 const baseDetail = {
609 authorId: null,
610 number: 7,
611 title: "Pull request 7",
612 url: "https://github.com/acme/web/pull/7",
613 author: null,
614 headBranch: "feat/page",
615 baseBranch: "main",
616 state: "open" as const,
617 isDraft: false,
618 mergeability: "mergeable" as const,
619 additions: 1,
620 deletions: 1,
621 createdAt: "2026-07-01T00:00:00Z",
622 updatedAt: "2026-07-02T00:00:00Z",
623 reviewRequestLogins: [],
624 hasTeamReviewRequest: false,
625 checksState: null,
626 labels: [],
627 body: "",
628 changedFiles: 1,
629 mergedAt: null,
630 closedAt: null,
631 checks: [],
632 comments: [],
633 };
634​
635 const baseThreadComments = {
636 comments: [],
637 dismissalsByReviewId: new Map<string, string>(),
638 reviewThreads: [],
639 commentCount: 0,
640 truncated: false,
641 reviewThreadsTruncated: false,
642 reactions: [],
643 reactionsById: new Map<string, ReadonlyArray<PullRequestReaction>>(),
644 editedAtById: new Map<string, string>(),
645 reviewers: [],
646 avatarsByLogin: new Map<string, string>(),
647 botLogins: new Set<string>(),
648 viewer: { canUpdate: true, didAuthor: false },
649 };
650​
651 const layerWith = (commits: GitHubReviewThreadComments["commits"]) =>
652 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
653 revalidateChecks: (_input, read) => read,
654 getPullRequestActivity: () =>
655 Effect.succeed({
656 author: baseDetail.author,
657 comments: baseDetail.comments,
658 commits: [
659 {
660 oid: "graphql-newest",
661 messageHeadline: "Activity metadata",
662 committedDate: "2026-07-06T00:00:00Z",
663 additions: 18,
664 deletions: 7,
665 authors: [],
666 },
667 {
668 oid: "view-oldest",
669 messageHeadline: "gh pr view's oldest commit",
670 committedDate: "2026-01-01T00:00:00Z",
671 authors: [],
672 },
673 ],
674 }),
675 listReviewThreadComments: () => Effect.succeed({ ...baseThreadComments, commits }),
676 });
677​
678 it.effect("prefers the GraphQL commits, which are the newest, over the gh view list", () =>
679 Effect.gen(function* () {
680 const provider = yield* make;
681 const detail = yield* provider.getChangeRequestActivity({
682 cwd: "/w",
683 repository: "acme/web",
684 host: "github.com",
685 number: 7,
686 });
687​
688 expect(detail.commits.map((commit) => commit.oid)).toEqual(["graphql-newest"]);
689 expect(detail.commits[0]).toMatchObject({
690 messageHeadline: "the newest commit gh pr view drops",
691 additions: 18,
692 deletions: 7,
693 });
694 }).pipe(
695 Effect.provide(
696 layerWith([
697 {
698 oid: "graphql-newest",
699 messageHeadline: "the newest commit gh pr view drops",
700 committedDate: "2026-07-06T00:00:00Z",
701 authors: [],
702 },
703 ]),
704 ),
705 ),
706 );
707​
708 it.effect("falls back to the gh view list when the GraphQL read has no commits", () =>
709 Effect.gen(function* () {
710 const provider = yield* make;
711 const detail = yield* provider.getChangeRequestActivity({
712 cwd: "/w",
713 repository: "acme/web",
714 host: "github.com",
715 number: 7,
716 });
717​
718 expect(detail.commits.map((commit) => commit.oid)).toEqual(["graphql-newest", "view-oldest"]);
719 }).pipe(Effect.provide(layerWith([]))),
720 );
721});
722​
723describe("getChangeRequestActivity dismissed reviews", () => {
724 const dismissedReview = (body: string) => ({
725 id: "PRR_1",
726 kind: "review" as const,
727 author: { login: "macroscopeapp", name: null, avatarUrl: null },
728 body,
729 createdAt: "2026-07-03T00:00:00Z",
730 url: null,
731 path: null,
732 reviewState: "DISMISSED",
733 });
734 const threadComments: GitHubReviewThreadComments = {
735 comments: [],
736 dismissalsByReviewId: new Map([["PRR_1", "Dismissing prior approval to re-evaluate 9b66581"]]),
737 reviewThreads: [],
738 commentCount: 0,
739 truncated: false,
740 reviewThreadsTruncated: false,
741 reactions: [],
742 reactionsById: new Map(),
743 editedAtById: new Map([["PRR_1", "2026-07-04T00:00:00Z"]]),
744 reviewers: [],
745 avatarsByLogin: new Map(),
746 botLogins: new Set(["macroscopeapp"]),
747 commits: [],
748 viewer: { canUpdate: true, didAuthor: false },
749 };
750 const layerFor = (body: string) =>
751 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
752 revalidateChecks: (_input, read) => read,
753 getPullRequestActivity: () =>
754 Effect.succeed({ author: null, comments: [dismissedReview(body)], commits: [] }),
755 listReviewThreadComments: () => Effect.succeed(threadComments),
756 });
757 const readActivity = Effect.gen(function* () {
758 const provider = yield* make;
759 return yield* provider.getChangeRequestActivity({
760 cwd: "/w",
761 repository: "acme/web",
762 host: "github.com",
763 number: 7,
764 });
765 });
766​
767 it.effect("fills a marker-only dismissed review with the timeline's reason", () =>
768 readActivity.pipe(
769 Effect.map((activity) => {
770 expect(activity.comments[0]?.body).toBe("Dismissing prior approval to re-evaluate 9b66581");
771 expect(activity.comments[0]?.author?.isBot).toBe(true);
772 expect(activity.comments[0]?.editedAt).toBe("2026-07-04T00:00:00Z");
773 }),
774 Effect.provide(layerFor("<!-- Macroscope (Approvability) review body marker -->")),
775 ),
776 );
777});
778​
779describe("loginAvatarUrl", () => {
780 it("refuses anything that is not a login, rather than building a URL out of it", () => {
781 for (const login of ["../../etc", "a b", "-leading", "x".repeat(40), ""]) {
782 expect(loginAvatarUrl(login, "github.com")).toBeNull();
783 }
784 });
785});
786​
787describe("listChangeRequestsAcross", () => {
788 const searched = (repository: string): GitHubPullRequestSearchItem => ({
789 repository,
790 number: 1,
791 title: "Change",
792 url: `https://github.com/${repository}/pull/1`,
793 author: null,
794 authorId: null,
795 headBranch: "feature",
796 baseBranch: "main",
797 state: "open" as const,
798 isDraft: false,
799 mergeability: "mergeable" as const,
800 additions: 0,
801 deletions: 0,
802 createdAt: "2026-07-01T00:00:00Z",
803 updatedAt: "2026-07-02T00:00:00Z",
804 reviewRequestLogins: [],
805 hasTeamReviewRequest: false,
806 labels: [],
807 reviewDecision: null,
808 checksState: null,
809 });
810 const across = {
811 cwd: "/w",
812 host: "github.com",
813 repositories: ["acme/web", "acme/docs"],
814 state: "open" as const,
815 involvement: "all" as const,
816 viewer: "viewer",
817 limit: 50,
818 };
819 type Search = Parameters<
820 GitHubPullRequestApi.GitHubPullRequestApi["Service"]["searchPullRequests"]
821 >[0];
822 // Pages answer in turn; a one-repository check for any pull request answers from `covered`.
823 const providerAnswering = (input: {
824 readonly pages: Array<GitHubPullRequestApi.GitHubPullRequestSearchBatch>;
825 readonly covered?: (repository: string) => boolean;
826 readonly checks?: Array<string>;
827 }) =>
828 make.pipe(
829 Effect.provide(
830 Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
831 searchPullRequests: (search: Search) => {
832 if (search.state !== "all") return Effect.succeed(input.pages.shift()!);
833 const repository = search.repositories[0]!;
834 input.checks?.push(repository);
835 return input.covered === undefined
836 ? Effect.fail(
837 new GitHubPullRequestApi.GitHubViewerLoginUnavailableError({ cwd: search.cwd }),
838 )
839 : Effect.succeed({
840 items: input.covered(repository) ? [searched(repository)] : [],
841 truncated: false,
842 });
843 },
844 }),
845 ),
846 Effect.map((provider) => provider.listChangeRequestsAcross!),
847 );
848​
849 it.effect("believes silence about a repository search covers, and checks it once", () =>
850 Effect.gen(function* () {
851 const checks: Array<string> = [];
852 const read = yield* providerAnswering({
853 pages: [
854 { items: [searched("acme/web")], truncated: false },
855 { items: [searched("acme/web")], truncated: false },
856 ],
857 covered: () => true,
858 checks,
859 });
860 expect((yield* read(across)).unresolved).toEqual([]);
861 expect((yield* read(across)).unresolved).toEqual([]);
862 expect(checks).toEqual(["acme/docs"]);
863 }),
864 );
865​
866 it.effect("leaves a repository search does not cover to be read on its own", () =>
867 Effect.gen(function* () {
868 const read = yield* providerAnswering({
869 pages: [{ items: [searched("acme/web")], truncated: false }],
870 covered: (repository) => repository !== "acme/docs",
871 });
872 expect((yield* read(across)).unresolved).toEqual(["acme/docs"]);
873 }),
874 );
875​
876 it.effect("does not check a repository a page had rows for", () =>
877 Effect.gen(function* () {
878 const checks: Array<string> = [];
879 const read = yield* providerAnswering({
880 pages: [
881 { items: [searched("acme/web"), searched("acme/docs")], truncated: false },
882 { items: [searched("acme/web")], truncated: false },
883 ],
884 covered: () => true,
885 checks,
886 });
887 yield* read(across);
888 expect((yield* read(across)).unresolved).toEqual([]);
889 expect(checks).toEqual([]);
890 }),
891 );
892​
893 it.effect("vouches for no silent repository in a truncated first slice", () =>
894 Effect.gen(function* () {
895 const read = yield* providerAnswering({
896 pages: [{ items: [searched("acme/web")], truncated: true }],
897 covered: () => true,
898 });
899 expect((yield* read(across)).unresolved).toEqual(["acme/docs"]);
900 }),
901 );
902​
903 it.effect("past the first slice, believes a covered repository and not an uncovered one", () =>
904 Effect.gen(function* () {
905 const read = yield* providerAnswering({
906 pages: [
907 { items: [searched("acme/web")], truncated: true },
908 { items: [searched("acme/web")], truncated: true },
909 ],
910 covered: (repository) => repository !== "acme/renamed",
911 });
912 const later = { ...across, cursor: { updatedBefore: "2026-07-02T00:00:00Z", delivered: 1 } };
913 expect((yield* read(later)).unresolved).toEqual([]);
914 expect(
915 (yield* read({ ...later, repositories: ["acme/web", "acme/renamed"] })).unresolved,
916 ).toEqual(["acme/renamed"]);
917 }),
918 );
919​
920 it.effect("asks again after a failed check, and after coverage has had time to change", () =>
921 Effect.gen(function* () {
922 const checks: Array<string> = [];
923 const failing = yield* providerAnswering({
924 pages: [
925 { items: [searched("acme/web")], truncated: false },
926 { items: [searched("acme/web")], truncated: false },
927 ],
928 checks,
929 });
930 expect((yield* failing(across)).unresolved).toEqual(["acme/docs"]);
931 expect((yield* failing(across)).unresolved).toEqual(["acme/docs"]);
932 expect(checks).toEqual(["acme/docs", "acme/docs"]);
933​
934 checks.length = 0;
935 const read = yield* providerAnswering({
936 pages: [
937 { items: [searched("acme/web")], truncated: false },
938 { items: [searched("acme/web")], truncated: false },
939 ],
940 covered: () => true,
941 checks,
942 });
943 yield* read(across);
944 yield* TestClock.adjust("61 minutes");
945 yield* read(across);
946 expect(checks).toEqual(["acme/docs", "acme/docs"]);
947 }),
948 );
949});