@@ -4808,6 +4808,120 @@ for (const validHost of [undefined, "GITHUB.COM"] as const) {
48084808 ) ;
48094809}
48104810
4811+ for ( const variation of [ "same-checkout" , "different-checkout" , "different-remote" ] as const ) {
4812+ it . effect (
4813+ `coalesces scoped provider refinement only for the same checkout and remote (${ variation } )` ,
4814+ ( ) =>
4815+ Effect . gen ( function * ( ) {
4816+ const refinements : Array < { cwd : string ; remoteUrl : string | undefined } > = [ ] ;
4817+ const statsReads : string [ ] = [ ] ;
4818+ const unknownIdentity = project ( {
4819+ id : "child" ,
4820+ title : "app" ,
4821+ workspaceRoot : "/task/projects/app" ,
4822+ repository : "org/app" ,
4823+ provider : "unknown" ,
4824+ host : "code.example.test" ,
4825+ } ) . repositoryIdentity ! ;
4826+ const secondIdentity =
4827+ variation === "different-remote"
4828+ ? project ( {
4829+ id : "child" ,
4830+ title : "app" ,
4831+ workspaceRoot : "/task/projects/app" ,
4832+ repository : "org/app" ,
4833+ provider : "unknown" ,
4834+ host : "other.example.test" ,
4835+ } ) . repositoryIdentity !
4836+ : unknownIdentity ;
4837+ const service = yield * makeService ( {
4838+ projects : [ project ( { id : "p1" , title : "wrapper" , workspaceRoot : "/wrapper" } ) ] ,
4839+ threads : [
4840+ scopedThread ,
4841+ {
4842+ ...scopedThread ,
4843+ id : "t2" as ThreadId ,
4844+ worktreePath : variation === "different-checkout" ? "/other" : "/task" ,
4845+ } ,
4846+ { ...scopedThread , id : "invalid" as ThreadId , projectId : "p2" as ProjectId } ,
4847+ ] ,
4848+ repositories : ( cwd ) => [
4849+ {
4850+ path : "projects/app" ,
4851+ name : "app" ,
4852+ cwd : `${ cwd } /projects/app` ,
4853+ kind : "repository" ,
4854+ available : true ,
4855+ repositoryIdentity : unknownIdentity ,
4856+ } ,
4857+ {
4858+ path : "projects/alias" ,
4859+ name : "alias" ,
4860+ cwd : `${ cwd } /projects/app` ,
4861+ kind : "repository" ,
4862+ available : true ,
4863+ repositoryIdentity : secondIdentity ,
4864+ } ,
4865+ ] ,
4866+ resolveHandle : ( { cwd, context } ) =>
4867+ Effect . gen ( function * ( ) {
4868+ refinements . push ( { cwd, remoteUrl : context ?. remoteUrl } ) ;
4869+ yield * Effect . yieldNow ;
4870+ return {
4871+ context : {
4872+ ...context ! ,
4873+ provider : { ...context ! . provider , kind : "gitlab" as const } ,
4874+ } ,
4875+ provider : undefined as never ,
4876+ } ;
4877+ } ) ,
4878+ providers : [
4879+ fakeProvider ( "gitlab" , {
4880+ listChangeRequestStats : ( { cwd, host, changeRequests } ) => {
4881+ statsReads . push ( `${ cwd } ${ host } ` ) ;
4882+ return Effect . succeed (
4883+ [ ...new Set ( changeRequests . map ( ( ref ) => ref . number ) ) ] . map ( ( number ) => ( {
4884+ repository : "org/app" ,
4885+ number,
4886+ additions : 10 ,
4887+ deletions : 0 ,
4888+ } ) ) ,
4889+ ) ;
4890+ } ,
4891+ } ) ,
4892+ ] ,
4893+ } ) ;
4894+ const refs = [
4895+ scopedRef ,
4896+ {
4897+ ...scopedRef ,
4898+ workspace : { threadId : "t2" as ThreadId , repositoryPath : "projects/alias" } ,
4899+ } ,
4900+ { ...scopedRef , workspace : { ...scopedRef . workspace , threadId : "invalid" as ThreadId } } ,
4901+ { ...scopedRef , repository : "org/not-authorized" } ,
4902+ ] ;
4903+ const result = yield * service . listStats ( { refs } ) ;
4904+ assert . deepStrictEqual ( result . stats . map ( ( stat ) => stat . workspace ?. threadId ) . sort ( ) , [
4905+ "t1" ,
4906+ "t2" ,
4907+ ] ) ;
4908+ assert . strictEqual ( refinements . length , variation === "same-checkout" ? 1 : 2 ) ;
4909+ assert . strictEqual ( statsReads . length , variation === "same-checkout" ? 1 : 2 ) ;
4910+ if ( variation === "different-checkout" )
4911+ assert . deepStrictEqual ( refinements . map ( ( entry ) => entry . cwd ) . sort ( ) , [
4912+ "/other/projects/app" ,
4913+ "/task/projects/app" ,
4914+ ] ) ;
4915+ if ( variation === "different-remote" )
4916+ assert . deepStrictEqual ( refinements . map ( ( entry ) => entry . remoteUrl ) . sort ( ) , [
4917+ "https://code.example.test/org/app.git" ,
4918+ "https://other.example.test/org/app.git" ,
4919+ ] ) ;
4920+ assert . deepStrictEqual ( yield * service . listStats ( { refs : refs . slice ( 2 ) } ) , { stats : [ ] } ) ;
4921+ } ) ,
4922+ ) ;
4923+ }
4924+
48114925it . effect ( "publishes child repository merges with their workspace scope" , ( ) =>
48124926 Effect . scoped (
48134927 Effect . gen ( function * ( ) {
0 commit comments