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

GitHubPullRequestProvider.test.ts

787 lines24.7 KB

1import { describe, expect, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import type { PullRequestReaction } from "@t3tools/contracts";
5​
6import * as GitHubCli from "../sourceControl/GitHubCli.ts";
7import * as GitHubPullRequestCli from "./GitHubPullRequestCli.ts";
8import { gitHubViewerPermissions, loginAvatarUrl, make } from "./GitHubPullRequestProvider.ts";
9import type { GitHubReviewThreadComments } from "./gitHubPullRequestJson.ts";
10​
11it.effect("uses one narrow read for a linked pull request summary", () =>
12 Effect.gen(function* () {
13 let summaryReads = 0;
14 const provider = yield* make.pipe(
15 Effect.provide(
16 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
17 getPullRequestSummary: () =>
18 Effect.sync(() => {
19 summaryReads += 1;
20 return {
21 number: 7,
22 title: "Summary",
23 url: "https://github.com/acme/web/pull/7",
24 headBranch: "feat/summary",
25 baseBranch: "main",
26 state: "open" as const,
27 updatedAt: "2026-08-24T12:34:56.000Z",
28 };
29 }),
30 }),
31 ),
32 );
33​
34 const readSummary = provider.getChangeRequestSummary;
35 if (readSummary === undefined) return yield* Effect.die("summary read was not implemented");
36 const summary = yield* readSummary({
37 cwd: "/w",
38 repository: "acme/web",
39 host: "github.com",
40 number: 7,
41 });
42​
43 expect(summary.state).toBe("open");
44 expect(summaryReads).toBe(1);
45 }),
46);
47​
48describe("gitHubViewerPermissions", () => {
49 it("offers everything to a viewer who can write to the repository", () => {
50 expect(
51 gitHubViewerPermissions({
52 canWrite: true,
53 canTriage: true,
54 canUpdate: true,
55 didAuthor: false,
56 }),
57 ).toEqual({
58 // Arming a merge for later is the merge, so it travels with it.
59 actions: [
60 "merge",
61 "enable-auto-merge",
62 "disable-auto-merge",
63 "revert",
64 "approve-workflows",
65 "ready",
66 "draft",
67 "close",
68 "reopen",
69 ],
70 comment: true,
71 resolve: true,
72 verdicts: ["comment", "approve", "request-changes"],
73 requestReviewers: true,
74 labels: true,
75 });
76 });
77​
78 it("leaves a passer-by on a repository they can only read nothing but the review", () => {
79 // Every open-source pull request somebody else opened: GitHub says no to all five actions
80 // and to resolving, and yes to commenting and to every verdict.
81 expect(
82 gitHubViewerPermissions({
83 canWrite: false,
84 canTriage: false,
85 canUpdate: false,
86 didAuthor: false,
87 }),
88 ).toEqual({
89 actions: [],
90 comment: true,
91 resolve: false,
92 verdicts: ["comment", "approve", "request-changes"],
93 // Asking somebody else to review is the one thing read access never stretches to.
94 requestReviewers: false,
95 labels: false,
96 });
97 });
98​
99 it("lets a triager label without letting them merge or ask for a review", () => {
100 const permissions = gitHubViewerPermissions({
101 canWrite: false,
102 canTriage: true,
103 canUpdate: false,
104 didAuthor: false,
105 });
106 expect(permissions.labels).toBe(true);
107 expect(permissions.requestReviewers).toBe(false);
108 expect(permissions.actions).toEqual([]);
109 });
110​
111 it("keeps an author's own pull request theirs to close, with read access and no more", () => {
112 expect(
113 gitHubViewerPermissions({
114 canWrite: false,
115 canTriage: false,
116 canUpdate: true,
117 didAuthor: true,
118 }),
119 ).toEqual({
120 // Merging is the one thing writing is needed for, now or later; the rest an author may do.
121 actions: ["ready", "draft", "close", "reopen"],
122 comment: true,
123 resolve: true,
124 // GitHub refuses an author's approval of their own change, so the page does not offer one.
125 verdicts: ["comment"],
126 requestReviewers: false,
127 labels: false,
128 });
129 });
130​
131 it.effect("uses the small viewer-access read for core permissions", () =>
132 Effect.gen(function* () {
133 const provider = yield* make;
134 const detail = yield* provider.getChangeRequest({
135 cwd: "/w",
136 repository: "acme/web",
137 host: "github.com",
138 number: 7,
139 });
140​
141 expect(detail.viewerPermissions).toEqual({
142 actions: ["ready", "draft", "close", "reopen"],
143 comment: true,
144 resolve: false,
145 verdicts: ["comment", "approve", "request-changes"],
146 requestReviewers: false,
147 labels: false,
148 });
149 expect(detail.workflowApprovalsRequired).toBeUndefined();
150 expect(detail.checks).toContainEqual({
151 name: "Workflow approval status",
152 status: "action-required",
153 description: "GitHub could not determine whether workflows are awaiting approval.",
154 url: null,
155 });
156 }).pipe(
157 Effect.provide(
158 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
159 getPullRequestDetail: () =>
160 Effect.succeed({
161 authorId: null,
162 number: 7,
163 title: "Pull request 7",
164 url: "https://github.com/acme/web/pull/7",
165 author: null,
166 isCrossRepository: true,
167 headRepositoryOwner: null,
168 headBranch: "feat/page",
169 baseBranch: "main",
170 state: "open",
171 isDraft: false,
172 mergeability: "mergeable",
173 reviewDecision: null,
174 additions: 1,
175 deletions: 1,
176 createdAt: "2026-07-01T00:00:00Z",
177 updatedAt: "2026-07-02T00:00:00Z",
178 reviewRequestLogins: [],
179 hasTeamReviewRequest: false,
180 checksState: null,
181 labels: [],
182 body: "",
183 changedFiles: 1,
184 mergedAt: null,
185 closedAt: null,
186 checks: [],
187 comments: [],
188 commits: [],
189 }),
190 getRepositoryAccess: () =>
191 Effect.succeed({
192 canWrite: false,
193 mergeCapabilities: { merge: true, squash: true, rebase: true },
194 }),
195 getViewerAccess: () =>
196 Effect.succeed({
197 canWrite: false,
198 canTriage: false,
199 canUpdate: true,
200 didAuthor: false,
201 }),
202 }),
203 ),
204 ),
205 );
206​
207 it.effect("keeps fork workflows awaiting approval out of the passing state", () =>
208 Effect.gen(function* () {
209 const provider = yield* make;
210 const detail = yield* provider.getChangeRequest({
211 cwd: "/w",
212 repository: "acme/web",
213 host: "github.com",
214 number: 7,
215 });
216​
217 expect(detail.workflowApprovalsRequired).toBe(1);
218 expect(detail.checks).toEqual([
219 {
220 name: "manual gate",
221 status: "action-required",
222 description: null,
223 url: "https://example.com/manual-gate",
224 },
225 {
226 name: "build",
227 status: "success",
228 description: null,
229 url: null,
230 },
231 {
232 name: "contributor tests",
233 status: "action-required",
234 description: "A maintainer must approve this workflow before it can run.",
235 url: "https://github.com/acme/web/actions/runs/123",
236 },
237 ]);
238 }).pipe(
239 Effect.provide(
240 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
241 getPullRequestDetail: () =>
242 Effect.succeed({
243 authorId: null,
244 number: 7,
245 title: "Pull request 7",
246 url: "https://github.com/acme/web/pull/7",
247 author: null,
248 isCrossRepository: true,
249 headRepositoryOwner: "octocat",
250 headSha: "abc123",
251 headBranch: "feat/page",
252 baseBranch: "main",
253 state: "open",
254 isDraft: false,
255 mergeability: "mergeable",
256 reviewDecision: null,
257 additions: 1,
258 deletions: 1,
259 createdAt: "2026-07-01T00:00:00Z",
260 updatedAt: "2026-07-02T00:00:00Z",
261 reviewRequestLogins: [],
262 hasTeamReviewRequest: false,
263 checksState: "passing",
264 labels: [],
265 body: "",
266 changedFiles: 1,
267 mergedAt: null,
268 closedAt: null,
269 checks: [
270 {
271 name: "manual gate",
272 status: "action-required",
273 description: null,
274 url: "https://example.com/manual-gate",
275 },
276 { name: "build", status: "success", description: null, url: null },
277 ],
278 comments: [],
279 commits: [],
280 }),
281 listWorkflowRunsRequiringApproval: () =>
282 Effect.succeed([
283 {
284 id: 123,
285 name: "contributor tests",
286 url: "https://github.com/acme/web/actions/runs/123",
287 },
288 ]),
289 getPullRequestBaseComparison: () =>
290 Effect.succeed({ behindBy: 0, viewerCanUpdate: true }),
291 getRepositoryAccess: () =>
292 Effect.succeed({
293 canWrite: true,
294 mergeCapabilities: { merge: true, squash: true, rebase: true },
295 }),
296 getViewerAccess: () =>
297 Effect.succeed({ canWrite: true, canTriage: true, canUpdate: true, didAuthor: false }),
298 }),
299 ),
300 ),
301 );
302});
303​
304const openDetail = {
305 authorId: null,
306 number: 7,
307 title: "Pull request 7",
308 url: "https://github.com/acme/web/pull/7",
309 author: null,
310 isCrossRepository: true,
311 headRepositoryOwner: "acme",
312 headSha: "abc123",
313 headBranch: "feat/page",
314 baseBranch: "main",
315 state: "open" as const,
316 isDraft: false,
317 mergeability: "mergeable" as const,
318 reviewDecision: null,
319 additions: 1,
320 deletions: 1,
321 createdAt: "2026-07-01T00:00:00Z",
322 updatedAt: "2026-07-02T00:00:00Z",
323 reviewRequestLogins: [],
324 hasTeamReviewRequest: false,
325 checksState: null,
326 labels: [],
327 body: "",
328 changedFiles: 1,
329 mergedAt: null,
330 closedAt: null,
331 checks: [],
332 comments: [],
333 commits: [],
334};
335​
336it.effect("does not classify same-repository gates as fork workflow approvals", () =>
337 Effect.gen(function* () {
338 const provider = yield* make;
339 const detail = yield* provider.getChangeRequest({
340 cwd: "/w",
341 repository: "acme/web",
342 host: "github.com",
343 number: 7,
344 });
345​
346 expect(detail.workflowApprovalsRequired).toBe(0);
347 expect(detail.checks).toEqual([]);
348 }).pipe(
349 Effect.provide(
350 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
351 getPullRequestDetail: () => Effect.succeed({ ...openDetail, isCrossRepository: false }),
352 getPullRequestBaseComparison: () => Effect.succeed({ behindBy: 0, viewerCanUpdate: true }),
353 listWorkflowRunsRequiringApproval: () =>
354 Effect.die("same-repository pull requests must not probe fork workflow approvals"),
355 getRepositoryAccess: () =>
356 Effect.succeed({
357 canWrite: true,
358 mergeCapabilities: { merge: true, squash: true, rebase: true },
359 }),
360 getViewerAccess: () =>
361 Effect.succeed({ canWrite: true, canTriage: true, canUpdate: true, didAuthor: false }),
362 }),
363 ),
364 ),
365);
366​
367it.effect("keeps an unsafe workflow approval scope visible as unknown", () =>
368 Effect.gen(function* () {
369 const provider = yield* make;
370 const detail = yield* provider.getChangeRequest({
371 cwd: "/w",
372 repository: "acme/web",
373 host: "github.com",
374 number: 7,
375 });
376​
377 expect(detail.workflowApprovalsRequired).toBeUndefined();
378 expect(detail.checks).toEqual([
379 {
380 name: "Workflow approval status",
381 status: "action-required",
382 description: "GitHub could not determine whether workflows are awaiting approval.",
383 url: null,
384 },
385 ]);
386 }).pipe(
387 Effect.provide(
388 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
389 getPullRequestDetail: () => Effect.succeed(openDetail),
390 getPullRequestBaseComparison: () => Effect.succeed({ behindBy: 0, viewerCanUpdate: true }),
391 listWorkflowRunsRequiringApproval: () =>
392 Effect.fail(
393 new GitHubPullRequestCli.GitHubWorkflowApprovalRefusedError({
394 command: "gh",
395 cwd: "/w",
396 number: 7,
397 reason: "head-not-unique",
398 observedCount: 2,
399 limit: 1_000,
400 }),
401 ),
402 getRepositoryAccess: () =>
403 Effect.succeed({
404 canWrite: true,
405 mergeCapabilities: { merge: true, squash: true, rebase: true },
406 }),
407 getViewerAccess: () =>
408 Effect.succeed({ canWrite: true, canTriage: true, canUpdate: true, didAuthor: false }),
409 }),
410 ),
411 ),
412);
413​
414it.effect("propagates workflow discovery rate limits", () =>
415 Effect.gen(function* () {
416 const provider = yield* make;
417 const error = yield* provider
418 .getChangeRequest({
419 cwd: "/w",
420 repository: "acme/web",
421 host: "github.com",
422 number: 7,
423 })
424 .pipe(Effect.flip);
425​
426 expect(error.operation).toBe("getChangeRequest");
427 expect(error.reason).toBe("rate-limited");
428 }).pipe(
429 Effect.provide(
430 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
431 getPullRequestDetail: () => Effect.succeed(openDetail),
432 getPullRequestBaseComparison: () => Effect.succeed({ behindBy: 0, viewerCanUpdate: true }),
433 listWorkflowRunsRequiringApproval: () =>
434 Effect.fail(
435 new GitHubCli.GitHubCliRateLimitError({
436 command: "gh",
437 cwd: "/w",
438 cause: new Error("rate limited"),
439 }),
440 ),
441 getRepositoryAccess: () =>
442 Effect.succeed({
443 canWrite: true,
444 mergeCapabilities: { merge: true, squash: true, rebase: true },
445 }),
446 getViewerAccess: () =>
447 Effect.succeed({ canWrite: true, canTriage: true, canUpdate: true, didAuthor: false }),
448 }),
449 ),
450 ),
451);
452​
453describe("getViewerPermissions", () => {
454 const layerWithComparison = (
455 comparison: Effect.Effect<{
456 readonly behindBy: number | null;
457 readonly viewerCanUpdate: boolean;
458 }>,
459 ) =>
460 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
461 getPullRequestDetail: () => Effect.succeed(openDetail),
462 getPullRequestBaseComparison: () => comparison,
463 getViewerAccess: () =>
464 Effect.succeed({ canWrite: true, canTriage: true, canUpdate: true, didAuthor: false }),
465 });
466​
467 it.effect("offers update-branch when the comparison grants it", () =>
468 Effect.gen(function* () {
469 const provider = yield* make;
470 const permissions = yield* provider.getViewerPermissions({
471 cwd: "/w",
472 repository: "acme/web",
473 host: "github.com",
474 number: 7,
475 });
476​
477 expect(permissions.actions).toContain("update-branch");
478 expect(permissions.updateMethods).toEqual(["merge", "rebase"]);
479 }).pipe(
480 Effect.provide(layerWithComparison(Effect.succeed({ behindBy: 3, viewerCanUpdate: true }))),
481 ),
482 );
483​
484 it.effect("uses the GraphQL reserve for manual permission checks", () => {
485 let viewerAllowReserve: boolean | undefined;
486 let comparisonAllowReserve: boolean | undefined;
487 return Effect.gen(function* () {
488 const provider = yield* make;
489 yield* provider.getViewerPermissions({
490 cwd: "/w",
491 repository: "acme/web",
492 host: "github.com",
493 number: 7,
494 });
495​
496 expect(viewerAllowReserve).toBe(true);
497 expect(comparisonAllowReserve).toBe(true);
498 }).pipe(
499 Effect.provide(
500 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
501 getPullRequestDetail: () => Effect.succeed(openDetail),
502 getPullRequestBaseComparison: (input) =>
503 Effect.sync(() => {
504 comparisonAllowReserve = input.allowReserve;
505 return { behindBy: 3, viewerCanUpdate: true };
506 }),
507 getViewerAccess: (input) =>
508 Effect.sync(() => {
509 viewerAllowReserve = input.allowReserve;
510 return { canWrite: true, canTriage: true, canUpdate: true, didAuthor: false };
511 }),
512 }),
513 ),
514 );
515 });
516​
517 it.effect("withholds update-branch when the comparison cannot be read", () =>
518 Effect.gen(function* () {
519 const provider = yield* make;
520 const permissions = yield* provider.getViewerPermissions({
521 cwd: "/w",
522 repository: "acme/web",
523 host: "github.com",
524 number: 7,
525 });
526​
527 expect(permissions.actions).not.toContain("update-branch");
528 expect(permissions.updateMethods).toBeUndefined();
529 // The rest of the answer survives a comparison nobody could make.
530 expect(permissions.actions).toContain("merge");
531 }).pipe(
532 Effect.provide(
533 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
534 getPullRequestDetail: () => Effect.succeed(openDetail),
535 getPullRequestBaseComparison: () =>
536 Effect.fail(
537 new GitHubPullRequestCli.GitHubPullRequestReadError({
538 command: "gh",
539 cwd: "/w",
540 operation: "getPullRequestBaseComparison",
541 cause: new Error("unreadable"),
542 }),
543 ),
544 getViewerAccess: () =>
545 Effect.succeed({ canWrite: true, canTriage: true, canUpdate: true, didAuthor: false }),
546 }),
547 ),
548 ),
549 );
550});
551​
552describe("getChangeRequest commits", () => {
553 const baseDetail = {
554 authorId: null,
555 number: 7,
556 title: "Pull request 7",
557 url: "https://github.com/acme/web/pull/7",
558 author: null,
559 headBranch: "feat/page",
560 baseBranch: "main",
561 state: "open" as const,
562 isDraft: false,
563 mergeability: "mergeable" as const,
564 additions: 1,
565 deletions: 1,
566 createdAt: "2026-07-01T00:00:00Z",
567 updatedAt: "2026-07-02T00:00:00Z",
568 reviewRequestLogins: [],
569 hasTeamReviewRequest: false,
570 checksState: null,
571 labels: [],
572 body: "",
573 changedFiles: 1,
574 mergedAt: null,
575 closedAt: null,
576 checks: [],
577 comments: [],
578 };
579​
580 const baseThreadComments = {
581 comments: [],
582 dismissalsByReviewId: new Map<string, string>(),
583 reviewThreads: [],
584 commentCount: 0,
585 truncated: false,
586 reactions: [],
587 reactionsById: new Map<string, ReadonlyArray<PullRequestReaction>>(),
588 reviewers: [],
589 avatarsByLogin: new Map<string, string>(),
590 commitStats: new Map<string, { readonly additions: number; readonly deletions: number }>(),
591 viewer: { canUpdate: true, didAuthor: false },
592 };
593​
594 const layerWith = (commits: GitHubReviewThreadComments["commits"]) =>
595 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
596 getPullRequestActivity: () =>
597 Effect.succeed({
598 author: baseDetail.author,
599 comments: baseDetail.comments,
600 commits: [
601 {
602 oid: "view-oldest",
603 messageHeadline: "gh pr view's oldest commit",
604 committedDate: "2026-01-01T00:00:00Z",
605 authors: [],
606 },
607 ],
608 }),
609 listReviewThreadComments: () => Effect.succeed({ ...baseThreadComments, commits }),
610 });
611​
612 it.effect("prefers the GraphQL commits, which are the newest, over the gh view list", () =>
613 Effect.gen(function* () {
614 const provider = yield* make;
615 const detail = yield* provider.getChangeRequestActivity({
616 cwd: "/w",
617 repository: "acme/web",
618 host: "github.com",
619 number: 7,
620 });
621​
622 expect(detail.commits.map((commit) => commit.oid)).toEqual(["graphql-newest"]);
623 }).pipe(
624 Effect.provide(
625 layerWith([
626 {
627 oid: "graphql-newest",
628 messageHeadline: "the newest commit gh pr view drops",
629 committedDate: "2026-07-06T00:00:00Z",
630 authors: [],
631 },
632 ]),
633 ),
634 ),
635 );
636​
637 it.effect("falls back to the gh view list when the GraphQL read has no commits", () =>
638 Effect.gen(function* () {
639 const provider = yield* make;
640 const detail = yield* provider.getChangeRequestActivity({
641 cwd: "/w",
642 repository: "acme/web",
643 host: "github.com",
644 number: 7,
645 });
646​
647 expect(detail.commits.map((commit) => commit.oid)).toEqual(["view-oldest"]);
648 }).pipe(Effect.provide(layerWith([]))),
649 );
650});
651​
652describe("getChangeRequestActivity dismissed reviews", () => {
653 const dismissedReview = (body: string) => ({
654 id: "PRR_1",
655 kind: "review" as const,
656 author: null,
657 body,
658 createdAt: "2026-07-03T00:00:00Z",
659 url: null,
660 path: null,
661 reviewState: "DISMISSED",
662 });
663 const threadComments: GitHubReviewThreadComments = {
664 comments: [],
665 dismissalsByReviewId: new Map([["PRR_1", "Dismissing prior approval to re-evaluate 9b66581"]]),
666 reviewThreads: [],
667 commentCount: 0,
668 truncated: false,
669 reactions: [],
670 reactionsById: new Map(),
671 reviewers: [],
672 avatarsByLogin: new Map(),
673 commitStats: new Map(),
674 commits: [],
675 viewer: { canUpdate: true, didAuthor: false },
676 };
677 const layerFor = (body: string) =>
678 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
679 getPullRequestActivity: () =>
680 Effect.succeed({ author: null, comments: [dismissedReview(body)], commits: [] }),
681 listReviewThreadComments: () => Effect.succeed(threadComments),
682 });
683 const readActivity = Effect.gen(function* () {
684 const provider = yield* make;
685 return yield* provider.getChangeRequestActivity({
686 cwd: "/w",
687 repository: "acme/web",
688 host: "github.com",
689 number: 7,
690 });
691 });
692​
693 it.effect("fills a marker-only dismissed review with the timeline's reason", () =>
694 // Macroscope's approvals carry only an HTML comment, which markdown renders as nothing —
695 // an empty-string check misses them and the card opens onto nothing.
696 readActivity.pipe(
697 Effect.map((activity) => {
698 expect(activity.comments[0]?.body).toBe("Dismissing prior approval to re-evaluate 9b66581");
699 }),
700 Effect.provide(layerFor("<!-- Macroscope (Approvability) review body marker -->")),
701 ),
702 );
703​
704 it.effect("keeps the words of a dismissed review that has its own", () =>
705 readActivity.pipe(
706 Effect.map((activity) => {
707 expect(activity.comments[0]?.body).toBe("These findings still stand.");
708 }),
709 Effect.provide(layerFor("These findings still stand.")),
710 ),
711 );
712});
713​
714describe("editing", () => {
715 const rewrites: Array<unknown> = [];
716​
717 it.effect("hands a rewrite to the CLI as the request named it", () =>
718 Effect.gen(function* () {
719 const provider = yield* make;
720​
721 expect(provider.capabilities.edit).toEqual({ changeRequest: true, comment: true });
722 yield* provider.updateChangeRequest!({
723 cwd: "/w",
724 repository: "acme/web",
725 host: "github.com",
726 number: 7,
727 title: "A better title",
728 });
729 yield* provider.updateComment!({
730 cwd: "/w",
731 repository: "acme/web",
732 host: "github.com",
733 number: 7,
734 commentId: "IC_1",
735 kind: "review-comment",
736 body: "Reworded.",
737 });
738​
739 expect(rewrites).toEqual([
740 {
741 cwd: "/w",
742 repository: "acme/web",
743 host: "github.com",
744 number: 7,
745 title: "A better title",
746 },
747 {
748 cwd: "/w",
749 repository: "acme/web",
750 host: "github.com",
751 number: 7,
752 commentId: "IC_1",
753 kind: "review-comment",
754 body: "Reworded.",
755 },
756 ]);
757 }).pipe(
758 Effect.provide(
759 Layer.mock(GitHubPullRequestCli.GitHubPullRequestCli)({
760 updatePullRequest: (input) => Effect.sync(() => void rewrites.push(input)),
761 updateComment: (input) => Effect.sync(() => void rewrites.push(input)),
762 }),
763 ),
764 ),
765 );
766});
767​
768describe("loginAvatarUrl", () => {
769 it("serves a user's picture from the host they belong to", () => {
770 expect(loginAvatarUrl("octocat", "github.com")).toBe("https://github.com/octocat.png?size=80");
771 expect(loginAvatarUrl("octocat", "ghe.example.com")).toBe(
772 "https://ghe.example.com/octocat.png?size=80",
773 );
774 });
775​
776 it("has nothing for an app, which names no page", () => {
777 // `dependabot[bot]` has a picture, but not at `/dependabot[bot].png` — a guess that 404s is
778 // worse than the initials it would replace.
779 expect(loginAvatarUrl("dependabot[bot]", "github.com")).toBeNull();
780 });
781​
782 it("refuses anything that is not a login, rather than building a URL out of it", () => {
783 for (const login of ["../../etc", "a b", "-leading", "x".repeat(40), ""]) {
784 expect(loginAvatarUrl(login, "github.com")).toBeNull();
785 }
786 });
787});