11import { describe , expect , it } from "vite-plus/test" ;
22
3- import type { ThreadPullRequestLink } from "@t3tools/contracts" ;
3+ import type { ThreadPullRequestKey , ThreadPullRequestLink } from "@t3tools/contracts" ;
44
55import {
66 composerPullRequestsFromLinks ,
77 filterComposerPullRequestMatches ,
88 withLinkedComposerPullRequestsFirst ,
99} from "./composerPullRequestMatches.ts" ;
1010
11+ const keyOf = ( entry : ThreadPullRequestKey ) =>
12+ `${ entry . host . trim ( ) . toLowerCase ( ) } /${ entry . repository . trim ( ) . toLowerCase ( ) } #${ entry . number } ` ;
13+
1114const entry = ( number : number , updatedAt : string ) => ( {
1215 number,
16+ host : "github.com" ,
1317 projectId : "p1" ,
1418 repository : "owner/repo" ,
1519 updatedAt,
@@ -18,6 +22,7 @@ const entry = (number: number, updatedAt: string) => ({
1822describe ( "filterComposerPullRequestMatches" , ( ) => {
1923 it ( "ranks the exact number above newer substring matches" , ( ) => {
2024 const result = filterComposerPullRequestMatches ( {
25+ keyOf,
2126 entries : [ entry ( 1234 , "2026-01-03" ) , entry ( 123 , "2026-01-01" ) , entry ( 1230 , "2026-01-02" ) ] ,
2227 projectId : "p1" ,
2328 repository : "owner/repo" ,
@@ -29,6 +34,7 @@ describe("filterComposerPullRequestMatches", () => {
2934
3035 it ( "orders by update instant when timestamps carry different UTC offsets" , ( ) => {
3136 const result = filterComposerPullRequestMatches ( {
37+ keyOf,
3238 entries : [ entry ( 401 , "2026-10-25T02:50:00+02:00" ) , entry ( 499 , "2026-10-25T02:10:00+01:00" ) ] ,
3339 projectId : "p1" ,
3440 repository : "owner/repo" ,
@@ -66,6 +72,7 @@ describe("linked pull requests", () => {
6672
6773 it ( "offers a linked pull request from another repository above the project's own" , ( ) => {
6874 const result = filterComposerPullRequestMatches ( {
75+ keyOf,
6976 entries : [ entry ( 4 , "2026-01-03" ) , { ...entry ( 4 , "2026-01-04" ) , repository : "owner/other" } ] ,
7077 linked : composerPullRequestsFromLinks ( [ link ( "owner/repo-b" , 4 ) ] , "p1" ) ,
7178 projectId : "p1" ,
@@ -79,8 +86,27 @@ describe("linked pull requests", () => {
7986 ] ) ;
8087 } ) ;
8188
89+ it ( "keeps linked reviews with the same repository and number on different hosts" , ( ) => {
90+ const github = link ( "wireshark/wireshark" , 1 ) ;
91+ const gitlab = link ( "wireshark/wireshark" , 1 , {
92+ host : "gitlab.com" ,
93+ url : "https://gitlab.com/wireshark/wireshark/-/merge_requests/1" ,
94+ } ) ;
95+ const result = filterComposerPullRequestMatches ( {
96+ keyOf,
97+ entries : [ ] ,
98+ linked : composerPullRequestsFromLinks ( [ github , gitlab ] , "p1" ) ,
99+ projectId : "p1" ,
100+ repository : "wireshark/wireshark" ,
101+ query : "1" ,
102+ limit : 10 ,
103+ } ) ;
104+ expect ( result . map ( ( match ) => match . url ) ) . toEqual ( [ github . url , gitlab . url ] ) ;
105+ } ) ;
106+
82107 it ( "keeps one row for a linked pull request the project listing already has" , ( ) => {
83108 const result = filterComposerPullRequestMatches ( {
109+ keyOf,
84110 entries : [ entry ( 4 , "2026-01-03" ) ] ,
85111 linked : composerPullRequestsFromLinks ( [ link ( "Owner/Repo" , 4 ) ] , "p1" ) ,
86112 projectId : "p1" ,
@@ -98,22 +124,34 @@ describe("linked pull requests", () => {
98124 snapshot : { ...link ( "owner/repo" , 7 ) . snapshot ! , title : "Fix login" } ,
99125 } ) ,
100126 link ( "owner/repo" , 8 ) ,
127+ link ( "owner/repo" , 8 , {
128+ host : "gitlab.com" ,
129+ url : "https://gitlab.com/owner/repo/-/merge_requests/8" ,
130+ snapshot : { ...link ( "owner/repo" , 8 ) . snapshot ! , title : "Fix CI" } ,
131+ } ) ,
101132 ] ,
102133 "p1" ,
103134 ) ;
104135 const searching = withLinkedComposerPullRequestsFirst ( {
136+ keyOf,
105137 matches : [ ] ,
106138 linked,
107139 query : "fix" ,
108140 limit : 10 ,
109141 } ) ;
110- expect ( searching . map ( ( match ) => match . number ) ) . toEqual ( [ 7 ] ) ;
142+ expect ( searching . map ( ( match ) => match . number ) ) . toEqual ( [ 7 , 8 ] ) ;
111143 const searched = withLinkedComposerPullRequestsFirst ( {
144+ keyOf,
112145 matches : [ entry ( 9 , "2026-01-05" ) , entry ( 8 , "2026-01-03" ) ] ,
113146 linked,
114147 query : "fix" ,
115148 limit : 10 ,
116149 } ) ;
117- expect ( searched ) . toEqual ( [ linked [ 0 ] , entry ( 8 , "2026-01-03" ) , entry ( 9 , "2026-01-05" ) ] ) ;
150+ expect ( searched ) . toEqual ( [
151+ linked [ 0 ] ,
152+ entry ( 8 , "2026-01-03" ) ,
153+ linked [ 2 ] ,
154+ entry ( 9 , "2026-01-05" ) ,
155+ ] ) ;
118156 } ) ;
119157} ) ;
0 commit comments