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

gitHubPullRequestJson.test.ts

1,432 lines46.4 KB

1import * as Result from "effect/Result";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 buildReviewSubmissionJson,
6 buildReviewerRequestJson,
7 decodeBaseComparisonJson,
8 decodePullRequestActivityJson,
9 decodePullRequestDetailJson,
10 decodePullRequestFilesJson,
11 decodePullRequestListJson,
12 decodePullRequestNodeIdJson,
13 decodePullRequestSearchJson,
14 decodeRepositoryAccessJson,
15 decodeReviewerCandidatesJson,
16 decodeReviewThreadCommentsJson,
17 decodeReviewThreadsJson,
18 decodeViewerPermissionsJson,
19 decodeWorkflowRunApprovalsJson,
20 reviewThreadConversation,
21 REVIEW_THREADS_GRAPHQL_QUERY,
22} from "./gitHubPullRequestJson.ts";
23​
24function listJson(entries: ReadonlyArray<Record<string, unknown>>): string {
25 return JSON.stringify(
26 entries.map((entry) => ({
27 number: 1,
28 title: "Add the pull requests page",
29 url: "https://github.com/pingdotgg/t3code/pull/1",
30 headRefName: "feat/page",
31 baseRefName: "main",
32 createdAt: "2026-07-01T00:00:00Z",
33 updatedAt: "2026-07-02T00:00:00Z",
34 ...entry,
35 })),
36 );
38​
39function expectSuccess<A>(result: Result.Result<A, unknown>): A {
40 expect(Result.isSuccess(result)).toBe(true);
41 if (!Result.isSuccess(result)) throw new Error("expected a successful decode");
42 return result.success;
44​
45describe("pull request list decoding", () => {
46 it("treats a merge timestamp as merged even when the state still says closed", () => {
47 const [entry] = expectSuccess(
48 decodePullRequestListJson(listJson([{ state: "CLOSED", mergedAt: "2026-07-03T00:00:00Z" }])),
49 ).items;
50 expect(entry?.state).toBe("merged");
51 });
52​
53 it("normalizes mergeability and defaults unknown values", () => {
54 const batch = expectSuccess(
55 decodePullRequestListJson(
56 listJson([{ mergeable: "CONFLICTING" }, { mergeable: "SOMETHING_NEW" }, {}]),
57 ),
58 );
59 expect(batch.items.map((entry) => entry.mergeability)).toEqual([
60 "conflicting",
61 "unknown",
62 "unknown",
63 ]);
64 });
65​
66 it("keeps user review requests and drops team ones, which are not logins", () => {
67 const [entry] = expectSuccess(
68 decodePullRequestListJson(
69 listJson([{ reviewRequests: [{ login: "octocat" }, { slug: "web-platform" }] }]),
70 ),
71 ).items;
72 expect(entry?.reviewRequestLogins).toEqual(["octocat"]);
73 });
74​
75 it("normalizes the review decision and reports nothing for one GitHub does not summarize", () => {
76 const batch = expectSuccess(
77 decodePullRequestListJson(
78 listJson([
79 { reviewDecision: "APPROVED" },
80 { reviewDecision: "CHANGES_REQUESTED" },
81 { reviewDecision: "REVIEW_REQUIRED" },
82 { reviewDecision: null },
83 ]),
84 ),
85 );
86 expect(batch.items.map((entry) => entry.reviewDecision)).toEqual([
87 "approved",
88 "changes-requested",
89 "review-required",
90 null,
91 ]);
92 });
93​
94 it("rolls the head commit's checks up to the one word a row has space for", () => {
95 const batch = expectSuccess(
96 decodePullRequestListJson(
97 listJson([
98 // A failure outranks a run still going, and a completed run has to be read through its
99 // conclusion rather than its status.
100 {
101 statusCheckRollup: [
102 { name: "lint", status: "COMPLETED", conclusion: "SUCCESS" },
103 { name: "build", status: "IN_PROGRESS" },
104 { name: "test", status: "COMPLETED", conclusion: "FAILURE" },
105 ],
106 },
107 {
108 statusCheckRollup: [
109 { name: "lint", status: "COMPLETED", conclusion: "SUCCESS" },
110 { name: "build", status: "QUEUED" },
111 ],
112 },
113 { statusCheckRollup: [{ name: "lint", status: "COMPLETED", conclusion: "SUCCESS" }] },
114 // A commit status reports one `state` and no `status` at all.
115 { statusCheckRollup: [{ context: "ci/legacy", state: "ERROR" }] },
116 // Neither a pass, a failure nor a wait is no verdict rather than a green tick.
117 { statusCheckRollup: [{ name: "lint", status: "COMPLETED", conclusion: "SKIPPED" }] },
118 { statusCheckRollup: [] },
119 {},
120 ]),
121 ),
122 );
123 expect(batch.items.map((entry) => entry.checksState)).toEqual([
124 "failing",
125 "pending",
126 "passing",
127 "failing",
128 null,
129 null,
130 null,
131 ]);
132 });
133​
134 it("skips malformed entries but still counts them, so paging does not stop early", () => {
135 const raw = `[${listJson([{}]).slice(1, -1)},{"number":"not-a-number"}]`;
136 const batch = expectSuccess(decodePullRequestListJson(raw));
137 expect(batch.items).toHaveLength(1);
138 expect(batch.rawCount).toBe(2);
139 });
140});
141​
142describe("pull request search decoding", () => {
143 function searchJson(rollupStates: ReadonlyArray<string | null>): string {
144 return JSON.stringify({
145 data: {
146 search: {
147 pageInfo: { hasNextPage: false },
148 nodes: rollupStates.map((state, index) => ({
149 number: index + 1,
150 title: "Add the pull requests page",
151 url: "https://github.com/pingdotgg/t3code/pull/1",
152 headRefName: "feat/page",
153 baseRefName: "main",
154 createdAt: "2026-07-01T00:00:00Z",
155 updatedAt: "2026-07-02T00:00:00Z",
156 repository: { nameWithOwner: "pingdotgg/t3code" },
157 commits: {
158 nodes: [{ commit: { statusCheckRollup: state === null ? null : { state } } }],
159 },
160 })),
161 },
162 },
163 });
164 }
165​
166 it("maps the rollup enum the search answers with onto the same three words", () => {
167 // The search asks GitHub for the verdict rather than the checks behind it, so this path sees
168 // one enum where the listing sees an array.
169 const batch = expectSuccess(
170 decodePullRequestSearchJson(
171 searchJson(["SUCCESS", "FAILURE", "ERROR", "PENDING", "EXPECTED", null]),
172 ),
173 );
174 expect(batch.items.map((entry) => entry.checksState)).toEqual([
175 "passing",
176 "failing",
177 "failing",
178 "pending",
179 "pending",
180 null,
181 ]);
182 });
183});
184​
185describe("pull request detail decoding", () => {
186 const detailJson = JSON.stringify({
187 number: 7,
188 title: "Detail",
189 url: "https://github.com/pingdotgg/t3code/pull/7",
190 headRefName: "feat/detail",
191 baseRefName: "main",
192 createdAt: "2026-07-01T00:00:00Z",
193 updatedAt: "2026-07-05T00:00:00Z",
194 body: "Body",
195 statusCheckRollup: [
196 { __typename: "CheckRun", name: "build", status: "IN_PROGRESS" },
197 { __typename: "CheckRun", name: "test", status: "COMPLETED", conclusion: "FAILURE" },
198 { __typename: "StatusContext", context: "ci/legacy", state: "SUCCESS" },
199 ],
200 comments: [{ id: "c1", body: "second", createdAt: "2026-07-04T00:00:00Z" }],
201 reviews: [
202 { id: "r1", body: "first", state: "CHANGES_REQUESTED", submittedAt: "2026-07-03T00:00:00Z" },
203 { id: "r2", body: " ", state: "APPROVED", submittedAt: "2026-07-06T00:00:00Z" },
204 ],
205 commits: [
206 {
207 oid: "abc1234",
208 messageHeadline: "Ship the timeline",
209 committedDate: "2026-07-05T00:00:00Z",
210 authors: [
211 { login: "octocat", name: "Octo Cat", email: "octo@example.com" },
212 { name: "Pair Author", email: "pair@example.com" },
213 ],
214 },
215 ],
216 });
217​
218 it("maps check-run status and commit-status state onto one vocabulary", () => {
219 const detail = expectSuccess(decodePullRequestDetailJson(detailJson));
220 expect(detail.checks.map((check) => [check.name, check.status])).toEqual([
221 ["build", "pending"],
222 ["test", "failure"],
223 ["ci/legacy", "success"],
224 ]);
225 });
226​
227 it("keeps a workflow waiting for approval out of the passing state", () => {
228 const raw = JSON.parse(detailJson) as Record<string, unknown>;
229 const detail = expectSuccess(
230 decodePullRequestDetailJson(
231 JSON.stringify({
232 ...raw,
233 statusCheckRollup: [
234 { __typename: "CheckRun", name: "build", status: "COMPLETED", conclusion: "SUCCESS" },
235 {
236 __typename: "CheckRun",
237 name: "contributor tests",
238 status: "COMPLETED",
239 conclusion: "ACTION_REQUIRED",
240 },
241 ],
242 }),
243 ),
244 );
245​
246 expect(detail.checks.map((check) => check.status)).toEqual(["success", "action-required"]);
247 expect(detail.checksState).toBe("pending");
248 });
249​
250 it("decodes workflow runs that can be approved", () => {
251 expect(
252 expectSuccess(
253 decodeWorkflowRunApprovalsJson(
254 JSON.stringify([
255 { databaseId: 10, workflowName: "contributor tests", url: "https://example.com/10" },
256 { databaseId: 11, workflowName: null, url: null },
257 ]),
258 ),
259 ),
260 ).toEqual([
261 { id: 10, name: "contributor tests", url: "https://example.com/10" },
262 { id: 11, name: "Workflow run 11", url: null },
263 ]);
264 });
265​
266 it("reads an auto-merge request and strategy, its null as off and its absence as neither", () => {
267 const raw = JSON.parse(detailJson) as Record<string, unknown>;
268 const armed = (entry: Record<string, unknown>) =>
269 expectSuccess(decodePullRequestDetailJson(JSON.stringify({ ...raw, ...entry })));
270​
271 expect(
272 armed({ autoMergeRequest: { enabledBy: { login: "octocat" }, mergeMethod: "SQUASH" } }),
273 ).toMatchObject({ autoMergeEnabled: true, autoMergeMethod: "squash" });
274 expect(armed({ autoMergeRequest: null }).autoMergeEnabled).toBe(false);
275 // `gh` not answering for the field at all is not GitHub saying the merge is unarmed.
276 expect(armed({}).autoMergeEnabled).toBeUndefined();
277 });
278​
279 it("shows a re-running check once, as the run that is happening now", () => {
280 // What `statusCheckRollup` reports while a workflow is being re-run: the same check twice,
281 // the finished run and the one that replaced it, with no id to tell them apart.
282 const raw = JSON.parse(detailJson) as Record<string, unknown>;
283 const detail = expectSuccess(
284 decodePullRequestDetailJson(
285 JSON.stringify({
286 ...raw,
287 statusCheckRollup: [
288 {
289 __typename: "CheckRun",
290 name: "Prepare PR size config",
291 workflowName: "PR Size",
292 status: "COMPLETED",
293 conclusion: "SUCCESS",
294 startedAt: "2026-08-11T16:06:20Z",
295 completedAt: "2026-08-11T16:06:25Z",
296 },
297 {
298 __typename: "CheckRun",
299 name: "Prepare PR size config",
300 workflowName: "PR Size",
301 status: "IN_PROGRESS",
302 conclusion: "",
303 startedAt: "2026-08-11T17:01:04Z",
304 completedAt: "0001-01-01T00:00:00Z",
305 },
306 ],
307 }),
308 ),
309 );
310​
311 expect(detail.checks.map((check) => [check.name, check.status])).toEqual([
312 ["Prepare PR size config", "pending"],
313 ]);
314 expect(detail.checksState).toBe("pending");
315 });
316​
317 it("merges reviews with comments in time order and keeps a bodyless approval", () => {
318 const detail = expectSuccess(decodePullRequestActivityJson(detailJson));
319 // r2 approved without writing anything, which is still the event worth seeing.
320 expect(detail.comments.map((comment) => comment.id)).toEqual(["r1", "c1", "r2"]);
321 expect(detail.comments.at(-1)?.reviewState).toBe("APPROVED");
322 });
323​
324 it("keeps every attributed commit author, including an unlinked signature", () => {
325 const detail = expectSuccess(decodePullRequestActivityJson(detailJson));
326 expect(detail.commits[0]?.authors).toEqual([
327 { login: "octocat", name: "Octo Cat", avatarUrl: null },
328 { login: "Pair Author", name: "Pair Author", avatarUrl: null },
329 ]);
330 });
331​
332 it("drops the bodyless review GitHub opens to hold line comments", () => {
333 const raw = JSON.parse(detailJson) as Record<string, unknown>;
334 const detail = expectSuccess(
335 decodePullRequestActivityJson(
336 JSON.stringify({
337 ...raw,
338 reviews: [
339 // What a reviewer leaving inline comments produces: a container with a state but
340 // nothing to read. Its comments come from the review threads instead.
341 { id: "r4", body: "", state: "COMMENTED", submittedAt: "2026-07-07T00:00:00Z" },
342 {
343 id: "r5",
344 body: "Looks good.",
345 state: "COMMENTED",
346 submittedAt: "2026-07-08T00:00:00Z",
347 },
348 ],
349 }),
350 ),
351 );
352​
353 expect(detail.comments.map((comment) => comment.id)).toEqual(["c1", "r5"]);
354 });
355​
356 it.each(["APPROVED", "CHANGES_REQUESTED", "DISMISSED"])(
357 "keeps a bodyless %s review, which is the event itself",
358 (state) => {
359 const raw = JSON.parse(detailJson) as Record<string, unknown>;
360 const detail = expectSuccess(
361 decodePullRequestActivityJson(
362 JSON.stringify({
363 ...raw,
364 reviews: [{ id: "r6", body: "", state, submittedAt: "2026-07-07T00:00:00Z" }],
365 }),
366 ),
367 );
368​
369 expect(detail.comments.map((comment) => comment.id)).toContain("r6");
370 },
371 );
372​
373 it("drops a review that carries neither a body nor a state", () => {
374 const raw = JSON.parse(detailJson) as Record<string, unknown>;
375 const detail = expectSuccess(
376 decodePullRequestActivityJson(
377 JSON.stringify({
378 ...raw,
379 reviews: [{ id: "r3", body: " ", submittedAt: "2026-07-07T00:00:00Z" }],
380 }),
381 ),
382 );
383 expect(detail.comments.map((comment) => comment.id)).toEqual(["c1"]);
384 });
385});
386​
387describe("review thread decoding", () => {
388 const threadsJson = (
389 nodes: ReadonlyArray<Record<string, unknown>>,
390 totalCount = nodes.length,
391 pageInfo: Record<string, unknown> = { hasNextPage: false, endCursor: null },
392 ): string =>
393 JSON.stringify({
394 data: { repository: { pullRequest: { reviewThreads: { totalCount, pageInfo, nodes } } } },
395 });
396​
397 /** The same query carries the review roster, so it is built alongside the threads. */
398 const reviewJson = (input: {
399 readonly requested?: ReadonlyArray<unknown>;
400 readonly reviewed?: ReadonlyArray<unknown>;
401 }): string =>
402 JSON.stringify({
403 data: {
404 repository: {
405 pullRequest: {
406 reviewThreads: { totalCount: 0, nodes: [] },
407 reviewRequests: {
408 nodes: (input.requested ?? []).map((r) => ({ requestedReviewer: r })),
409 },
410 latestReviews: { nodes: (input.reviewed ?? []).map((a) => ({ author: a })) },
411 },
412 },
413 },
414 });
415​
416 it("keeps a reviewer who has already reviewed, app or person, with their avatar", () => {
417 const result = expectSuccess(
418 decodeReviewThreadsJson(
419 reviewJson({
420 requested: [{ login: "julius", name: "Julius", avatarUrl: "https://avatars/j.png" }],
421 // An app that has reviewed is no longer an outstanding request, which is why asking
422 // only for requests reported nobody on a pull request a bot had reviewed.
423 reviewed: [{ login: "macroscopeapp", avatarUrl: "https://avatars/in/900172.png" }],
424 }),
425 ),
426 );
427​
428 expect(result.reviewers).toEqual([
429 { login: "julius", name: "Julius", avatarUrl: "https://avatars/j.png" },
430 { login: "macroscopeapp", name: null, avatarUrl: "https://avatars/in/900172.png" },
431 ]);
432 });
433​
434 it("carries per-commit line counts from the pull-request connection", () => {
435 const result = expectSuccess(
436 decodeReviewThreadsJson(
437 JSON.stringify({
438 data: {
439 repository: {
440 pullRequest: {
441 reviewThreads: { totalCount: 0, nodes: [] },
442 commits: {
443 nodes: [
444 { commit: { oid: "abc123", additions: 18, deletions: 7 } },
445 { commit: { oid: "def456", additions: 3, deletions: 0 } },
446 ],
447 },
448 },
449 },
450 },
451 }),
452 ),
453 );
454​
455 expect([...result.commitStats]).toEqual([
456 ["abc123", { additions: 18, deletions: 7 }],
457 ["def456", { additions: 3, deletions: 0 }],
458 ]);
459 });
460​
461 it("omits misleading line counts from merge commits", () => {
462 const result = expectSuccess(
463 decodeReviewThreadsJson(
464 JSON.stringify({
465 data: {
466 repository: {
467 pullRequest: {
468 reviewThreads: { totalCount: 0, nodes: [] },
469 commits: {
470 nodes: [
471 {
472 commit: {
473 oid: "merge123",
474 additions: 36_858,
475 deletions: 12_928,
476 parents: { totalCount: 2 },
477 },
478 },
479 ],
480 },
481 },
482 },
483 },
484 }),
485 ),
486 );
487​
488 expect([...result.commitStats]).toEqual([]);
489 });
490​
491 it("decodes the newest commits off the same connection, oldest to newest", () => {
492 const result = expectSuccess(
493 decodeReviewThreadsJson(
494 JSON.stringify({
495 data: {
496 repository: {
497 pullRequest: {
498 reviewThreads: { totalCount: 0, nodes: [] },
499 commits: {
500 nodes: [
501 {
502 commit: {
503 oid: "abc123",
504 messageHeadline: "Ship the timeline",
505 committedDate: "2026-07-05T00:00:00Z",
506 additions: 18,
507 deletions: 7,
508 authors: { nodes: [{ name: "Julius", user: { login: "julius" } }] },
509 },
510 },
511 {
512 commit: {
513 oid: "def456",
514 messageHeadline: "Fix the flaky test",
515 committedDate: "2026-07-06T00:00:00Z",
516 },
517 },
518 ],
519 },
520 },
521 },
522 },
523 }),
524 ),
525 );
526​
527 expect(result.commits).toEqual([
528 {
529 oid: "abc123",
530 messageHeadline: "Ship the timeline",
531 committedDate: "2026-07-05T00:00:00Z",
532 authors: [{ login: "julius", name: "Julius", avatarUrl: null }],
533 },
534 {
535 oid: "def456",
536 messageHeadline: "Fix the flaky test",
537 committedDate: "2026-07-06T00:00:00Z",
538 authors: [],
539 },
540 ]);
541 });
542​
543 it("lists someone who was asked and then answered only once", () => {
544 const result = expectSuccess(
545 decodeReviewThreadsJson(
546 reviewJson({
547 requested: [{ login: "julius", avatarUrl: "https://avatars/j.png" }],
548 reviewed: [{ login: "julius", avatarUrl: "https://avatars/j.png" }],
549 }),
550 ),
551 );
552​
553 expect(result.reviewers).toHaveLength(1);
554 });
555​
556 it("skips a team request, which names nobody to show", () => {
557 const result = expectSuccess(decodeReviewThreadsJson(reviewJson({ requested: [null] })));
558​
559 expect(result.reviewers).toEqual([]);
560 });
561​
562 it("keeps the conversation when a request is from a team, which has no login", () => {
563 // GraphQL answers with an empty object for a union member the query has no fragment for.
564 // Failing on it would take the whole response down, comments included.
565 const result = expectSuccess(
566 decodeReviewThreadsJson(
567 reviewJson({ requested: [{}, { login: "julius", avatarUrl: "https://avatars/j.png" }] }),
568 ),
569 );
570​
571 expect(result.reviewers).toEqual([
572 { login: "julius", name: null, avatarUrl: "https://avatars/j.png" },
573 ]);
574 });
575​
576 it("carries a resolved thread into the conversation, which was still said", () => {
577 const result = expectSuccess(
578 decodeReviewThreadsJson(
579 threadsJson([
580 {
581 id: "PRRT_a",
582 isResolved: false,
583 path: "apps/server/src/ws.ts",
584 comments: {
585 nodes: [{ id: "t1", body: "fix this", createdAt: "2026-07-01T00:00:00Z" }],
586 },
587 },
588 {
589 id: "PRRT_b",
590 isResolved: true,
591 path: "apps/web/src/main.tsx",
592 comments: { nodes: [{ id: "t2", body: "done", createdAt: "2026-07-01T00:00:00Z" }] },
593 },
594 ]),
595 ),
596 );
597 const comments = reviewThreadConversation(result.threads.map((entry) => entry.thread));
598 expect(comments.map((comment) => comment.id)).toEqual(["t1", "t2"]);
599 expect(comments[0]).toMatchObject({
600 id: "t1",
601 kind: "review-comment",
602 path: "apps/server/src/ws.ts",
603 });
604 });
605​
606 it("carries every reply, not only the remark each thread opened with", () => {
607 const result = expectSuccess(
608 decodeReviewThreadsJson(
609 threadsJson([
610 {
611 id: "PRRT_c",
612 isResolved: false,
613 path: "apps/server/src/ws.ts",
614 comments: {
615 nodes: [
616 { id: "t1", body: "fix this", createdAt: "2026-07-01T00:00:00Z" },
617 { id: "t2", body: "fixed", createdAt: "2026-07-01T01:00:00Z" },
618 ],
619 },
620 },
621 ]),
622 ),
623 );
624 const comments = reviewThreadConversation(result.threads.map((entry) => entry.thread));
625 expect(comments.map((comment) => comment.id)).toEqual(["t1", "t2"]);
626 });
627​
628 it("hands back the cursor the next page of threads carries on from", () => {
629 const result = expectSuccess(
630 decodeReviewThreadsJson(
631 threadsJson(
632 [
633 {
634 id: "PRRT_d",
635 path: "apps/server/src/ws.ts",
636 isResolved: false,
637 comments: { nodes: [{ id: "t1", createdAt: "2026-07-01T00:00:00Z" }] },
638 },
639 ],
640 80,
641 { hasNextPage: true, endCursor: "Y3Vyc29yOjE" },
642 ),
643 ),
644 );
645 expect(result.nextCursor).toBe("Y3Vyc29yOjE");
646 });
647​
648 it("keeps GitHub's own count of a thread whose comments were not all read", () => {
649 const result = expectSuccess(
650 decodeReviewThreadsJson(
651 threadsJson([
652 {
653 id: "PRRT_e",
654 path: "apps/server/src/ws.ts",
655 isResolved: false,
656 comments: {
657 totalCount: 140,
658 pageInfo: { hasNextPage: true, endCursor: "Y3Vyc29yOjI" },
659 nodes: [{ id: "t1", createdAt: "2026-07-01T00:00:00Z" }],
660 },
661 },
662 ]),
663 ),
664 );
665 expect(result.threads[0]).toMatchObject({
666 commentCount: 140,
667 nextCommentCursor: "Y3Vyc29yOjI",
668 });
669 });
670​
671 it("ends a thread's walk on the last page, which still names a cursor", () => {
672 const decoded = expectSuccess(
673 decodeReviewThreadCommentsJson(
674 JSON.stringify({
675 data: {
676 repository: { pullRequest: { id: "PR_1" } },
677 node: {
678 pullRequest: { id: "PR_1" },
679 comments: {
680 pageInfo: { hasNextPage: false, endCursor: "Y3Vyc29yOjk" },
681 nodes: [{ id: "t9", body: "last", createdAt: "2026-07-01T00:00:00Z" }],
682 },
683 },
684 },
685 }),
686 ),
687 );
688 expect(decoded.comments.map((comment) => comment.id)).toEqual(["t9"]);
689 expect(decoded.nextCursor).toBeNull();
690 });
691});
692​
693describe("reaction decoding", () => {
694 const commentWithGroups = (reactionGroups: ReadonlyArray<Record<string, unknown>>) =>
695 JSON.stringify({
696 data: {
697 repository: { pullRequest: { id: "PR_1" } },
698 node: {
699 pullRequest: { id: "PR_1" },
700 comments: {
701 pageInfo: { hasNextPage: false, endCursor: null },
702 nodes: [{ id: "t1", body: "nice", createdAt: "2026-07-01T00:00:00Z", reactionGroups }],
703 },
704 },
705 },
706 });
707​
708 it("keeps a named group, widens a group whose reactors were cut short, drops an unknown content and an empty group", () => {
709 const decoded = expectSuccess(
710 decodeReviewThreadCommentsJson(
711 commentWithGroups([
712 {
713 content: "THUMBS_UP",
714 viewerHasReacted: true,
715 reactors: { totalCount: 2, nodes: [{ login: "julius" }, { login: "bilal" }] },
716 },
717 // Not one of the eight the contract carries.
718 {
719 content: "PARTY_PARROT",
720 reactors: { totalCount: 1, nodes: [{ login: "hubot" }] },
721 },
722 // Nobody behind it, which GitHub still answers a group for.
723 { content: "HEART", reactors: { totalCount: 0, nodes: [] } },
724 // More reactors than the bounded read named, and no `viewerHasReacted` at all.
725 {
726 content: "ROCKET",
727 reactors: { totalCount: 140, nodes: [{ login: "a" }, { login: "b" }, { login: "c" }] },
728 },
729 ]),
730 ),
731 );
732​
733 expect(decoded.comments[0]?.reactions).toEqual([
734 { content: "thumbs-up", count: 2, actors: ["julius", "bilal"], viewerHasReacted: true },
735 { content: "rocket", count: 140, actors: ["a", "b", "c"], viewerHasReacted: false },
736 ]);
737 });
738​
739 it("leaves the viewer's own login out of actors, matched case-insensitively, while count still counts them", () => {
740 const decoded = expectSuccess(
741 decodeReviewThreadCommentsJson(
742 JSON.stringify({
743 data: {
744 viewer: { login: "Bilal" },
745 repository: { pullRequest: { id: "PR_1" } },
746 node: {
747 pullRequest: { id: "PR_1" },
748 comments: {
749 pageInfo: { hasNextPage: false, endCursor: null },
750 nodes: [
751 {
752 id: "t1",
753 body: "nice",
754 createdAt: "2026-07-01T00:00:00Z",
755 reactionGroups: [
756 {
757 content: "HEART",
758 viewerHasReacted: true,
759 reactors: {
760 totalCount: 2,
761 nodes: [{ login: "bilal" }, { login: "julius" }],
762 },
763 },
764 ],
765 },
766 ],
767 },
768 },
769 },
770 }),
771 ),
772 );
773​
774 expect(decoded.comments[0]?.reactions).toEqual([
775 { content: "heart", count: 2, actors: ["julius"], viewerHasReacted: true },
776 ]);
777 });
778});
779​
780describe("repository access decoding", () => {
781 const repositoryJson = (viewerPermission?: string | null) =>
782 JSON.stringify({
783 mergeCommitAllowed: true,
784 squashMergeAllowed: false,
785 rebaseMergeAllowed: true,
786 ...(viewerPermission === undefined ? {} : { viewerPermission }),
787 });
788​
789 it("reads the three settings gh reports", () => {
790 expect(
791 expectSuccess(decodeRepositoryAccessJson(repositoryJson("ADMIN"))).mergeCapabilities,
792 ).toEqual({ merge: true, squash: false, rebase: true });
793 });
794​
795 it("fails rather than defaulting open when a setting is missing", () => {
796 const decoded = decodeRepositoryAccessJson(JSON.stringify({ mergeCommitAllowed: true }));
797 expect(Result.isSuccess(decoded)).toBe(false);
798 });
799​
800 it("counts the roles that can push as write, and the ones that cannot as read", () => {
801 for (const permission of ["ADMIN", "MAINTAIN", "WRITE"]) {
802 expect(expectSuccess(decodeRepositoryAccessJson(repositoryJson(permission))).canWrite).toBe(
803 true,
804 );
805 }
806 for (const permission of ["TRIAGE", "READ", "NONE"]) {
807 expect(expectSuccess(decodeRepositoryAccessJson(repositoryJson(permission))).canWrite).toBe(
808 false,
809 );
810 }
811 });
812​
813 it("withholds write where gh names no permission, which is not a standing it gave", () => {
814 // The one place an unknown answer is not granted: a Merge button a reader cannot use wastes
815 // the press, where a missing one still leaves the pull request open on its host.
816 expect(expectSuccess(decodeRepositoryAccessJson(repositoryJson())).canWrite).toBe(false);
817 expect(expectSuccess(decodeRepositoryAccessJson(repositoryJson(null))).canWrite).toBe(false);
818 });
819});
820​
821describe("viewer permission decoding", () => {
822 const viewerJson = (repository: Record<string, unknown>) =>
823 JSON.stringify({ data: { repository } });
824​
825 it("reads the repository's role and the pull request's own viewer fields together", () => {
826 expect(
827 expectSuccess(
828 decodeViewerPermissionsJson(
829 viewerJson({
830 viewerPermission: "READ",
831 pullRequest: { viewerCanUpdate: true, viewerDidAuthor: true },
832 }),
833 ),
834 ),
835 ).toEqual({ canWrite: false, canUpdate: true, didAuthor: true });
836 });
837​
838 it("says no to a passer-by on a repository they can only read", () => {
839 expect(
840 expectSuccess(
841 decodeViewerPermissionsJson(
842 viewerJson({
843 viewerPermission: "READ",
844 pullRequest: { viewerCanUpdate: false, viewerDidAuthor: false },
845 }),
846 ),
847 ),
848 ).toEqual({ canWrite: false, canUpdate: false, didAuthor: false });
849 });
850​
851 it("reads silence as permission, but not as authorship", () => {
852 // A node the viewer cannot see comes back null. Updating is a permission, so an unknown
853 // answer grants it and lets the host refuse; authorship is a fact about who wrote the change,
854 // and claiming it for someone who did not is how an author's own rules get handed out.
855 expect(expectSuccess(decodeViewerPermissionsJson(viewerJson({ pullRequest: null })))).toEqual({
856 canWrite: false,
857 canUpdate: true,
858 didAuthor: false,
859 });
860 });
861});
862​
863describe("review thread decoding", () => {
864 const threadsJson = (
865 nodes: ReadonlyArray<Record<string, unknown>>,
866 pullRequest: Record<string, unknown> = {},
867 ) =>
868 JSON.stringify({
869 data: {
870 repository: {
871 pullRequest: {
872 reviewThreads: { totalCount: nodes.length, nodes },
873 author: null,
874 comments: { nodes: [] },
875 reviewRequests: { nodes: [] },
876 latestReviews: { nodes: [] },
877 ...pullRequest,
878 },
879 },
880 },
881 });
882​
883 it("carries what the reader may do with the pull request, off the conversation read", () => {
884 // The same response the threads arrive in, so knowing this costs no request of its own.
885 expect(
886 expectSuccess(
887 decodeReviewThreadsJson(
888 threadsJson([], { viewerCanUpdate: false, viewerDidAuthor: false }),
889 ),
890 ).viewer,
891 ).toEqual({ canUpdate: false, didAuthor: false });
892 expect(expectSuccess(decodeReviewThreadsJson(threadsJson([]))).viewer).toEqual({
893 canUpdate: true,
894 didAuthor: false,
895 });
896 });
897​
898 const comment = (id: string, body: string) => ({
899 id,
900 author: { login: "bilal", avatarUrl: "https://avatars/b.png" },
901 body,
902 createdAt: "2026-07-01T00:00:00Z",
903 url: `https://github.com/acme/web/pull/1#discussion_r${id}`,
904 });
905​
906 it("anchors a thread to its line and side, keeping the whole conversation", () => {
907 const reviewThreads = expectSuccess(
908 decodeReviewThreadsJson(
909 threadsJson([
910 {
911 id: "PRRT_1",
912 isResolved: false,
913 isOutdated: false,
914 path: "src/a.ts",
915 line: 42,
916 diffSide: "LEFT",
917 comments: { totalCount: 2, nodes: [comment("c1", "first"), comment("c2", "second")] },
918 },
919 ]),
920 ),
921 );
922 expect(reviewThreads.threads.map((entry) => entry.thread)).toEqual([
923 {
924 id: "PRRT_1",
925 path: "src/a.ts",
926 line: 42,
927 side: "left",
928 isResolved: false,
929 isOutdated: false,
930 comments: [
931 {
932 id: "c1",
933 author: { login: "bilal", name: null, avatarUrl: "https://avatars/b.png" },
934 body: "first",
935 createdAt: "2026-07-01T00:00:00Z",
936 url: "https://github.com/acme/web/pull/1#discussion_rc1",
937 reactions: [],
938 },
939 {
940 id: "c2",
941 author: { login: "bilal", name: null, avatarUrl: "https://avatars/b.png" },
942 body: "second",
943 createdAt: "2026-07-01T00:00:00Z",
944 url: "https://github.com/acme/web/pull/1#discussion_rc2",
945 reactions: [],
946 },
947 ],
948 },
949 ]);
950 });
951​
952 it("leaves an outdated thread without a line rather than pinning it to a stale one", () => {
953 const reviewThreads = expectSuccess(
954 decodeReviewThreadsJson(
955 threadsJson([
956 {
957 id: "PRRT_2",
958 isResolved: true,
959 isOutdated: true,
960 path: "src/a.ts",
961 // GitHub reports no current line once the thread has fallen off the diff.
962 line: null,
963 diffSide: "RIGHT",
964 comments: { totalCount: 1, nodes: [comment("c3", "stale")] },
965 },
966 ]),
967 ),
968 );
969 expect(reviewThreads.threads[0]?.thread).toMatchObject({
970 line: null,
971 isOutdated: true,
972 isResolved: true,
973 });
974 });
975​
976 it("keeps a resolved thread in the conversation as well as against its line", () => {
977 const decoded = expectSuccess(
978 decodeReviewThreadsJson(
979 threadsJson([
980 {
981 id: "PRRT_3",
982 isResolved: true,
983 path: "src/a.ts",
984 line: 7,
985 diffSide: "RIGHT",
986 comments: { totalCount: 1, nodes: [comment("c4", "done")] },
987 },
988 ]),
989 ),
990 );
991 // A resolved conversation is finished work, not unsaid work: the timeline reads it and the
992 // diff pins it to its line, the same as any other.
993 const threads = decoded.threads.map((entry) => entry.thread);
994 expect(reviewThreadConversation(threads).map((comment) => comment.id)).toEqual(["c4"]);
995 expect(threads).toHaveLength(1);
996 });
997​
998 it("puts an issue comment's and a review's reactions in reactionsById, and the pull request's own in reactions", () => {
999 const result = expectSuccess(
1000 decodeReviewThreadsJson(
1001 threadsJson([], {
1002 reactionGroups: [
1004 content: "HEART",
1005 viewerHasReacted: true,
1006 reactors: { totalCount: 1, nodes: [{ login: "bilal" }] },
1007 },
1008 ],
1009 comments: {
1010 nodes: [
1012 id: "c1",
1013 reactionGroups: [
1015 content: "THUMBS_UP",
1016 reactors: { totalCount: 1, nodes: [{ login: "julius" }] },
1017 },
1018 ],
1019 },
1020 ],
1021 },
1022 reviews: {
1023 nodes: [
1025 id: "r1",
1026 reactionGroups: [
1027 { content: "EYES", reactors: { totalCount: 1, nodes: [{ login: "hubot" }] } },
1028 ],
1029 },
1030 ],
1031 },
1032 }),
1033 ),
1034 );
1035​
1036 expect(result.reactions).toEqual([
1037 { content: "heart", count: 1, actors: ["bilal"], viewerHasReacted: true },
1038 ]);
1039 expect([...result.reactionsById]).toEqual([
1040 ["c1", [{ content: "thumbs-up", count: 1, actors: ["julius"], viewerHasReacted: false }]],
1041 ["r1", [{ content: "eyes", count: 1, actors: ["hubot"], viewerHasReacted: false }]],
1042 ]);
1043 });
1044​
1045 it("leaves the viewer's own login out of the pull request's own reactions, matched case-insensitively, while count still counts them", () => {
1046 const result = expectSuccess(
1047 decodeReviewThreadsJson(
1048 JSON.stringify({
1049 data: {
1050 viewer: { login: "Bilal" },
1051 repository: {
1052 pullRequest: {
1053 reviewThreads: { totalCount: 0, nodes: [] },
1054 reactionGroups: [
1056 content: "HEART",
1057 viewerHasReacted: true,
1058 reactors: { totalCount: 2, nodes: [{ login: "bilal" }, { login: "julius" }] },
1059 },
1060 ],
1061 },
1062 },
1063 },
1064 }),
1065 ),
1066 );
1067​
1068 expect(result.reactions).toEqual([
1069 { content: "heart", count: 2, actors: ["julius"], viewerHasReacted: true },
1070 ]);
1071 });
1072});
1073​
1074describe("decodePullRequestNodeIdJson", () => {
1075 it("reads the pull request's own node id, which a reaction on its description is addressed by", () => {
1076 expect(
1077 expectSuccess(
1078 decodePullRequestNodeIdJson(
1079 JSON.stringify({ data: { repository: { pullRequest: { id: "PR_kwDOA" } } } }),
1080 ),
1081 ),
1082 ).toBe("PR_kwDOA");
1083 });
1084});
1085​
1086describe("REVIEW_THREADS_GRAPHQL_QUERY", () => {
1087 it("caps the initial query after the 104-point rate-limit regression", () => {
1088 const match = REVIEW_THREADS_GRAPHQL_QUERY.match(
1089 /reviewThreads\(first: (\d+)[\s\S]*?comments\(first: (\d+)\)/u,
1090 );
1091​
1092 expect(match).not.toBeNull();
1093 if (match === null) throw new Error("expected review-thread connections");
1094 expect(Number(match[1]) * Number(match[2])).toBeLessThanOrEqual(1_000);
1095 });
1096​
1097 it("asks for reactionGroups on the pull request itself, its comments, its reviews and each thread's comments", () => {
1098 expect(REVIEW_THREADS_GRAPHQL_QUERY.match(/reactionGroups/g)).toHaveLength(4);
1099 // The reviews connection is new: only reactions were ever wanted off it.
1100 expect(REVIEW_THREADS_GRAPHQL_QUERY).toContain("reviews(first:");
1101 });
1102});
1103​
1104describe("reviewer candidate decoding", () => {
1105 const candidatesJson = (input: {
1106 readonly assignable: ReadonlyArray<Record<string, unknown> | null>;
1107 readonly requested?: ReadonlyArray<Record<string, unknown> | null>;
1108 readonly author?: string;
1109 readonly hasNextPage?: boolean;
1110 }) =>
1111 JSON.stringify({
1112 data: {
1113 repository: {
1114 assignableUsers: {
1115 pageInfo: { hasNextPage: input.hasNextPage ?? false },
1116 nodes: input.assignable,
1117 },
1118 pullRequest: {
1119 author: input.author === undefined ? null : { login: input.author },
1120 reviewRequests: {
1121 nodes: (input.requested ?? []).map((requestedReviewer) => ({ requestedReviewer })),
1122 },
1123 },
1124 },
1125 },
1126 });
1127​
1128 it("leaves the author out of the people their own pull request can be sent to", () => {
1129 const list = expectSuccess(
1130 decodeReviewerCandidatesJson(
1131 candidatesJson({
1132 assignable: [{ login: "bilal" }, { login: "octocat", name: "The Octocat" }],
1133 author: "bilal",
1134 }),
1135 ),
1136 );
1137 expect(list.candidates).toEqual([
1139 id: "octocat",
1140 kind: "user",
1141 login: "octocat",
1142 name: "The Octocat",
1143 avatarUrl: null,
1144 isRequested: false,
1145 },
1146 ]);
1147 expect(list.truncated).toBe(false);
1148 });
1149​
1150 it("marks whoever has already been asked, and leaves the rest to be asked", () => {
1151 const list = expectSuccess(
1152 decodeReviewerCandidatesJson(
1153 candidatesJson({
1154 assignable: [{ login: "octocat" }, { login: "hubot" }],
1155 requested: [{ login: "octocat" }],
1156 }),
1157 ),
1158 );
1159 expect(list.candidates.map((candidate) => [candidate.login, candidate.isRequested])).toEqual([
1160 ["octocat", true],
1161 ["hubot", false],
1162 ]);
1163 });
1164​
1165 it("keeps a requested team apart from the people, so the request can be taken back", () => {
1166 // A team is never among the assignable users, and a request that cannot be seen cannot be
1167 // undone — so the ones GitHub reports are carried, marked as the teams they are.
1168 const list = expectSuccess(
1169 decodeReviewerCandidatesJson(
1170 candidatesJson({
1171 assignable: [{ login: "octocat" }],
1172 requested: [{ slug: "reviewers", name: "Reviewers" }],
1173 }),
1174 ),
1175 );
1176 expect(list.candidates).toEqual([
1178 id: "reviewers",
1179 kind: "team",
1180 login: "reviewers",
1181 name: "Reviewers",
1182 avatarUrl: null,
1183 isRequested: true,
1184 },
1186 id: "octocat",
1187 kind: "user",
1188 login: "octocat",
1189 name: null,
1190 avatarUrl: null,
1191 isRequested: false,
1192 },
1193 ]);
1194 });
1195​
1196 it("says so when the repository has more people than the read asked for", () => {
1197 expect(
1198 expectSuccess(
1199 decodeReviewerCandidatesJson(
1200 candidatesJson({ assignable: [{ login: "octocat" }], hasNextPage: true }),
1201 ),
1202 ).truncated,
1203 ).toBe(true);
1204 });
1205});
1206​
1207describe("reviewer request payload", () => {
1208 it("sends people and teams in the two lists GitHub keeps them in", () => {
1209 expect(
1210 JSON.parse(
1211 buildReviewerRequestJson([
1212 { id: "octocat", kind: "user" },
1213 { id: "reviewers", kind: "team" },
1214 { id: "hubot", kind: "user" },
1215 ]),
1216 ),
1217 ).toEqual({ reviewers: ["octocat", "hubot"], team_reviewers: ["reviewers"] });
1218 });
1219​
1220 it("sends both lists even where one of them is empty, which is what GitHub reads", () => {
1221 expect(JSON.parse(buildReviewerRequestJson([{ id: "octocat", kind: "user" }]))).toEqual({
1222 reviewers: ["octocat"],
1223 team_reviewers: [],
1224 });
1225 });
1226});
1227​
1228describe("review submission payload", () => {
1229 it("sends the verdict, the summary and every line comment in one body", () => {
1230 const payload = JSON.parse(
1231 buildReviewSubmissionJson({
1232 verdict: "request-changes",
1233 body: "Two things.",
1234 comments: [
1236 path: "src/a.ts",
1237 position: { kind: "added", newLine: 12 },
1238 body: "rename this",
1239 },
1241 path: "src/b.ts",
1242 position: { kind: "deleted", oldLine: 3 },
1243 body: "why remove?",
1244 },
1245 ],
1246 }),
1247 ) as Record<string, unknown>;
1248 expect(payload).toEqual({
1249 event: "REQUEST_CHANGES",
1250 body: "Two things.",
1251 comments: [
1252 { path: "src/a.ts", line: 12, side: "RIGHT", body: "rename this" },
1253 { path: "src/b.ts", line: 3, side: "LEFT", body: "why remove?" },
1254 ],
1255 });
1256 });
1257​
1258 it("sends an approval with no words and no comments", () => {
1259 expect(
1260 JSON.parse(buildReviewSubmissionJson({ verdict: "approve", body: "", comments: [] })),
1261 ).toEqual({ event: "APPROVE", body: "", comments: [] });
1262 });
1263});
1264​
1265describe("decodePullRequestFilesJson", () => {
1266 it("assembles a unified patch the files API does not return", () => {
1267 const result = expectSuccess(
1268 decodePullRequestFilesJson(
1269 JSON.stringify([
1270 { filename: "src/app.ts", status: "modified", patch: "@@ -1 +1 @@\n-old\n+new" },
1271 ]),
1272 ),
1273 );
1274​
1275 expect(result.patch).toBe(
1277 "diff --git a/src/app.ts b/src/app.ts",
1278 "--- a/src/app.ts",
1279 "+++ b/src/app.ts",
1280 "@@ -1 +1 @@",
1281 "-old",
1282 "+new",
1283 "",
1284 ].join("\n"),
1285 );
1286 expect(result.truncated).toBe(false);
1287 expect(result.rawCount).toBe(1);
1288 });
1289​
1290 it("points an added file at /dev/null on the left and a removed one on the right", () => {
1291 const result = expectSuccess(
1292 decodePullRequestFilesJson(
1293 JSON.stringify([
1294 { filename: "src/new.ts", status: "added", patch: "@@ -0,0 +1 @@\n+hello" },
1295 { filename: "src/gone.ts", status: "removed", patch: "@@ -1 +0,0 @@\n-bye" },
1296 ]),
1297 ),
1298 );
1299​
1300 expect(result.patch).toBe(
1302 "diff --git a/src/new.ts b/src/new.ts",
1303 "new file mode 100644",
1304 "--- /dev/null",
1305 "+++ b/src/new.ts",
1306 "@@ -0,0 +1 @@",
1307 "+hello",
1308 "diff --git a/src/gone.ts b/src/gone.ts",
1309 "deleted file mode 100644",
1310 "--- a/src/gone.ts",
1311 "+++ /dev/null",
1312 "@@ -1 +0,0 @@",
1313 "-bye",
1314 "",
1315 ].join("\n"),
1316 );
1317 });
1318​
1319 it("names both paths of a rename, counting its hunks against the old one", () => {
1320 const result = expectSuccess(
1321 decodePullRequestFilesJson(
1322 JSON.stringify([
1324 filename: "src/new.ts",
1325 status: "renamed",
1326 previous_filename: "src/old.ts",
1327 patch: "@@ -1 +1 @@\n-old\n+new",
1328 },
1329 ]),
1330 ),
1331 );
1332​
1333 expect(result.patch).toBe(
1335 "diff --git a/src/old.ts b/src/new.ts",
1336 "rename from src/old.ts",
1337 "rename to src/new.ts",
1338 "--- a/src/old.ts",
1339 "+++ b/src/new.ts",
1340 "@@ -1 +1 @@",
1341 "-old",
1342 "+new",
1343 "",
1344 ].join("\n"),
1345 );
1346 });
1347​
1348 it("still lists a file GitHub sent no hunks for, and says what was withheld", () => {
1349 const result = expectSuccess(
1350 decodePullRequestFilesJson(
1351 JSON.stringify([
1352 // Binary: it changed, and none of it can be shown.
1353 { filename: "logo.png", status: "modified", additions: 4, deletions: 2 },
1355 filename: "src/app.ts",
1356 status: "modified",
1357 additions: 1,
1358 deletions: 1,
1359 patch: "@@ -1 +1 @@\n-old\n+new",
1360 },
1361 ]),
1362 ),
1363 );
1364​
1365 // Dropping it would take the file out of the change altogether, not just its contents.
1366 expect(result.patch).toContain("diff --git a/logo.png b/logo.png");
1367 expect(result.patch).toContain("diff --git a/src/app.ts b/src/app.ts");
1368 expect(result.truncated).toBe(true);
1369 expect(result.rawCount).toBe(2);
1370 });
1371​
1372 it("does not call a pure rename incomplete, since it has no hunks to withhold", () => {
1373 const result = expectSuccess(
1374 decodePullRequestFilesJson(
1375 JSON.stringify([
1377 filename: "src/new.ts",
1378 previous_filename: "src/old.ts",
1379 status: "renamed",
1380 additions: 0,
1381 deletions: 0,
1382 },
1383 ]),
1384 ),
1385 );
1386​
1387 expect(result.patch).toContain("rename from src/old.ts");
1388 expect(result.truncated).toBe(false);
1389 });
1390});
1391​
1392describe("how far a branch trails its base", () => {
1393 const comparison = (pullRequest: unknown) =>
1394 JSON.stringify({ data: { repository: { pullRequest } } });
1395​
1396 it("reads the commit count and whether this viewer may move the branch", () => {
1397 const decoded = expectSuccess(
1398 decodeBaseComparisonJson(
1399 comparison({ viewerCanUpdateBranch: true, baseRef: { compare: { behindBy: 12 } } }),
1400 ),
1401 );
1402 expect(decoded).toEqual({ behindBy: 12, viewerCanUpdate: true });
1403 });
1404​
1405 it("reads a current branch as nothing to do", () => {
1406 expect(
1407 expectSuccess(
1408 decodeBaseComparisonJson(
1409 comparison({ viewerCanUpdateBranch: false, baseRef: { compare: { behindBy: 0 } } }),
1410 ),
1411 ),
1412 ).toEqual({ behindBy: 0, viewerCanUpdate: false });
1413 });
1414​
1415 it("answers unknown where the head could not be compared", () => {
1416 // A pull request from a fork whose repository is gone, which GitHub answers with a null
1417 // comparison beside a perfectly good pull request.
1418 expect(
1419 expectSuccess(
1420 decodeBaseComparisonJson(comparison({ viewerCanUpdateBranch: true, baseRef: null })),
1421 ).behindBy,
1422 ).toBeNull();
1423 expect(expectSuccess(decodeBaseComparisonJson(comparison(null)))).toEqual({
1424 behindBy: null,
1425 viewerCanUpdate: false,
1426 });
1427 });
1428​
1429 it("refuses a body that is not the answer to this question", () => {
1430 expect(Result.isSuccess(decodeBaseComparisonJson("{"))).toBe(false);
1431 });
1432});