Open History to see the last commit
1import {
2 ProjectId,
3 type ThreadPullRequestLink,
4 type ThreadPullRequestSnapshot,
5} from "@t3tools/contracts";
6import { beforeEach, describe, expect, it } from "vite-plus/test";
7
8import { foldSearchQuery, scoreThreadSearch } from "@t3tools/shared/paletteSearch";
9import { threadSearchPullRequests } from "@t3tools/shared/threadPullRequests";
10
11import {
12 legacyThreadPullRequestKey,
13 pullRequestListLines,
14 threadPullRequestSearchTerms,
15 resolveThreadCurrentPullRequest,
16 resolveThreadPullRequestChains,
17 resolveThreadPullRequestBadge,
18 threadPullRequestKeysEqual,
19 visibleThreadPullRequests,
20} from "./threadPullRequests.ts";
21
22// Remove ES2023 array methods to match Hermes on mobile.
23beforeEach(() => {
24 const methods = ["toSorted", "toReversed", "toSpliced"] as const;
25 const descriptors = methods.map((method) =>
26 Object.getOwnPropertyDescriptor(Array.prototype, method),
27 );
28 for (const method of methods) Reflect.deleteProperty(Array.prototype, method);
29 return () => {
30 for (const [index, method] of methods.entries()) {
31 const descriptor = descriptors[index];
32 if (descriptor) Reflect.defineProperty(Array.prototype, method, descriptor);
33 }
34 };
35});
36
37function snapshot(input: Partial<ThreadPullRequestSnapshot> = {}): ThreadPullRequestSnapshot {
38 return {
39 state: "open",
40 title: "Change",
41 headBranch: "feature",
42 baseBranch: "main",
43 isDraft: false,
44 updatedAt: "2026-01-01T00:00:00.000Z",
45 syncedAt: "2026-01-01T00:00:00.000Z",
46 ...input,
47 };
48}
49
50function link(
51 number: number,
52 input: Partial<Omit<ThreadPullRequestLink, "number">> = {},
53): ThreadPullRequestLink {
54 return {
55 host: "github.com",
56 repository: "pingdotgg/t3code",
57 number,
58 url: `https://github.com/pingdotgg/t3code/pull/${number}`,
59 source: "manual",
60 linkedAt: `2026-01-01T00:00:${String(number).padStart(2, "0")}.000Z`,
61 snapshot: null,
62 stack: null,
63 ...input,
64 };
65}
66
67describe("threadPullRequestKeysEqual", () => {
68 it("recovers Forgejo ports from old stored URLs and keeps separate servers distinct", () => {
69 const old = link(1, {
70 host: "forge.example",
71 repository: "team/repo",
72 url: "http://forge.example:3000/team/repo/pulls/1",
73 });
74 expect(threadPullRequestKeysEqual(old, { ...old, host: "forge.example:3000" })).toBe(true);
75 expect(
76 threadPullRequestKeysEqual(old, {
77 host: "forge.example:3000",
78 repository: "team/repo",
79 number: 1,
80 }),
81 ).toBe(true);
82 expect(
83 threadPullRequestKeysEqual(old, {
84 ...old,
85 url: "http://forge.example:4000/team/repo/pulls/1",
86 }),
87 ).toBe(false);
88 });
89
90 it("recovers Azure repository keys from stored URLs", () => {
91 const own = link(7, {
92 host: "dev.azure.com",
93 repository: "org-a/project/_git/web",
94 url: "https://dev.azure.com/org-a/project/_git/web/pullrequest/7",
95 });
96 expect(legacyThreadPullRequestKey({ ...own, repository: "web" })).toEqual({
97 host: "dev.azure.com",
98 repository: "org-a/project/_git/web",
99 number: 7,
100 });
101 expect(
102 threadPullRequestKeysEqual(own, {
103 host: "org-a.visualstudio.com",
104 repository: "DefaultCollection/project/_git/web",
105 number: 7,
106 }),
107 ).toBe(true);
108 });
109});
110
111describe("resolveThreadCurrentPullRequest", () => {
112 it("selects the same terminal link as stable sorting across input orders", () => {
113 const dates = ["invalid", "1969-01-01T00:00:00.000Z", "2026-01-01T00:00:00.000Z"];
114 for (let offset = 0; offset < dates.length; offset++) {
115 const links = Array.from({ length: 12 }, (_, index) =>
116 link(index + 1, {
117 snapshot: snapshot({
118 state: "merged",
119 updatedAt: dates[(index + offset) % dates.length]!,
120 }),
121 }),
122 );
123 for (const input of [links, [...links].sort((left, right) => right.number - left.number)]) {
124 const expected = [...input].sort(
125 (left, right) =>
126 (Date.parse(right.snapshot?.updatedAt ?? right.linkedAt) || 0) -
127 (Date.parse(left.snapshot?.updatedAt ?? left.linkedAt) || 0),
128 )[0];
129 expect(resolveThreadCurrentPullRequest(input)).toEqual({ kind: "single", link: expected });
130 }
131 }
132 });
133
134 it("preserves input order when open chains have equal link dates", () => {
135 const linkedAt = "2026-01-01T00:00:00.000Z";
136 const current = resolveThreadCurrentPullRequest([
137 link(3, { linkedAt }),
138 link(1, { linkedAt }),
139 link(2, { linkedAt }),
140 ]);
141 expect(current?.kind === "stack" ? current.open.map((entry) => entry.number) : null).toEqual([
142 3, 1, 2,
143 ]);
144 });
145
146 it("keeps the first terminal link on ties and treats invalid update dates as zero", () => {
147 const first = link(3, { snapshot: snapshot({ state: "merged", updatedAt: "invalid" }) });
148 const second = link(1, {
149 snapshot: snapshot({ state: "closed", updatedAt: "1970-01-01T00:00:00.000Z" }),
150 });
151 expect(resolveThreadCurrentPullRequest([first, second])).toEqual({
152 kind: "single",
153 link: first,
154 });
155 expect(resolveThreadCurrentPullRequest([second, first])).toEqual({
156 kind: "single",
157 link: second,
158 });
159 });
160
161 it("prefers the single open link over terminal ones", () => {
162 const current = resolveThreadCurrentPullRequest([
163 link(1, { snapshot: snapshot({ state: "merged" }) }),
164 link(2, { snapshot: snapshot({ state: "open" }) }),
165 link(3, { snapshot: snapshot({ state: "closed" }) }),
166 ]);
167 expect(current).toMatchObject({ kind: "single", link: { number: 2 } });
168 });
169
170 it("reports a stack when several links are open and puts the highest layer on top", () => {
171 const stack = {
172 kind: "native" as const,
173 id: "s1",
174 number: 1,
175 url: "https://github.com/pingdotgg/t3code/stacks/1",
176 base: "main",
177 layers: [
178 { number: 10, headBranch: "a", state: "open" as const },
179 { number: 11, headBranch: "b", state: "open" as const },
180 ],
181 };
182 const current = resolveThreadCurrentPullRequest([
183 link(11, { snapshot: snapshot(), stack }),
184 link(10, { snapshot: snapshot(), stack }),
185 ]);
186 expect(current).toMatchObject({ kind: "stack", top: { number: 11 } });
187 if (current?.kind === "stack") {
188 expect(current.open.map((entry) => entry.number)).toEqual([11, 10]);
189 }
190 });
191
192 it("orders an open set without stack data by most recent link", () => {
193 const current = resolveThreadCurrentPullRequest([link(1), link(2)]);
194 expect(current).toMatchObject({ kind: "stack", top: { number: 2 } });
195 });
196});
197
198describe("resolveThreadPullRequestChains", () => {
199 it("chains links by base → head within a repository, bottom to top", () => {
200 const chains = resolveThreadPullRequestChains([
201 link(3, { snapshot: snapshot({ headBranch: "c", baseBranch: "b" }) }),
202 link(1, { snapshot: snapshot({ headBranch: "a", baseBranch: "main" }) }),
203 link(2, { snapshot: snapshot({ headBranch: "b", baseBranch: "a" }) }),
204 link(9, { snapshot: snapshot({ headBranch: "solo", baseBranch: "main" }) }),
205 ]);
206 expect(chains.map((chain) => [chain.kind, chain.layers.map((layer) => layer.number)])).toEqual([
207 ["derived", [1, 2, 3]],
208 ["derived", [9]],
209 ]);
210 });
211
212 it("keeps every link built on the same parent under it", () => {
213 const links = [
214 link(3, { snapshot: snapshot({ headBranch: "c", baseBranch: "a" }) }),
215 link(5, { snapshot: snapshot({ headBranch: "p", baseBranch: "main" }) }),
216 link(6, { snapshot: snapshot({ headBranch: "q", baseBranch: "p" }) }),
217 link(1, { snapshot: snapshot({ headBranch: "a", baseBranch: "p" }) }),
218 link(2, { snapshot: snapshot({ headBranch: "b", baseBranch: "a" }) }),
219 link(9, { snapshot: snapshot({ headBranch: "solo", baseBranch: "main" }) }),
220 ];
221 const chains = resolveThreadPullRequestChains(links);
222 expect(
223 chains.map((chain) => [chain.layers.map((layer) => layer.number), chain.depths]),
224 ).toEqual([
225 [
226 [5, 6, 1, 3, 2],
227 [0, 1, 1, 2, 2],
228 ],
229 [[9], [0]],
230 ]);
231 expect(resolveThreadPullRequestBadge(links.slice(0, 5))).toEqual({
232 kind: "stack",
233 layers: 5,
234 state: "open",
235 });
236 });
237
238 it("points at the highest layer of a branched stack, not the last sibling listed", () => {
239 const branched = (state: ThreadPullRequestSnapshot["state"]) => [
240 link(1, { snapshot: snapshot({ state, headBranch: "a" }) }),
241 link(2, { snapshot: snapshot({ state, headBranch: "b", baseBranch: "a" }) }),
242 link(3, { snapshot: snapshot({ state, headBranch: "c", baseBranch: "b" }) }),
243 link(4, { snapshot: snapshot({ state, headBranch: "d", baseBranch: "a" }) }),
244 ];
245 const open = resolveThreadCurrentPullRequest(branched("open"));
246 expect(open?.kind === "stack" ? open.open.map((entry) => entry.number) : null).toEqual([
247 3, 4, 2, 1,
248 ]);
249 expect(resolveThreadCurrentPullRequest(branched("merged"))).toMatchObject({
250 kind: "single",
251 link: { number: 3 },
252 });
253 });
254
255 it("uses a later complete native snapshot for layer order and the current pull request", () => {
256 const links = [18, 20, 83, 84].map((number) =>
257 link(number, {
258 linkedAt: "2026-01-01T00:00:00.000Z",
259 snapshot: snapshot(),
260 stack: {
261 kind: "native",
262 id: "80",
263 number: 80,
264 url: "https://github.com/pingdotgg/t3code/stacks/80",
265 base: "main",
266 layers: (number < 83
267 ? [79, 37, 38, 39, 76, 18, 20]
268 : [79, 37, 38, 39, 76, 18, 20, 83, 84]
269 ).map((number) => ({ number, headBranch: `pr-${number}`, state: "open" })),
270 },
271 }),
272 );
273 expect
274 .soft(
275 resolveThreadPullRequestChains(links).map((chain) =>
276 chain.layers.map((layer) => layer.number),
277 ),
278 )
279 .toEqual([[18, 20, 83, 84]]);
280 expect(resolveThreadCurrentPullRequest(links)).toMatchObject({
281 kind: "stack",
282 top: { number: 84 },
283 open: [{ number: 84 }, { number: 83 }, { number: 20 }, { number: 18 }],
284 });
285 });
286
287 it("uses the earliest longest partial snapshot and appends missing members in stored order", () => {
288 const links = [
289 [3, 2],
290 [9, 2, 3],
291 [9, 3, 2],
292 [9, 3, 2],
293 ].map((numbers, index) =>
294 link(index + 1, {
295 stack: {
296 kind: "native",
297 id: "s1",
298 number: 1,
299 url: "https://github.com/pingdotgg/t3code/stacks/1",
300 base: "main",
301 layers: numbers.map((number) => ({ number, headBranch: `pr-${number}`, state: "open" })),
302 },
303 }),
304 );
305 expect(
306 resolveThreadPullRequestChains(links).map((chain) =>
307 chain.layers.map((layer) => layer.number),
308 ),
309 ).toEqual([[2, 3, 1, 4]]);
310 });
311
312 it("uses the native stack order when the host provides one", () => {
313 const stack = {
314 kind: "native" as const,
315 id: "s1",
316 number: 1,
317 url: "https://github.com/pingdotgg/t3code/stacks/1",
318 base: "main",
319 layers: [
320 { number: 5, headBranch: "a", state: "merged" as const },
321 { number: 6, headBranch: "b", state: "open" as const },
322 ],
323 };
324 const chains = resolveThreadPullRequestChains([
325 link(6, { snapshot: snapshot({ headBranch: "b", baseBranch: "main" }), stack }),
326 link(5, {
327 snapshot: snapshot({ state: "merged", headBranch: "a", baseBranch: "main" }),
328 stack,
329 }),
330 link(8),
331 ]);
332 expect(chains.map((chain) => [chain.kind, chain.layers.map((layer) => layer.number)])).toEqual([
333 ["native", [5, 6]],
334 ["derived", [8]],
335 ]);
336 });
337});
338
339describe("chain selection and badge state", () => {
340 it.each(["open", "merged", "closed"] as const)(
341 "targets the top of a derived %s chain despite a later bottom update and link",
342 (state) => {
343 const bottom = link(2, {
344 snapshot: snapshot({ state, headBranch: "base", updatedAt: "2026-02-01T00:00:00.000Z" }),
345 });
346 const top = link(1, {
347 snapshot: snapshot({ state, headBranch: "top", baseBranch: "base" }),
348 });
349 expect(resolveThreadCurrentPullRequest([bottom, top])).toMatchObject(
350 state === "open"
351 ? { kind: "stack", top: { number: 1 }, open: [top, bottom] }
352 : { kind: "single", link: { number: 1 } },
353 );
354 expect(resolveThreadPullRequestBadge([bottom, top])).toEqual({
355 kind: "stack",
356 layers: 2,
357 state,
358 });
359 },
360 );
361
362 it("keeps the top native layer after completion and treats an unsynced layer as open", () => {
363 const stack = {
364 kind: "native" as const,
365 id: "native-1",
366 number: 1,
367 url: "https://github.com/pingdotgg/t3code/stacks/1",
368 base: "main",
369 layers: [
370 { number: 2, headBranch: "base", state: "merged" as const },
371 { number: 1, headBranch: "top", state: "merged" as const },
372 ],
373 };
374 const bottom = link(2, {
375 stack,
376 snapshot: snapshot({ state: "merged", updatedAt: "2026-02-01T00:00:00.000Z" }),
377 });
378 const top = link(1, { stack, snapshot: snapshot({ state: "merged" }) });
379 expect(resolveThreadCurrentPullRequest([bottom, top])).toMatchObject({
380 kind: "single",
381 link: { number: 1 },
382 });
383 expect(resolveThreadPullRequestBadge([bottom, { ...top, snapshot: null }])).toEqual({
384 kind: "stack",
385 layers: 2,
386 state: "open",
387 });
388 });
389
390 it("uses aggregate state and distinguishes unrelated work from a stack", () => {
391 const bottom = link(1, { snapshot: snapshot({ state: "merged", headBranch: "base" }) });
392 const top = link(2, { snapshot: snapshot({ state: "closed", baseBranch: "base" }) });
393 expect(resolveThreadPullRequestBadge([bottom, top])).toEqual({
394 kind: "stack",
395 layers: 2,
396 state: "closed",
397 });
398 expect(resolveThreadPullRequestBadge([bottom, top, link(3)])).toEqual({
399 kind: "pull-request",
400 others: 2,
401 state: "open",
402 });
403 expect(resolveThreadPullRequestBadge([link(3, { source: "stack-dismissed" })])).toBeNull();
404 });
405
406 it("keeps branch matching case-sensitive while ignoring repository case", () => {
407 const bottom = link(1, {
408 repository: "PingDotGG/T3code",
409 snapshot: snapshot({ headBranch: "Base" }),
410 });
411 const top = link(2, { snapshot: snapshot({ headBranch: "top", baseBranch: "base" }) });
412 expect(resolveThreadPullRequestChains([bottom, top])).toHaveLength(2);
413 expect(
414 resolveThreadPullRequestChains([
415 bottom,
416 { ...top, snapshot: snapshot({ headBranch: "top", baseBranch: "Base" }) },
417 ])[0]?.layers,
418 ).toEqual([bottom, { ...top, snapshot: snapshot({ headBranch: "top", baseBranch: "Base" }) }]);
419 });
420
421 it("preserves cyclic links without presenting a guessed stack order", () => {
422 const links = [
423 link(1, { snapshot: snapshot({ headBranch: "a", baseBranch: "b" }) }),
424 link(2, { snapshot: snapshot({ headBranch: "b", baseBranch: "a" }) }),
425 ];
426 expect(resolveThreadPullRequestChains(links).map((chain) => chain.layers)).toEqual(
427 links.map((entry) => [entry]),
428 );
429 expect(resolveThreadCurrentPullRequest(links)).toMatchObject({
430 kind: "stack",
431 top: { number: 2 },
432 });
433 expect(resolveThreadPullRequestBadge(links)).toEqual({
434 kind: "pull-request",
435 others: 1,
436 state: "open",
437 });
438 });
439
440 it("lists a pull request once when two links share its identity", () => {
441 const links = [
442 link(1, { snapshot: snapshot({ headBranch: "a" }) }),
443 link(1, { snapshot: snapshot({ headBranch: "b", baseBranch: "a" }) }),
444 link(1, { snapshot: snapshot({ headBranch: "c" }) }),
445 ];
446 expect(resolveThreadPullRequestChains(links).map((chain) => chain.layers)).toEqual([
447 [links[0]],
448 ]);
449 });
450
451 it("does not guess a parent when a head branch was reused", () => {
452 const links = [
453 link(1, { snapshot: snapshot({ state: "merged", headBranch: "reused" }) }),
454 link(2, { snapshot: snapshot({ headBranch: "reused" }) }),
455 link(3, { snapshot: snapshot({ headBranch: "top", baseBranch: "reused" }) }),
456 ];
457 expect(resolveThreadPullRequestChains(links).map((chain) => chain.layers)).toEqual(
458 links.map((entry) => [entry]),
459 );
460 });
461});
462
463describe("threadSearchPullRequests", () => {
464 const branchPullRequest = {
465 projectId: ProjectId.make("project"),
466 repository: "PingDotGG/T3Code",
467 number: 42,
468 url: "https://github.com/pingdotgg/t3code/pull/42",
469 };
470
471 it("drops a branch PR that duplicates a titled link", () => {
472 expect(
473 threadSearchPullRequests({
474 branchPullRequest,
475 pullRequests: [
476 link(42, {
477 source: "created",
478 snapshot: snapshot({ title: "Fix login crash" }),
479 }),
480 ],
481 }),
482 ).toEqual([
483 {
484 number: 42,
485 title: "Fix login crash",
486 references: ["pingdotgg/t3code#42", "https://github.com/pingdotgg/t3code/pull/42"],
487 },
488 ]);
489 });
490
491 it("keeps a branch PR whose repository and number match a link on another host", () => {
492 for (const source of ["manual", "stack-dismissed"] as const) {
493 expect(
494 threadSearchPullRequests({
495 branchPullRequest,
496 pullRequests: [
497 link(42, {
498 host: "gitlab.com",
499 source,
500 url: "https://gitlab.com/pingdotgg/t3code/-/merge_requests/42",
501 }),
502 ],
503 }).flatMap((entry) => entry.references),
504 ).toContain(branchPullRequest.url);
505 }
506 });
507
508 it("keeps a branch PR the links do not include", () => {
509 expect(
510 threadSearchPullRequests({
511 branchPullRequest,
512 pullRequests: [link(7, { snapshot: snapshot({ title: "Other change" }) })],
513 }).map((entry) => [entry.number, entry.title]),
514 ).toEqual([
515 [42, null],
516 [7, "Other change"],
517 ]);
518 });
519
520 it("drops a branch PR the user unlinked", () => {
521 expect(
522 threadSearchPullRequests({
523 branchPullRequest,
524 pullRequests: [link(42, { source: "stack-dismissed" }), link(7)],
525 }).map((entry) => entry.number),
526 ).toEqual([7]);
527 });
528
529 it("drops a branch PR the user unlinked through a comment or files-tab link", () => {
530 for (const url of [
531 "https://github.com/pingdotgg/t3code/pull/42#issuecomment-42",
532 "https://github.com/pingdotgg/t3code/pull/42/files#r123",
533 ]) {
534 expect(
535 threadSearchPullRequests({
536 branchPullRequest,
537 pullRequests: [link(42, { source: "stack-dismissed", url })],
538 }),
539 ).toEqual([]);
540 }
541 });
542
543 it.each(["#issuecomment-42", "/files#r123"])(
544 "keeps the branch PR search title and references when linked through %s",
545 (suffix) => {
546 const url = `${branchPullRequest.url}${suffix}`;
547 const pullRequests = threadSearchPullRequests({
548 branchPullRequest,
549 pullRequests: [link(42, { url, snapshot: snapshot({ title: "Fix auth" }) })],
550 });
551 const subject = { title: "Unrelated", activityAt: null, pullRequests };
552 expect(scoreThreadSearch(foldSearchQuery("#42"), subject, 0)?.explain?.()?.text).toBe(
553 "#42 Fix auth",
554 );
555 expect(pullRequests).toEqual([
556 {
557 number: 42,
558 title: "Fix auth",
559 references: ["pingdotgg/t3code#42", url, branchPullRequest.url],
560 },
561 ]);
562 expect(
563 scoreThreadSearch(
564 foldSearchQuery(`${branchPullRequest.url}/files`),
565 subject,
566 0,
567 )?.explain?.()?.field,
568 ).toBe("reference");
569 },
570 );
571});
572
573describe("threadPullRequestSearchTerms", () => {
574 it("includes completed and unsynced links but excludes dismissed links", () => {
575 const terms = threadPullRequestSearchTerms({
576 pullRequests: [
577 link(12, { snapshot: snapshot({ title: "Fix login", state: "merged" }) }),
578 link(34),
579 link(56, { source: "stack-dismissed" }),
580 ],
581 });
582 expect(terms).toContain("#12");
583 expect(terms).toContain("pingdotgg/t3code#12");
584 expect(terms).toContain("https://github.com/pingdotgg/t3code/pull/12");
585 expect(terms).toContain("Fix login");
586 expect(terms).toContain("#34");
587 expect(terms.join(" ")).not.toContain("56");
588 });
589});
590
591it("searches the legacy projection when old environments decode to an empty links list", () => {
592 const linkedPullRequest = {
593 projectId: ProjectId.make("project"),
594 repository: "pingdotgg/t3code",
595 number: 12,
596 url: "https://github.com/pingdotgg/t3code/pull/12",
597 };
598 expect(threadPullRequestSearchTerms({ pullRequests: [], linkedPullRequest })).toContain("#12");
599 expect(
600 threadPullRequestSearchTerms({ pullRequests: [link(34)], linkedPullRequest }),
601 ).not.toContain("#12");
602});
603
604describe("pullRequestListLines and derived caching", () => {
605 it("orders chains by latest layer update, preserves ties, and treats invalid timestamps as zero", () => {
606 const base = link(1, {
607 snapshot: snapshot({
608 headBranch: "a",
609 baseBranch: "main",
610 updatedAt: "2026-01-01T00:00:00.000Z",
611 }),
612 });
613 const top = link(2, {
614 snapshot: snapshot({
615 headBranch: "b",
616 baseBranch: "a",
617 updatedAt: "2026-03-01T00:00:00.000Z",
618 }),
619 });
620 const tiedFirst = link(3, {
621 snapshot: snapshot({ headBranch: "c", updatedAt: "2026-02-01T00:00:00.000Z" }),
622 });
623 const tiedSecond = link(4, {
624 snapshot: snapshot({ headBranch: "d", updatedAt: "2026-02-01T00:00:00.000Z" }),
625 });
626 const invalid = link(5, {
627 snapshot: snapshot({ headBranch: "e", updatedAt: "invalid" }),
628 });
629 const chains = resolveThreadPullRequestChains([invalid, tiedFirst, base, top, tiedSecond]);
630 const lines = pullRequestListLines(chains);
631
632 expect(lines.map((line) => [line.link.number, line.depth, line.stack])).toEqual([
633 [1, 0, { kind: "derived", size: 2 }],
634 [2, 1, null],
635 [3, 0, null],
636 [4, 0, null],
637 [5, 0, null],
638 ]);
639 });
640
641 it("reuses cached derived results for the same immutable links array", () => {
642 const links = [
643 link(1, { snapshot: snapshot({ headBranch: "a", baseBranch: "main" }) }),
644 link(2, { snapshot: snapshot({ headBranch: "b", baseBranch: "a" }) }),
645 link(3, { source: "stack-dismissed" }),
646 ];
647
648 const undismissed = links.slice(0, 2);
649 expect(visibleThreadPullRequests(undismissed)).toBe(undismissed);
650 const chains = resolveThreadPullRequestChains(links);
651 expect(resolveThreadPullRequestChains(links)).toBe(chains);
652 expect(pullRequestListLines(chains)).toBe(pullRequestListLines(chains));
653 expect(resolveThreadCurrentPullRequest(links)).toBe(resolveThreadCurrentPullRequest(links));
654 expect(resolveThreadPullRequestBadge(links)).toBe(resolveThreadPullRequestBadge(links));
655
656 const updated = [...links.slice(0, 2), link(4)];
657 expect(resolveThreadPullRequestChains(updated)).not.toBe(chains);
658 expect(resolveThreadPullRequestBadge(updated)).toEqual({
659 kind: "pull-request",
660 others: 2,
661 state: "open",
662 });
663 });
664});