@@ -36,6 +36,9 @@ import * as SourceControlProviderRegistry from "../sourceControl/SourceControlPr
3636import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit" ;
3737import * as ForgejoCli from "@t3tools/source-control-forgejo/server/ForgejoCli" ;
3838import * as ForgejoPullRequestProvider from "@t3tools/source-control-forgejo/server/ForgejoPullRequestProvider" ;
39+ import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi" ;
40+ import * as BitbucketPullRequestApi from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestApi" ;
41+ import * as BitbucketPullRequestProvider from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestProvider" ;
3942import * as GitHubRest from "@t3tools/source-control-github/server/GitHubRest" ;
4043import * as GitHubCredentials from "@t3tools/source-control-github/server/GitHubCredentials" ;
4144import * as GitHubPullRequestApi from "@t3tools/source-control-github/server/GitHubPullRequestApi" ;
@@ -921,6 +924,82 @@ it.effect("uses a provider's raw cursor advance when it consumed malformed rows"
921924 } ) ,
922925) ;
923926
927+ it . effect ( "continues Bitbucket listings through tied timestamps and terminates" , ( ) =>
928+ Effect . gen ( function * ( ) {
929+ const boundary = "2026-10-12T00:00:00.000Z" ;
930+ const older = "2026-10-11T00:00:00.000Z" ;
931+ const rows = [ 1 , 2 , 3 , 4 , 5 ] . map ( ( id ) => ( {
932+ id,
933+ title : `Pull request ${ id } ` ,
934+ state : "OPEN" ,
935+ created_on : older ,
936+ updated_on : id <= 3 ? boundary : older ,
937+ source : { branch : { name : `feat/${ id } ` } } ,
938+ destination : { branch : { name : "main" } } ,
939+ links : { html : { href : `https://bitbucket.org/acme/web/pull-requests/${ id } ` } } ,
940+ } ) ) ;
941+ const provider = yield * BitbucketPullRequestProvider . make . pipe (
942+ Effect . provide (
943+ BitbucketPullRequestApi . layer . pipe (
944+ Layer . provide (
945+ Layer . mock ( BitbucketApi . BitbucketApi ) ( {
946+ request : ( { url } ) => {
947+ if ( url === "/user" ) {
948+ return Effect . succeed ( {
949+ body : JSON . stringify ( { nickname : "bilal" } ) ,
950+ truncated : false ,
951+ } ) ;
952+ }
953+ const filter =
954+ new URL ( url , "https://api.bitbucket.org" ) . searchParams . get ( "q" ) ?? "" ;
955+ const updatedBefore = / u p d a t e d _ o n < = ( \S + ) / . exec ( filter ) ?. [ 1 ] ;
956+ const excluded = new Set (
957+ Array . from ( filter . matchAll ( / i d ! = ( \d + ) / g) , ( match ) => Number ( match [ 1 ] ) ) ,
958+ ) ;
959+ const values = rows . filter (
960+ ( row ) =>
961+ ( updatedBefore === undefined || row . updated_on <= updatedBefore ) &&
962+ ! excluded . has ( row . id ) ,
963+ ) ;
964+ return Effect . succeed ( { body : JSON . stringify ( { values } ) , truncated : false } ) ;
965+ } ,
966+ } ) ,
967+ ) ,
968+ ) ,
969+ ) ,
970+ ) ;
971+ const service = yield * makeService ( {
972+ projects : [
973+ project ( {
974+ id : "p1" ,
975+ title : "web" ,
976+ workspaceRoot : "/w" ,
977+ repository : "acme/web" ,
978+ provider : "bitbucket" ,
979+ host : "bitbucket.org" ,
980+ } ) ,
981+ ] ,
982+ providers : [ provider ] ,
983+ } ) ;
984+ let page = yield * service . list ( { state : "open" , limit : 2 } ) ;
985+ assert . deepStrictEqual (
986+ page . entries . map ( ( entry ) => entry . number ) ,
987+ [ 1 , 2 ] ,
988+ ) ;
989+ for ( const expected of [ [ 3 , 4 ] , [ 5 ] ] ) {
990+ assert . isTrue ( page . truncated ) ;
991+ assert . isNotEmpty ( page . nextCursors ) ;
992+ page = yield * service . list ( { state : "open" , limit : 2 , cursors : page . nextCursors } ) ;
993+ assert . deepStrictEqual (
994+ page . entries . map ( ( entry ) => entry . number ) ,
995+ expected ,
996+ ) ;
997+ }
998+ assert . isFalse ( page . truncated ) ;
999+ assert . deepStrictEqual ( page . nextCursors , { } ) ;
1000+ } ) ,
1001+ ) ;
1002+
9241003it . effect ( "reads only the repositories it was asked to carry on with" , ( ) =>
9251004 Effect . gen ( function * ( ) {
9261005 const listed : string [ ] = [ ] ;
@@ -947,7 +1026,9 @@ it.effect("reads only the repositories it was asked to carry on with", () =>
9471026 } ) ;
9481027
9491028 assert . deepStrictEqual ( listed , [ "acme/web" ] ) ;
950- assert . deepStrictEqual ( cursors , [ { updatedBefore : "2026-07-02T00:00:00Z" , delivered : 99 } ] ) ;
1029+ assert . deepStrictEqual ( cursors , [
1030+ { updatedBefore : "2026-07-02T00:00:00Z" , delivered : 99 , seenAt : [ 7 ] } ,
1031+ ] ) ;
9511032 assert . strictEqual ( result . providers . length , 1 ) ;
9521033 } ) ,
9531034) ;
@@ -4554,7 +4635,7 @@ it.effect("carries a slice on without sending the rows it already sent", () =>
45544635 [ 4 ] ,
45554636 ) ;
45564637 assert . deepStrictEqual ( result . nextCursors , {
4557- "github.com acme/web" : "2026-07-02T00:00:00Z|2|3,3, 4" ,
4638+ "github.com acme/web" : "2026-07-02T00:00:00Z|2|3,4" ,
45584639 } ) ;
45594640 } ) ,
45604641) ;
0 commit comments