@@ -905,6 +905,173 @@ it.effect("tells two hosts of one kind apart in the switcher and the filter", ()
905905 } ) ,
906906) ;
907907
908+ it . effect ( "retains an unavailable host's summary when it is the only queried host" , ( ) =>
909+ Effect . gen ( function * ( ) {
910+ for ( const reason of [ "missing-tool" , "unauthenticated" ] as const ) {
911+ const service = yield * makeService ( {
912+ projects : [
913+ project ( {
914+ id : "p1" ,
915+ title : "t3code" ,
916+ workspaceRoot : "/a" ,
917+ repository : "pingdotgg/t3code" ,
918+ } ) ,
919+ ] ,
920+ providers : [
921+ fakePullRequestProvider ( SourceControlProviderKind . make ( "github" ) , {
922+ getViewer : ( ) =>
923+ Effect . fail ( unusable ( SourceControlProviderKind . make ( "github" ) , reason ) ) ,
924+ } ) ,
925+ ] ,
926+ } ) ;
927+
928+ for ( const filter of [ { } , { host : "github.com" } ] ) {
929+ const error = yield * service . list ( { state : "open" , ...filter } ) . pipe ( Effect . flip ) ;
930+ assert . strictEqual ( error . _tag , "PullRequestUnavailableError" ) ;
931+ assert . strictEqual (
932+ error . _tag === "PullRequestUnavailableError" ? error . reason : null ,
933+ reason === "missing-tool" ? "cli-missing" : "cli-unauthenticated" ,
934+ ) ;
935+ assert . isDefined ( error . listResult ) ;
936+ const result = error . listResult ! ;
937+ assert . deepStrictEqual ( result . entries , [ ] ) ;
938+ assert . deepStrictEqual ( result . viewers , { } ) ;
939+ assert . deepStrictEqual (
940+ result . providers . map ( ( { host, configured, projectIds } ) => ( {
941+ host,
942+ configured,
943+ projectIds : projectIds ?. map ( String ) ,
944+ } ) ) ,
945+ [ { host : "github.com" , configured : false , projectIds : undefined } ] ,
946+ ) ;
947+ assert . strictEqual ( result . providers [ 0 ] ?. detail ?. includes ( "github" ) , true ) ;
948+ assert . deepStrictEqual (
949+ result . errors . map ( ( { projectId } ) => projectId ) ,
950+ [ "p1" ] ,
951+ ) ;
952+ }
953+ }
954+ } ) ,
955+ ) ;
956+
957+ it . effect ( "retains a Bitbucket host summary when the provider rejects saved credentials" , ( ) =>
958+ Effect . gen ( function * ( ) {
959+ const provider = fakePullRequestProvider ( SourceControlProviderKind . make ( "bitbucket" ) , {
960+ getViewer : ( ) =>
961+ Effect . fail (
962+ new PullRequestProviderError ( {
963+ provider : SourceControlProviderKind . make ( "bitbucket" ) ,
964+ operation : "getViewer" ,
965+ reason : "failed" ,
966+ detail : "HTTP 403" ,
967+ } ) ,
968+ ) ,
969+ } ) ;
970+ const service = yield * makeService ( {
971+ projects : [
972+ project ( {
973+ id : "bitbucket" ,
974+ title : "Widget" ,
975+ workspaceRoot : "/widget" ,
976+ repository : "acme/widget" ,
977+ provider : "bitbucket" ,
978+ host : "bitbucket.org" ,
979+ } ) ,
980+ ] ,
981+ providers : [ provider ] ,
982+ } ) ;
983+ for ( const filter of [ { } , { host : "bitbucket.org" } ] ) {
984+ const error = yield * service . list ( { state : "open" , ...filter } ) . pipe ( Effect . flip ) ;
985+ assert . strictEqual ( error . _tag , "PullRequestOperationError" ) ;
986+ assert . isDefined ( error . listResult ) ;
987+ const result = error . listResult ! ;
988+ assert . deepStrictEqual (
989+ result . providers . map ( ( { host, configured, projectIds } ) => ( {
990+ host,
991+ configured,
992+ projectIds : projectIds ?. map ( String ) ,
993+ } ) ) ,
994+ [ { host : "bitbucket.org" , configured : false , projectIds : undefined } ] ,
995+ ) ;
996+ assert . deepStrictEqual ( result . entries , [ ] ) ;
997+ assert . deepStrictEqual (
998+ result . errors . map ( ( { projectId } ) => projectId ) ,
999+ [ "bitbucket" ] ,
1000+ ) ;
1001+ }
1002+ } ) ,
1003+ ) ;
1004+
1005+ it . effect . each ( [
1006+ {
1007+ provider : "forgejo" ,
1008+ host : "ssh.forge.example" ,
1009+ remoteUrl :
"ssh://[email protected] :2222/team/repo.git" , 1010+ } ,
1011+ {
1012+ provider : "unknown" ,
1013+ host : "forge.example" ,
1014+ remoteUrl : "http://forge.example:3000/team/repo.git" ,
1015+ } ,
1016+ ] ) (
1017+ "identifies every worktree behind an unavailable refined Forgejo authority" ,
1018+ ( { provider, host, remoteUrl } ) =>
1019+ Effect . gen ( function * ( ) {
1020+ const service = yield * makeService ( {
1021+ projects : [ "ssh" , "ssh-worktree" ] . map ( ( id ) =>
1022+ project ( {
1023+ id,
1024+ title : id ,
1025+ workspaceRoot : `/${ id } ` ,
1026+ repository : "team/repo" ,
1027+ provider,
1028+ host,
1029+ remoteUrl,
1030+ } ) ,
1031+ ) ,
1032+ providers : [
1033+ fakePullRequestProvider ( SourceControlProviderKind . make ( "forgejo" ) , {
1034+ getViewer : ( { host } ) => {
1035+ assert . strictEqual ( host , "forge.example:3000" ) ;
1036+ return Effect . fail (
1037+ unusable ( SourceControlProviderKind . make ( "forgejo" ) , "unauthenticated" ) ,
1038+ ) ;
1039+ } ,
1040+ listChangeRequests : ( ) => Effect . die ( "An unauthenticated host must not be queried" ) ,
1041+ } ) ,
1042+ ] ,
1043+ resolveHandle : ( { context } ) =>
1044+ Effect . succeed ( {
1045+ context : {
1046+ ...context ! ,
1047+ provider : {
1048+ kind : SourceControlProviderKind . make ( "forgejo" ) ,
1049+ name : "Forgejo" ,
1050+ baseUrl : "http://forge.example:3000" ,
1051+ } ,
1052+ } ,
1053+ provider : undefined as never ,
1054+ } ) ,
1055+ } ) ;
1056+ const error = yield * service . list ( { state : "open" } ) . pipe ( Effect . flip ) ;
1057+ assert . isDefined ( error . listResult ) ;
1058+ const result = error . listResult ! ;
1059+ assert . deepStrictEqual (
1060+ result . providers . map ( ( { host, configured, projectIds } ) => ( {
1061+ host,
1062+ configured,
1063+ projectIds : projectIds ?. map ( String ) ,
1064+ } ) ) ,
1065+ [ { host : "forge.example:3000" , configured : false , projectIds : [ "ssh" , "ssh-worktree" ] } ] ,
1066+ ) ;
1067+ assert . deepStrictEqual ( result . entries , [ ] ) ;
1068+ assert . deepStrictEqual (
1069+ result . errors . map ( ( { projectId } ) => projectId ) ,
1070+ [ "ssh" ] ,
1071+ ) ;
1072+ } ) ,
1073+ ) ;
1074+
9081075it . effect ( "reads a repository once when several worktrees share it" , ( ) =>
9091076 Effect . gen ( function * ( ) {
9101077 let calls = 0 ;
@@ -936,6 +1103,7 @@ it.effect("reads a repository once when several worktrees share it", () =>
9361103
9371104 assert . strictEqual ( calls , 1 ) ;
9381105 assert . strictEqual ( result . entries . length , 1 ) ;
1106+ assert . isUndefined ( result . providers [ 0 ] ?. projectIds ) ;
9391107 } ) ,
9401108) ;
9411109
0 commit comments