Open History to see the last commit
1import * as Result from "effect/Result";
2import { describe, expect, it } from "vite-plus/test";
3
4import {
5 decodeAwardEmojiJson,
6 decodeRepositoryBlobsJson,
7 decodeCommitsJson,
8 decodeGraphqlListSupportJson,
9 decodeMergeRequestGraphqlListJson,
10 decodeMergeMessagesJson,
11 decodeMergeRequestDetailJson,
12 decodeMergeRequestDiffsJson,
13 decodeMergeRequestListJson,
14 decodeMergeRequestFileStatsJson,
15 decodeMergeRequestStatsJson,
16 decodeMergeRequestWatchFingerprintJson,
17 decodeReferenceCandidatesJson,
18 decodeNotesJson,
19 decodeOwnAwardIdJson,
20 decodeListStatesJson,
21 decodeTriggerJobChecksJson,
22 decodePipelineStageChecksJson,
23} from "./gitLabMergeRequestJson.ts";
24
25function listJson(entries: ReadonlyArray<Record<string, unknown>>): string {
26 return JSON.stringify(
27 entries.map((entry) => ({
28 iid: 1,
29 title: "Add the merge requests page",
30 web_url: "https://gitlab.com/acme/web/-/merge_requests/1",
31 source_branch: "feat/page",
32 target_branch: "main",
33 created_at: "2026-07-01T00:00:00Z",
34 updated_at: "2026-07-02T00:00:00Z",
35 ...entry,
36 })),
37 );
38}
39
40function detailJson(entry: Record<string, unknown>): string {
41 return JSON.stringify({
42 iid: 1,
43 title: "Add the merge requests page",
44 web_url: "https://gitlab.com/acme/web/-/merge_requests/1",
45 source_branch: "feat/page",
46 target_branch: "main",
47 created_at: "2026-07-01T00:00:00Z",
48 updated_at: "2026-07-02T00:00:00Z",
49 ...entry,
50 });
51}
52
53function expectSuccess<A>(result: Result.Result<A, unknown>): A {
54 expect(Result.isSuccess(result)).toBe(true);
55 if (!Result.isSuccess(result)) throw new Error("expected a successful decode");
56 return result.success;
57}
58
59describe("decodeMergeRequestListJson", () => {
60 it("reads a merge request as a change request", () => {
61 const batch = expectSuccess(
62 decodeMergeRequestListJson(
63 listJson([
64 {
65 iid: 42,
66 author: { username: "bilal", name: "Bilal" },
67 state: "opened",
68 merge_status: "can_be_merged",
69 draft: false,
70 reviewers: [{ username: "julius" }],
71 labels: ["backend", " "],
72 },
73 {
74 iid: 43,
75 labels: [
76 { name: "bug", color: "#E24329", description: "Something is broken" },
77 { name: " ", color: "#000000" },
78 ],
79 },
80 ]),
81 ),
82 );
83
84 expect(batch.items).toHaveLength(2);
85 expect(batch.items[0]).toMatchObject({
86 number: 42,
87 author: { login: "bilal", name: "Bilal" },
88 headBranch: "feat/page",
89 baseBranch: "main",
90 state: "open",
91 isDraft: false,
92 mergeability: "mergeable",
93 reviewRequestLogins: ["julius"],
94 labels: [{ name: "backend", color: null }],
95 });
96 expect(batch.items[1]?.labels).toEqual([
97 { name: "bug", color: "#E24329", description: "Something is broken" },
98 ]);
99 });
100
101 it("treats a merged timestamp as merged whatever the state says", () => {
102 const batch = expectSuccess(
103 decodeMergeRequestListJson(
104 listJson([{ state: "opened", merged_at: "2026-07-03T00:00:00Z" }]),
105 ),
106 );
107
108 expect(batch.items[0]?.state).toBe("merged");
109 });
110
111 it("reads the legacy draft flag", () => {
112 const batch = expectSuccess(decodeMergeRequestListJson(listJson([{ work_in_progress: true }])));
113
114 expect(batch.items[0]?.isDraft).toBe(true);
115 });
116
117 it("calls a conflicted merge request conflicting even while the merge check is pending", () => {
118 const batch = expectSuccess(
119 decodeMergeRequestListJson(listJson([{ merge_status: "checking", has_conflicts: true }])),
120 );
121
122 expect(batch.items[0]?.mergeability).toBe("conflicting");
123 });
124
125 it("skips a malformed row but still counts it, so paging does not stop early", () => {
126 const batch = expectSuccess(
127 decodeMergeRequestListJson(
128 JSON.stringify([{ iid: "not a number" }, ...JSON.parse(listJson([{}]))]),
129 ),
130 );
131
132 expect(batch.items).toHaveLength(1);
133 expect(batch.rawIndexes).toEqual([1]);
134 expect(batch.rawCount).toBe(2);
135 });
136});
137
138describe("decodeMergeRequestDetailJson", () => {
139 it("preserves a required rebase while CI is running or successful", () => {
140 for (const status of ["running", "success"]) {
141 const detail = expectSuccess(
142 decodeMergeRequestDetailJson(
143 detailJson({
144 merge_status: "can_be_merged",
145 detailed_merge_status: "need_rebase",
146 has_conflicts: false,
147 head_pipeline: { status },
148 }),
149 ),
150 );
151 expect(detail.rebaseRequired).toBe(true);
152 expect(detail.mergeability).toBe("mergeable");
153 }
154 });
155
156 it("distinguishes a cleared rebase blocker from an inconclusive merge check", () => {
157 expect(
158 expectSuccess(
159 decodeMergeRequestDetailJson(detailJson({ detailed_merge_status: "mergeable" })),
160 ).rebaseRequired,
161 ).toBe(false);
162 for (const detailed_merge_status of [undefined, "checking", "ci_still_running"]) {
163 expect(
164 expectSuccess(decodeMergeRequestDetailJson(detailJson({ detailed_merge_status })))
165 .rebaseRequired,
166 ).toBeUndefined();
167 }
168 });
169
170 it("reads the description, file count and pipeline", () => {
171 const detail = expectSuccess(
172 decodeMergeRequestDetailJson(
173 detailJson({
174 description: "Ships the page.",
175 changes_count: "3",
176 reviewers: [{ username: "julius", name: "Julius" }],
177 head_pipeline: {
178 status: "success",
179 web_url: "https://gitlab.com/acme/web/-/pipelines/9",
180 source: "merge_request_event",
181 },
182 }),
183 ),
184 );
185
186 expect(detail.body).toBe("Ships the page.");
187 expect(detail.changedFiles).toBe(3);
188 expect(detail.reviewers).toEqual([{ login: "julius", name: "Julius", avatarUrl: null }]);
189 expect(detail.checks).toEqual([
190 {
191 name: "Pipeline",
192 status: "success",
193 description: "merge_request_event",
194 url: "https://gitlab.com/acme/web/-/pipelines/9",
195 },
196 ]);
197 });
198
199 it.each(["canceled", "canceling"])("maps a %s pipeline to cancelled", (status) => {
200 const detail = expectSuccess(
201 decodeMergeRequestDetailJson(detailJson({ head_pipeline: { status } })),
202 );
203
204 expect(detail.checks[0]?.status).toBe("cancelled");
205 });
206
207 it("reads an uncounted change set as its floor", () => {
208 const detail = expectSuccess(
209 decodeMergeRequestDetailJson(detailJson({ changes_count: "1000+" })),
210 );
211
212 expect(detail.changedFiles).toBe(1000);
213 });
214
215 it("reads the head commit, and says nothing where GitLab omitted it", () => {
216 const headSha = (entry: Record<string, unknown>) =>
217 expectSuccess(decodeMergeRequestDetailJson(detailJson(entry))).headSha;
218 const sha = "afce4da4d5fe7d2fd0647b5b864526ea0a2827cb";
219
220 expect(headSha({ sha })).toBe(sha);
221 expect(headSha({ sha, diff_refs: null })).toBe(sha);
222 expect(headSha({ sha, merge_commit_sha: "0".repeat(40) })).toBe(sha);
223 expect(headSha({})).toBeUndefined();
224 expect(headSha({ sha: null })).toBeUndefined();
225 expect(headSha({ sha: " " })).toBeUndefined();
226 });
227
228 it("reads the diff refs threads are placed against", () => {
229 const diffRefs = (entry: Record<string, unknown>) =>
230 expectSuccess(decodeMergeRequestDetailJson(detailJson(entry))).diffRefs;
231
232 expect(diffRefs({ diff_refs: { base_sha: "b", start_sha: "s", head_sha: "h" } })).toEqual({
233 baseSha: "b",
234 startSha: "s",
235 headSha: "h",
236 });
237 expect(diffRefs({ diff_refs: null })).toBeUndefined();
238 expect(
239 diffRefs({ diff_refs: { base_sha: null, start_sha: "s", head_sha: "h" } }),
240 ).toBeUndefined();
241 });
242
243 it("reads either auto-merge field, and says nothing where GitLab named neither", () => {
244 const armed = (entry: Record<string, unknown>) =>
245 expectSuccess(decodeMergeRequestDetailJson(detailJson(entry))).autoMergeEnabled;
246
247 expect(armed({ merge_when_pipeline_succeeds: true })).toBe(true);
248 expect(armed({ auto_merge_enabled: true })).toBe(true);
249 expect(armed({ merge_when_pipeline_succeeds: false })).toBe(false);
250 expect(armed({})).toBeUndefined();
251 });
252
253 it("keeps the squash choice stored with auto-merge", () => {
254 expect(
255 expectSuccess(
256 decodeMergeRequestDetailJson(
257 detailJson({ auto_merge_enabled: true, squash_on_merge: true }),
258 ),
259 ),
260 ).toMatchObject({ autoMergeEnabled: true, autoMergeMethod: "squash" });
261
262 expect(
263 expectSuccess(
264 decodeMergeRequestDetailJson(
265 detailJson({
266 auto_merge_enabled: true,
267 squash: true,
268 squash_on_merge: false,
269 }),
270 ),
271 ).autoMergeMethod,
272 ).toBeUndefined();
273 });
274
275 it("keeps a divergence GitLab did not count apart from a divergence of none", () => {
276 const behind = (entry: Record<string, unknown>) =>
277 expectSuccess(decodeMergeRequestDetailJson(detailJson(entry))).divergedCommits;
278
279 expect(behind({ diverged_commits_count: 3 })).toBe(3);
280 expect(behind({ diverged_commits_count: 0 })).toBe(0);
281 expect(behind({})).toBeUndefined();
282 expect(behind({ diverged_commits_count: null })).toBeUndefined();
283 });
284
285 it.each(["scheduled", " SCHEDULED "])("keeps a delayed pipeline pending: %s", (status) => {
286 const detail = expectSuccess(
287 decodeMergeRequestDetailJson(detailJson({ head_pipeline: { status } })),
288 );
289
290 expect(detail.checks[0]?.status).toBe("pending");
291 });
292
293 it("maps a pipeline waiting on a person to neutral, not failure", () => {
294 const detail = expectSuccess(
295 decodeMergeRequestDetailJson(detailJson({ head_pipeline: { status: "manual" } })),
296 );
297
298 expect(detail.checks[0]?.status).toBe("neutral");
299 });
300});
301
302describe("decodePipelineStageChecksJson", () => {
303 function stagesJson(
304 stages: ReadonlyArray<Record<string, unknown> | null> | null,
305 hasNextPage = false,
306 projectId?: string,
307 ): string {
308 return JSON.stringify({
309 data: {
310 project: {
311 mergeRequest: {
312 headPipeline:
313 stages === null
314 ? null
315 : {
316 path: "/fork/web/-/pipelines/9",
317 ...(projectId === undefined ? {} : { project: { id: projectId } }),
318 stages: { nodes: stages, pageInfo: { hasNextPage } },
319 },
320 },
321 },
322 },
323 });
324 }
325
326 it("shows every job under its stage", () => {
327 const checks = expectSuccess(
328 decodePipelineStageChecksJson(
329 stagesJson([
330 {
331 name: "build",
332 status: "success",
333 jobs: {
334 nodes: [
335 { name: "compile", status: "FAILED", retried: true, webPath: "/acme/web/-/jobs/1" },
336 {
337 name: "compile",
338 status: "SUCCESS",
339 detailedStatus: { label: "passed" },
340 webPath: "/acme/web/-/jobs/2",
341 },
342 ],
343 },
344 },
345 {
346 name: "test",
347 status: "failed",
348 jobs: {
349 nodes: [
350 {
351 name: "unit",
352 status: "FAILED",
353 allowFailure: false,
354 webPath: "/acme/web/-/jobs/3",
355 },
356 {
357 name: "lint",
358 status: "FAILED",
359 allowFailure: true,
360 webPath: "/acme/web/-/jobs/4",
361 },
362 { name: "slow", status: "CANCELED", webPath: "/acme/web/-/jobs/5" },
363 { name: "e2e", status: "RUNNING", webPath: "/acme/web/-/jobs/6" },
364 ],
365 },
366 },
367 {
368 name: "deploy",
369 status: "manual",
370 jobs: { nodes: [{ name: "release", status: "MANUAL", webPath: "/acme/web/-/jobs/7" }] },
371 },
372 ]),
373 "https://gitlab.example.com",
374 ),
375 );
376
377 expect(checks?.map((check) => [check.name, check.status, check.url])).toEqual([
378 ["build / compile", "success", "https://gitlab.example.com/acme/web/-/jobs/2"],
379 ["test / unit", "failure", "https://gitlab.example.com/acme/web/-/jobs/3"],
380 ["test / lint", "neutral", "https://gitlab.example.com/acme/web/-/jobs/4"],
381 ["test / slow", "cancelled", "https://gitlab.example.com/acme/web/-/jobs/5"],
382 ["test / e2e", "pending", "https://gitlab.example.com/acme/web/-/jobs/6"],
383 ["deploy / release", "neutral", "https://gitlab.example.com/acme/web/-/jobs/7"],
384 ]);
385 expect(checks?.[0]?.description).toBe("passed");
386 });
387
388 it("only identifies native builds with a known pipeline project", () => {
389 const stages = [
390 {
391 name: "test",
392 status: "failed",
393 jobs: {
394 nodes: [
395 { id: "gid://gitlab/Ci::Build/1", name: "unit", status: "FAILED", retried: true },
396 { id: "gid://gitlab/Ci::Build/2", name: "unit", status: "FAILED" },
397 { id: "gid://gitlab/Ci::Bridge/3", name: "trigger", status: "FAILED" },
398 { id: "gid://gitlab/GenericCommitStatus/4", name: "external", status: "FAILED" },
399 { name: "unknown", status: "FAILED", webPath: "/fork/web/-/jobs/5" },
400 ],
401 },
402 },
403 ];
404 const decode = (projectId?: string) =>
405 expectSuccess(
406 decodePipelineStageChecksJson(stagesJson(stages, false, projectId), "https://gitlab.com"),
407 );
408
409 expect(
410 decode("gid://gitlab/Project/42")?.map(({ name, nativeId }) => [name, nativeId]),
411 ).toEqual([
412 ["test / unit", "42/2"],
413 ["test / trigger", undefined],
414 ["test / external", undefined],
415 ["test / unknown", undefined],
416 ]);
417 for (const projectId of [undefined, "gid://gitlab/Project/invalid"]) {
418 const checks = decode(projectId);
419 expect(checks).toHaveLength(4);
420 expect(checks?.every((check) => !("nativeId" in check))).toBe(true);
421 }
422 });
423
424 it.each([
425 ["no jobs", undefined],
426 ["an empty job list", { nodes: [] }],
427 [
428 "more jobs than one page",
429 { nodes: [{ name: "unit", status: "FAILED" }], pageInfo: { hasNextPage: true } },
430 ],
431 ["a job GitLab could not resolve", { nodes: [{ name: "unit", status: "FAILED" }, null] }],
432 [
433 "a job without a name",
434 {
435 nodes: [
436 { name: "unit", status: "FAILED" },
437 { name: null, status: "FAILED" },
438 ],
439 },
440 ],
441 ])("keeps a stage whole where its jobs come back with %s", (_, jobs) => {
442 expect(
443 expectSuccess(
444 decodePipelineStageChecksJson(
445 stagesJson([
446 {
447 name: "test",
448 status: "failed",
449 detailedStatus: { label: "failed", detailsPath: "/fork/web/-/pipelines/9#test" },
450 ...(jobs === undefined ? {} : { jobs }),
451 },
452 ]),
453 "https://gitlab.com",
454 ),
455 ),
456 ).toEqual([
457 {
458 name: "test",
459 status: "failure",
460 description: "failed",
461 url: "https://gitlab.com/fork/web/-/pipelines/9#test",
462 },
463 ]);
464 });
465
466 it("answers nothing where there are no stages to show", () => {
467 expect(
468 expectSuccess(decodePipelineStageChecksJson(stagesJson(null), "https://gitlab.com")),
469 ).toBe(null);
470 expect(expectSuccess(decodePipelineStageChecksJson(stagesJson([]), "https://gitlab.com"))).toBe(
471 null,
472 );
473 // A stage past the first page could be the failed one.
474 expect(
475 expectSuccess(
476 decodePipelineStageChecksJson(
477 stagesJson([{ name: "build", status: "success" }], true),
478 "https://gitlab.com",
479 ),
480 ),
481 ).toBe(null);
482 // A stage GitLab failed to resolve comes back null beside an error, and could be the failed one.
483 expect(
484 expectSuccess(
485 decodePipelineStageChecksJson(
486 stagesJson([{ name: "build", status: "success" }, null]),
487 "https://gitlab.com",
488 ),
489 ),
490 ).toBe(null);
491 expect(
492 expectSuccess(
493 decodePipelineStageChecksJson(
494 stagesJson([
495 { name: "build", status: "success" },
496 { name: null, status: "failed" },
497 ]),
498 "https://gitlab.com",
499 ),
500 ),
501 ).toBe(null);
502 expect(
503 expectSuccess(
504 decodePipelineStageChecksJson(
505 JSON.stringify({
506 ...JSON.parse(stagesJson([{ name: "build", status: "success" }])),
507 errors: [{ message: "boom" }],
508 }),
509 "https://gitlab.com",
510 ),
511 ),
512 ).toBe(null);
513 // GitLab answers an error it hit with no data at all.
514 expect(
515 expectSuccess(
516 decodePipelineStageChecksJson(
517 JSON.stringify({ errors: [{ message: "boom" }] }),
518 "https://gitlab.com",
519 ),
520 ),
521 ).toBe(null);
522 });
523});
524
525describe("decodeNotesJson", () => {
526 it("keeps comments and drops GitLab's own activity notes", () => {
527 const notes = expectSuccess(
528 decodeNotesJson(
529 JSON.stringify([
530 {
531 id: 1,
532 body: "assigned to @bilal",
533 system: true,
534 created_at: "2026-07-01T00:00:00Z",
535 },
536 {
537 id: 2,
538 body: "Looks good.",
539 author: { username: "julius" },
540 created_at: "2026-07-02T00:00:00Z",
541 },
542 { id: 3, body: " ", created_at: "2026-07-03T00:00:00Z" },
543 ]),
544 ),
545 );
546
547 expect(notes.comments).toHaveLength(1);
548 expect(notes.comments[0]).toMatchObject({
549 id: "2",
550 kind: "issue-comment",
551 body: "Looks good.",
552 });
553 expect(notes.rawCount).toBe(3);
554 });
555
556 it("reads a line note as a review comment on its file", () => {
557 const notes = expectSuccess(
558 decodeNotesJson(
559 JSON.stringify([
560 {
561 id: 7,
562 type: "DiffNote",
563 body: "Rename this.",
564 created_at: "2026-07-02T00:00:00Z",
565 position: { new_path: "src/app.ts", old_path: "src/old.ts" },
566 },
567 ]),
568 ),
569 );
570
571 expect(notes.comments[0]).toMatchObject({ kind: "review-comment", path: "src/app.ts" });
572 });
573
574 it("falls back to the old path for a note on a deleted line", () => {
575 const notes = expectSuccess(
576 decodeNotesJson(
577 JSON.stringify([
578 {
579 id: 8,
580 type: "DiffNote",
581 body: "Gone.",
582 created_at: "2026-07-02T00:00:00Z",
583 position: { new_path: null, old_path: "src/old.ts" },
584 },
585 ]),
586 ),
587 );
588
589 expect(notes.comments[0]?.path).toBe("src/old.ts");
590 });
591});
592
593describe("decodeCommitsJson", () => {
594 it("falls back to the creation timestamp when there is no commit date", () => {
595 const commits = expectSuccess(
596 decodeCommitsJson(
597 JSON.stringify([
598 {
599 id: "aaa",
600 created_at: "2026-07-01T00:00:00+08:00",
601 author_name: "Ada Lovelace",
602 author_email: "ada@example.com",
603 },
604 ]),
605 ),
606 );
607
608 expect(commits[0]).toMatchObject({
609 oid: "aaa",
610 committedDate: "2026-07-01T00:00:00+08:00",
611 authors: [{ login: "Ada Lovelace", name: "Ada Lovelace", avatarUrl: null }],
612 });
613 });
614});
615
616describe("decodeMergeRequestDiffsJson", () => {
617 it("quotes literal backslashes without interpreting them as escapes", () => {
618 const result = expectSuccess(
619 decodeMergeRequestDiffsJson(
620 JSON.stringify([
621 {
622 old_path: String.raw`src\notes.ts`,
623 new_path: String.raw`src\notes.ts`,
624 diff: "@@ -1 +1 @@\n-old\n+new",
625 },
626 ]),
627 ),
628 );
629
630 expect(result.patch).toBe(
631 [
632 String.raw`diff --git "a/src\\notes.ts" "b/src\\notes.ts"`,
633 String.raw`--- "a/src\\notes.ts"`,
634 String.raw`+++ "b/src\\notes.ts"`,
635 "@@ -1 +1 @@",
636 "-old",
637 "+new",
638 "",
639 ].join("\n"),
640 );
641 });
642
643 it("preserves spaces and literal backslashes in both rename paths", () => {
644 const result = expectSuccess(
645 decodeMergeRequestDiffsJson(
646 JSON.stringify([
647 {
648 old_path: String.raw` old\name.ts `,
649 new_path: String.raw` new\name.ts `,
650 renamed_file: true,
651 diff: "",
652 },
653 ]),
654 ),
655 );
656
657 expect(result.patch).toBe(
658 [
659 String.raw`diff --git "a/ old\\name.ts " "b/ new\\name.ts "`,
660 "similarity index 100%",
661 String.raw`rename from " old\\name.ts "`,
662 String.raw`rename to " new\\name.ts "`,
663 String.raw`--- "a/ old\\name.ts "`,
664 String.raw`+++ "b/ new\\name.ts "`,
665 ].join("\n"),
666 );
667 });
668
669 it("assembles a unified patch GitLab does not return", () => {
670 const result = expectSuccess(
671 decodeMergeRequestDiffsJson(
672 JSON.stringify([
673 {
674 old_path: "src/app.ts",
675 new_path: "src/app.ts",
676 diff: "@@ -1 +1 @@\n-old\n+new\n",
677 },
678 ]),
679 ),
680 );
681
682 expect(result.patch).toBe(
683 [
684 "diff --git a/src/app.ts b/src/app.ts",
685 "--- a/src/app.ts",
686 "+++ b/src/app.ts",
687 "@@ -1 +1 @@",
688 "-old",
689 "+new",
690 "",
691 ].join("\n"),
692 );
693 expect(result.truncated).toBe(false);
694 });
695
696 it("points a new file at /dev/null on the left and a deleted file on the right", () => {
697 const result = expectSuccess(
698 decodeMergeRequestDiffsJson(
699 JSON.stringify([
700 {
701 old_path: "src/new.ts",
702 new_path: "src/new.ts",
703 new_file: true,
704 b_mode: "100755",
705 diff: "@@ -0,0 +1 @@\n+hello\n",
706 },
707 {
708 old_path: "src/gone.ts",
709 new_path: "src/gone.ts",
710 deleted_file: true,
711 diff: "@@ -1 +0,0 @@\n-bye\n",
712 },
713 ]),
714 ),
715 );
716
717 expect(result.patch).toContain("new file mode 100755");
718 expect(result.patch).toContain("--- /dev/null");
719 expect(result.patch).toContain("deleted file mode 100644");
720 expect(result.patch).toContain("+++ /dev/null");
721 });
722
723 it("reports truncation for a file GitLab refused to inline", () => {
724 const result = expectSuccess(
725 decodeMergeRequestDiffsJson(
726 JSON.stringify([{ old_path: "big.bin", new_path: "big.bin", diff: "", too_large: true }]),
727 ),
728 );
729
730 expect(result.truncated).toBe(true);
731 expect(result.patch).toContain("diff --git a/big.bin b/big.bin");
732 expect(result.withheldPaths).toEqual(["big.bin"]);
733 });
734
735 it("reports how many files GitLab returned, so the caller can page", () => {
736 const result = expectSuccess(
737 decodeMergeRequestDiffsJson(
738 JSON.stringify(
739 Array.from({ length: 3 }, (_, index) => ({
740 old_path: `src/${index}.ts`,
741 new_path: `src/${index}.ts`,
742 diff: "@@ -1 +1 @@\n-a\n+b\n",
743 })),
744 ),
745 ),
746 );
747
748 expect(result.rawCount).toBe(3);
749 expect(result.truncated).toBe(false);
750 expect(result.patch).toContain("src/2.ts");
751 });
752});
753
754describe("decodeTriggerJobChecksJson", () => {
755 it("reads a downstream failure GitLab was told to allow as neutral, not failure", () => {
756 const result = expectSuccess(
757 decodeTriggerJobChecksJson(
758 JSON.stringify([
759 { name: "e2e", allow_failure: true, downstream_pipeline: { status: "failed" } },
760 { name: "deploy", allow_failure: false, downstream_pipeline: { status: "running" } },
761 { name: 7 },
762 ]),
763 ),
764 );
765
766 expect(result.checks.map((check) => [check.name, check.status])).toEqual([
767 ["e2e", "neutral"],
768 ["deploy", "pending"],
769 ]);
770 expect(result.rawCount).toBe(3);
771 });
772});
773
774describe("merge request viewer fields", () => {
775 it("leaves merging permitted where GitLab answered without the field", () => {
776 expect(expectSuccess(decodeMergeRequestDetailJson(detailJson({}))).viewerCanMerge).toBe(true);
777 expect(
778 expectSuccess(decodeMergeRequestDetailJson(detailJson({ user: null }))).viewerCanMerge,
779 ).toBe(true);
780 });
781});
782
783describe("decodeAwardEmojiJson", () => {
784 it("reads MR-level awards, keys per-note awards by the REST id inside their gid, ignores an award outside the eight, and collects bot note authors", () => {
785 const result = expectSuccess(
786 decodeAwardEmojiJson(
787 JSON.stringify({
788 data: {
789 currentUser: { username: "bilal" },
790 project: {
791 mergeRequest: {
792 awardEmoji: {
793 nodes: [
794 { name: "thumbsup", user: { username: "bilal" } },
795 { name: "thumbsup", user: { username: "julius" } },
796 ],
797 },
798 notes: {
799 pageInfo: { hasNextPage: false, endCursor: null },
800 nodes: [
801 {
802 id: "gid://gitlab/DiffNote/42",
803 author: { username: "julius", bot: false },
804 awardEmoji: { nodes: [{ name: "heart", user: { username: "julius" } }] },
805 },
806 {
807 id: "gid://gitlab/Note/7",
808 author: { username: "project_278964_bot_89f97e2c", bot: true },
809 awardEmoji: {
810 nodes: [{ name: "partyparrot", user: { username: "bilal" } }],
811 },
812 },
813 ],
814 },
815 },
816 },
817 },
818 }),
819 ),
820 );
821
822 expect(result.reactions).toEqual([
823 { content: "thumbs-up", count: 2, actors: ["julius"], viewerHasReacted: true },
824 ]);
825 expect([...result.reactionsByNoteId]).toEqual([
826 ["42", [{ content: "heart", count: 1, actors: ["julius"], viewerHasReacted: false }]],
827 ]);
828 expect([...result.botLogins]).toEqual(["project_278964_bot_89f97e2c"]);
829 expect(result.nextCursor).toBeNull();
830 });
831
832 it("dates a note's edit only when someone edited its text, not when its thread was resolved", () => {
833 const result = expectSuccess(
834 decodeAwardEmojiJson(
835 JSON.stringify({
836 data: {
837 currentUser: { username: "bilal" },
838 project: {
839 mergeRequest: {
840 awardEmoji: { nodes: [] },
841 notes: {
842 pageInfo: { hasNextPage: false, endCursor: null },
843 nodes: [
844 {
845 id: "gid://gitlab/Note/1",
846 lastEditedAt: "2026-07-02T00:00:00Z",
847 lastEditedBy: { username: "julius" },
848 resolved: false,
849 },
850 {
851 id: "gid://gitlab/Note/2",
852 lastEditedAt: "2026-07-01T00:00:00Z",
853 lastEditedBy: null,
854 resolved: false,
855 },
856 {
857 id: "gid://gitlab/DiscussionNote/3",
858 lastEditedAt: "2026-07-03T00:00:00Z",
859 lastEditedBy: { username: "julius" },
860 resolved: true,
861 },
862 ],
863 },
864 },
865 },
866 },
867 }),
868 ),
869 );
870
871 expect([...result.editedAtByNoteId]).toEqual([["1", "2026-07-02T00:00:00Z"]]);
872 });
873
874 it("matches the viewer's username case-insensitively, since GitLab is not consistent about case", () => {
875 const result = expectSuccess(
876 decodeAwardEmojiJson(
877 JSON.stringify({
878 data: {
879 currentUser: { username: "Bilal" },
880 project: {
881 mergeRequest: {
882 awardEmoji: {
883 nodes: [
884 { name: "heart", user: { username: "bilal" } },
885 { name: "heart", user: { username: "julius" } },
886 ],
887 },
888 notes: { pageInfo: { hasNextPage: false, endCursor: null }, nodes: [] },
889 },
890 },
891 },
892 }),
893 ),
894 );
895
896 expect(result.reactions).toEqual([
897 { content: "heart", count: 2, actors: ["julius"], viewerHasReacted: true },
898 ]);
899 });
900});
901
902describe("decodeOwnAwardIdJson", () => {
903 const awards = JSON.stringify([
904 { id: 101, name: "thumbsup", user: { username: "julius" } },
905 { id: 102, name: "thumbsup", user: { username: "bilal" } },
906 ]);
907
908 it("finds the reader's own award of that name, which is the one a removal deletes", () => {
909 expect(
910 expectSuccess(decodeOwnAwardIdJson(awards, { content: "thumbs-up", viewer: "bilal" })),
911 ).toEqual({ id: 102, empty: false });
912 });
913});
914
915describe("decodeRepositoryBlobsJson", () => {
916 function expectBlobs(result: Result.Result<ReadonlyMap<string, string> | null, unknown>) {
917 const blobs = expectSuccess(result);
918 expect(blobs).not.toBe(null);
919 if (blobs === null) throw new Error("expected an answered blobs query");
920 return blobs;
921 }
922
923 it("leaves out a node missing either half, which names no version", () => {
924 const blobs = expectBlobs(
925 decodeRepositoryBlobsJson(
926 JSON.stringify({
927 data: {
928 project: {
929 repository: {
930 blobs: {
931 nodes: [
932 { path: "src/a.ts", oid: null },
933 { path: null, oid: "bbb222" },
934 null,
935 { path: "src/c.ts", oid: "ccc333" },
936 ],
937 },
938 },
939 },
940 },
941 }),
942 ),
943 );
944
945 expect([...blobs]).toEqual([["src/c.ts", "ccc333"]]);
946 });
947
948 it("keys a blob by the path the host spelled, spaces and all", () => {
949 const blobs = expectBlobs(
950 decodeRepositoryBlobsJson(
951 JSON.stringify({
952 data: {
953 project: {
954 repository: {
955 blobs: {
956 nodes: [
957 { path: " leading.ts", oid: "aaa111" },
958 { path: "trailing.ts ", oid: "bbb222" },
959 { path: " ", oid: "ccc333" },
960 { path: "", oid: "ddd444" },
961 ],
962 },
963 },
964 },
965 },
966 }),
967 ),
968 );
969
970 expect([...blobs]).toEqual([
971 [" leading.ts", "aaa111"],
972 ["trailing.ts ", "bbb222"],
973 [" ", "ccc333"],
974 ]);
975 });
976
977 it("tells a project the reader cannot see from a revision with none of the files", () => {
978 expect(
979 expectSuccess(decodeRepositoryBlobsJson(JSON.stringify({ data: { project: null } }))),
980 ).toBe(null);
981 expect(
982 expectSuccess(
983 decodeRepositoryBlobsJson(JSON.stringify({ data: { project: { repository: null } } })),
984 ),
985 ).toBe(null);
986 expect(
987 expectSuccess(
988 decodeRepositoryBlobsJson(
989 JSON.stringify({ data: { project: { repository: { blobs: { nodes: [] } } } } }),
990 ),
991 ),
992 ).toEqual(new Map());
993 });
994});
995
996describe("decodeListStatesJson", () => {
997 const statesOf = (enterprise: boolean | null, nodes: ReadonlyArray<unknown>) =>
998 expectSuccess(
999 decodeListStatesJson(
1000 JSON.stringify({
1001 data: {
1002 metadata: enterprise === null ? null : { enterprise },
1003 project: { mergeRequests: { nodes } },
1004 },
1005 }),
1006 ),
1007 );
1008 const approvedBy = (...usernames: ReadonlyArray<string>) => ({
1009 nodes: usernames.map((username) => ({ username })),
1010 });
1011 const reviewers = (...reviewStates: ReadonlyArray<string>) => ({
1012 nodes: reviewStates.map((reviewState) => ({ mergeRequestInteraction: { reviewState } })),
1013 });
1014
1015 it.each([
1016 {
1017 reading: "an approval short of Enterprise approval rules",
1018 enterprise: true,
1019 approval: { approved: false, approvedBy: approvedBy("GitLabDuo") },
1020 decision: "review-required",
1021 },
1022 {
1023 reading: "Enterprise approval rules no one has approved against",
1024 enterprise: true,
1025 approval: { approved: false, approvedBy: approvedBy() },
1026 decision: "review-required",
1027 },
1028 {
1029 reading: "Enterprise approval rules met",
1030 enterprise: true,
1031 approval: { approved: true, approvedBy: approvedBy("julius") },
1032 decision: "approved",
1033 },
1034 {
1035 reading: "Enterprise without approval rules or approvals",
1036 enterprise: true,
1037 approval: { approved: true, approvedBy: approvedBy() },
1038 decision: null,
1039 },
1040 {
1041 reading: "Community Edition with an approval",
1042 enterprise: false,
1043 approval: { approved: true, approvedBy: approvedBy("julius") },
1044 decision: "approved",
1045 },
1046 {
1047 reading: "Community Edition without approvals",
1048 enterprise: false,
1049 approval: { approved: false, approvedBy: approvedBy() },
1050 decision: null,
1051 },
1052 {
1053 reading: "a reviewer requesting changes after another approved",
1054 enterprise: true,
1055 approval: {
1056 approved: true,
1057 approvedBy: approvedBy("julius"),
1058 reviewers: reviewers("APPROVED", "REQUESTED_CHANGES"),
1059 },
1060 decision: "changes-requested",
1061 },
1062 {
1063 reading: "a Community Edition reviewer requesting changes",
1064 enterprise: false,
1065 approval: {
1066 approved: false,
1067 approvedBy: approvedBy(),
1068 reviewers: reviewers("REQUESTED_CHANGES"),
1069 },
1070 decision: "changes-requested",
1071 },
1072 {
1073 reading: "reviewers who have not asked for changes",
1074 enterprise: false,
1075 approval: {
1076 approved: true,
1077 approvedBy: approvedBy("julius"),
1078 reviewers: reviewers("UNREVIEWED", "REVIEWED"),
1079 },
1080 decision: "approved",
1081 },
1082 ])("reads $reading as $decision", ({ enterprise, approval, decision }) => {
1083 expect([...statesOf(enterprise, [{ iid: "7", ...approval }])]).toEqual([
1084 [7, { reviewDecision: decision, checksState: null }],
1085 ]);
1086 });
1087
1088 it.each([
1089 { pipeline: { status: "SUCCESS" }, checksState: "passing" },
1090 { pipeline: { status: "FAILED" }, checksState: "failing" },
1091 { pipeline: { status: "CANCELED" }, checksState: "failing" },
1092 { pipeline: { status: "RUNNING" }, checksState: "pending" },
1093 { pipeline: { status: "WAITING_FOR_RESOURCE" }, checksState: "pending" },
1094 { pipeline: { status: "MANUAL" }, checksState: null },
1095 { pipeline: { status: "SKIPPED" }, checksState: null },
1096 { pipeline: null, checksState: null },
1097 ])(
1098 "reads a $pipeline.status head pipeline as $checksState checks",
1099 ({ pipeline, checksState }) => {
1100 expect([
1101 ...statesOf(false, [
1102 { iid: "7", approved: false, approvedBy: approvedBy(), headPipeline: pipeline },
1103 ]),
1104 ]).toEqual([[7, { reviewDecision: null, checksState }]]);
1105 },
1106 );
1107
1108 it("leaves out a merge request it cannot key, and a project the reader cannot see", () => {
1109 expect([...statesOf(true, [null, { iid: "x", approved: true }])]).toEqual([]);
1110 expect(
1111 expectSuccess(decodeListStatesJson(JSON.stringify({ data: { project: null } }))),
1112 ).toEqual(new Map());
1113 });
1114
1115 it("keeps the checks of a merge request whose approval it cannot judge", () => {
1116 expect([
1117 ...statesOf(null, [
1118 {
1119 iid: "7",
1120 approved: false,
1121 approvedBy: approvedBy(),
1122 headPipeline: { status: "FAILED" },
1123 },
1124 ]),
1125 ...statesOf(true, [
1126 { iid: "8", approved: null, approvedBy: approvedBy("julius") },
1127 { iid: "9", approved: true, approvedBy: null },
1128 ]),
1129 ]).toEqual([
1130 [7, { checksState: "failing" }],
1131 [8, { checksState: null }],
1132 [9, { checksState: null }],
1133 ]);
1134 });
1135});
1136
1137describe("decodeReferenceCandidatesJson", () => {
1138 it("prefixes merge requests with ! and skips malformed entries", () => {
1139 const raw = JSON.stringify([
1140 { iid: 5, title: "Ship it", state: "merged" },
1141 { iid: 6, title: "Draft", state: "opened" },
1142 { iid: 7, title: "Locked", state: "locked" },
1143 { title: "No iid", state: "opened" },
1144 ]);
1145 const decoded = decodeReferenceCandidatesJson(raw, "change-request");
1146 expect(Result.isSuccess(decoded) && decoded.success).toEqual({
1147 items: [
1148 { reference: "!5", kind: "change-request", number: 5, title: "Ship it", state: "merged" },
1149 { reference: "!6", kind: "change-request", number: 6, title: "Draft", state: "open" },
1150 { reference: "!7", kind: "change-request", number: 7, title: "Locked", state: "closed" },
1151 ],
1152 rawCount: 4,
1153 });
1154 const issues = decodeReferenceCandidatesJson(raw, "issue");
1155 expect(Result.isSuccess(issues) && issues.success.items[0]?.reference).toBe("#5");
1156 });
1157});
1158
1159describe("decodeMergeRequestStatsJson", () => {
1160 it("keys the counts by merge request number", () => {
1161 const stats = expectSuccess(
1162 decodeMergeRequestStatsJson(
1163 JSON.stringify({
1164 data: {
1165 project: {
1166 mergeRequests: {
1167 nodes: [
1168 { iid: "7", diffStatsSummary: { additions: 12, deletions: 3 } },
1169 { iid: "8", diffStatsSummary: null },
1170 ],
1171 },
1172 },
1173 },
1174 }),
1175 ),
1176 );
1177
1178 // A merge request without a summary is left out rather than shown as zero lines changed.
1179 expect([...stats]).toEqual([[7, { additions: 12, deletions: 3 }]]);
1180 });
1181
1182 it("answers nothing for a project the token cannot see", () => {
1183 const stats = expectSuccess(
1184 decodeMergeRequestStatsJson(JSON.stringify({ data: { project: null } })),
1185 );
1186
1187 expect(stats.size).toBe(0);
1188 });
1189
1190 it("reports a file list shorter than the summary as truncated", () => {
1191 const read = (fileCount: number) =>
1192 expectSuccess(
1193 decodeMergeRequestFileStatsJson(
1194 JSON.stringify({
1195 data: {
1196 project: {
1197 mergeRequest: {
1198 diffStatsSummary: { fileCount },
1199 diffStats: [{ path: "src/a.ts", additions: 2, deletions: 1 }],
1200 },
1201 },
1202 },
1203 }),
1204 ),
1205 );
1206
1207 expect(read(1)).toEqual({
1208 files: [{ path: "src/a.ts", additions: 2, deletions: 1 }],
1209 truncated: false,
1210 });
1211 expect(read(2).truncated).toBe(true);
1212 });
1213});
1214
1215describe("decodeMergeRequestGraphqlListJson", () => {
1216 it("reads a row and its review state in one page, counting rows it cannot read", () => {
1217 const page = expectSuccess(
1218 decodeMergeRequestGraphqlListJson(
1219 JSON.stringify({
1220 data: {
1221 metadata: { enterprise: false },
1222 project: {
1223 mergeRequests: {
1224 pageInfo: { hasNextPage: true, endCursor: "eyJpZCI6IjcifQ" },
1225 nodes: [
1226 {
1227 iid: "7",
1228 title: "Add the merge requests page",
1229 webUrl: "https://gitlab.com/acme/web/-/merge_requests/7",
1230 state: "opened",
1231 draft: true,
1232 createdAt: "2026-07-01T00:00:00Z",
1233 updatedAt: "2026-07-02T00:00:00Z",
1234 sourceBranch: "feat/page",
1235 targetBranch: "main",
1236 conflicts: true,
1237 mergeStatusEnum: "CHECKING",
1238 author: {
1239 username: "bilal",
1240 name: "Bilal",
1241 avatarUrl: "/uploads/-/system/user/avatar/42/avatar.png?v=1",
1242 },
1243 labels: { nodes: [{ title: "bug", color: "#E24329", description: null }] },
1244 approved: false,
1245 approvedBy: { nodes: [] },
1246 reviewers: {
1247 nodes: [
1248 {
1249 username: "julius",
1250 mergeRequestInteraction: { reviewState: "REQUESTED_CHANGES" },
1251 },
1252 ],
1253 },
1254 headPipeline: { status: "FAILED" },
1255 },
1256 { iid: "8" },
1257 ],
1258 },
1259 },
1260 },
1261 }),
1262 ),
1263 );
1264
1265 expect(page.items).toEqual([
1266 expect.objectContaining({
1267 number: 7,
1268 author: {
1269 login: "bilal",
1270 name: "Bilal",
1271 avatarUrl: "https://gitlab.com/uploads/-/system/user/avatar/42/avatar.png?v=1",
1272 },
1273 state: "open",
1274 isDraft: true,
1275 mergeability: "conflicting",
1276 reviewRequestLogins: ["julius"],
1277 labels: [{ name: "bug", color: "#E24329", description: null }],
1278 }),
1279 ]);
1280 expect([...page.states]).toEqual([
1281 [7, { reviewDecision: "changes-requested", checksState: "failing" }],
1282 ]);
1283 expect(page).toMatchObject({ rawCount: 2, hasNextPage: true, endCursor: "eyJpZCI6IjcifQ" });
1284 });
1285
1286 it.each(["", " "])(
1287 "keeps a blank GraphQL avatarUrl as null, not the merge request page",
1288 (avatarUrl) => {
1289 const page = expectSuccess(
1290 decodeMergeRequestGraphqlListJson(
1291 JSON.stringify({
1292 data: {
1293 metadata: { enterprise: false },
1294 project: {
1295 mergeRequests: {
1296 pageInfo: { hasNextPage: false, endCursor: null },
1297 nodes: [
1298 {
1299 iid: "7",
1300 title: "Add the merge requests page",
1301 webUrl: "https://gitlab.com/acme/web/-/merge_requests/7",
1302 state: "opened",
1303 createdAt: "2026-07-01T00:00:00Z",
1304 updatedAt: "2026-07-02T00:00:00Z",
1305 sourceBranch: "feat/page",
1306 targetBranch: "main",
1307 author: { username: "bilal", name: "Bilal", avatarUrl },
1308 },
1309 ],
1310 },
1311 },
1312 },
1313 }),
1314 ),
1315 );
1316
1317 expect(page.items[0]?.author).toEqual({
1318 login: "bilal",
1319 name: "Bilal",
1320 avatarUrl: null,
1321 });
1322 },
1323 );
1324
1325 it("fails on a project the reader cannot see, rather than reading it as empty", () => {
1326 expect(
1327 Result.isFailure(
1328 decodeMergeRequestGraphqlListJson(
1329 JSON.stringify({ data: { metadata: { enterprise: true }, project: null } }),
1330 ),
1331 ),
1332 ).toBe(true);
1333 });
1334});
1335
1336describe("decodeGraphqlListSupportJson", () => {
1337 it.each([
1338 { version: "17.8.4", supported: false },
1339 { version: "17.9.0", supported: true },
1340 { version: "19.6.0-pre", supported: true },
1341 { version: null, supported: false },
1342 ])("reads GitLab $version as supported: $supported", ({ version, supported }) => {
1343 expect(
1344 expectSuccess(
1345 decodeGraphqlListSupportJson(JSON.stringify({ data: { metadata: { version } } })),
1346 ),
1347 ).toBe(supported);
1348 });
1349});
1350
1351describe("decodeMergeMessagesJson", () => {
1352 it("fails a partial response instead of reading errored fields as absent templates", () => {
1353 const decoded = decodeMergeMessagesJson(
1354 JSON.stringify({
1355 errors: [{ message: "Internal server error", path: ["project", "mergeRequest"] }],
1356 data: {
1357 project: { mergeRequest: { title: "Add thing", defaultMergeCommitMessage: null } },
1358 },
1359 }),
1360 );
1361
1362 expect(Result.isFailure(decoded)).toBe(true);
1363 });
1364});
1365
1366describe("decodeMergeRequestWatchFingerprintJson", () => {
1367 const pipeline = (status: string, downstream: string, failed = 0, moreBridges = false) => ({
1368 id: "gid://gitlab/Ci::Pipeline/9",
1369 status,
1370 succeeded: { count: 3 },
1371 failed: { count: failed },
1372 stopped: { count: 0 },
1373 jobs: {
1374 pageInfo: { hasNextPage: moreBridges },
1375 nodes: [
1376 {
1377 name: "deploy",
1378 status,
1379 downstreamPipeline: { id: "gid://gitlab/Ci::Pipeline/10", status: downstream },
1380 },
1381 ],
1382 },
1383 });
1384 const edit = (at: string, resolved = false) => ({
1385 lastEditedAt: at,
1386 lastEditedBy: { username: "reviewer" },
1387 resolved,
1388 });
1389 const read = (overrides: Record<string, unknown>) =>
1390 expectSuccess(
1391 decodeMergeRequestWatchFingerprintJson(
1392 JSON.stringify({
1393 data: {
1394 project: {
1395 mergeRequest: {
1396 state: "opened",
1397 mergeStatusEnum: "CAN_BE_MERGED",
1398 detailedMergeStatus: "MERGEABLE",
1399 conflicts: false,
1400 diffHeadSha: "a".repeat(40),
1401 userPermissions: { updateMergeRequest: true },
1402 headPipeline: pipeline("RUNNING", "RUNNING"),
1403 userNotesCount: 2,
1404 notes: {
1405 nodes: [
1406 edit("2026-07-02T00:00:00Z"),
1407 { lastEditedAt: null, lastEditedBy: null, resolved: null },
1408 edit("2026-07-01T00:00:00Z"),
1409 ],
1410 },
1411 ...overrides,
1412 },
1413 },
1414 },
1415 }),
1416 ),
1417 );
1418
1419 // A remarks change makes the watch reread every comment, so pipeline progress must not touch it.
1420 it("moves pipeline progress into status and comment edits into remarks", () => {
1421 const base = read({});
1422 const passed = read({ headPipeline: pipeline("SUCCESS", "RUNNING") });
1423 const downstreamPassed = read({ headPipeline: pipeline("SUCCESS", "SUCCESS") });
1424 const jobFailed = read({ headPipeline: pipeline("RUNNING", "RUNNING", 1) });
1425 const edited = read({ notes: { nodes: [edit("2026-07-03T00:00:00Z")] } });
1426 // Resolving a thread restamps its notes without an edit, so it must not reread comments.
1427 const resolved = read({
1428 notes: { nodes: [edit("2026-07-02T00:00:00Z"), edit("2026-07-03T00:00:00Z", true)] },
1429 });
1430
1431 expect(base?.remarks).toBe("2 2026-07-02T00:00:00Z");
1432 expect(passed?.status).not.toBe(base?.status);
1433 expect(downstreamPassed?.status).not.toBe(passed?.status);
1434 expect(jobFailed?.status).not.toBe(base?.status);
1435 expect(passed?.remarks).toBe(base?.remarks);
1436 expect(edited?.status).toBe(base?.status);
1437 expect(edited?.remarks).not.toBe(base?.remarks);
1438 expect(resolved?.remarks).toBe(base?.remarks);
1439 expect(read({ userNotesCount: 3 })?.remarks).not.toBe(base?.remarks);
1440 // A target branch moving on leaves merge_status at can_be_merged on fast-forward projects.
1441 expect(read({ detailedMergeStatus: "NEED_REBASE" })?.status).not.toBe(base?.status);
1442 });
1443
1444 // Only the REST read asks GitLab to recheck mergeability, and only for viewers who can update.
1445 it("covers the detail read once merge status has settled or no read could settle it", () => {
1446 expect(read({})?.coversDetail).toBe(true);
1447 // A capped job count or a second bridge page can hide a job settling.
1448 expect(read({ headPipeline: pipeline("RUNNING", "RUNNING", 1001) })?.coversDetail).toBe(false);
1449 expect(read({ headPipeline: pipeline("RUNNING", "RUNNING", 0, true) })?.coversDetail).toBe(
1450 false,
1451 );
1452 expect(read({ mergeStatusEnum: "UNCHECKED" })?.coversDetail).toBe(false);
1453 expect(read({ mergeStatusEnum: "CHECKING", conflicts: true })?.coversDetail).toBe(true);
1454 expect(
1455 read({ mergeStatusEnum: "UNCHECKED", userPermissions: { updateMergeRequest: false } })
1456 ?.coversDetail,
1457 ).toBe(true);
1458 });
1459
1460 it("answers null when GitLab returned no merge request", () => {
1461 expect(
1462 expectSuccess(
1463 decodeMergeRequestWatchFingerprintJson(
1464 JSON.stringify({ data: { project: { mergeRequest: null } } }),
1465 ),
1466 ),
1467 ).toBeNull();
1468 });
1469});