@@ -36,6 +36,7 @@ function harness(
3636 readonly fallbackGh ?: boolean ;
3737 readonly sameToken ?: boolean ;
3838 readonly rateLimited ?: boolean ;
39+ readonly appCoverage ?: "covered" | "not-covered" | "unknown" ;
3940 readonly restAnswers ?: Readonly < Record < string , string > > ;
4041 } = { } ,
4142) {
@@ -64,36 +65,66 @@ function harness(
6465 { message : options . rateLimited ? "API rate limit exceeded" : "Bad credentials" } ,
6566 refusalStatus ,
6667 )
67- : pathname === "/user"
68- ? json ( { id : 123 , login : "Chinoman10" } )
69- : restAnswer !== undefined
70- ? new Response ( restAnswer )
71- : pathname . startsWith ( "/repos/" )
72- ? json ( {
73- full_name : pathname . slice ( "/repos/" . length ) ,
74- html_url : `https://github.com/${ pathname . slice ( 7 ) } ` ,
75- ssh_url :
`[email protected] :${ pathname . slice ( 7 ) } .git` , 76- } )
77- : successfulGraphql
78- ? json ( {
79- data : {
80- repository : { pullRequest : { id : "PR_1" } , pullRequests : { nodes : [ ] } } ,
81- addComment : { clientMutationId : null } ,
82- addReaction : { reaction : { content : "THUMBS_UP" } } ,
83- _0_markFileAsViewed : { clientMutationId : null } ,
84- _1_unmarkFileAsViewed : { clientMutationId : null } ,
85- _0_repository : { pullRequests : { nodes : [ ] } } ,
86- } ,
87- } )
88- : json ( { message : "Not Found" } , 404 ) ;
68+ : pathname === "/user/installations"
69+ ? json (
70+ {
71+ installations :
72+ options . appCoverage === "covered"
73+ ? [ { id : 1 , repository_selection : "all" , account : { login : "OwnerA" } } ]
74+ : [ ] ,
75+ } ,
76+ options . appCoverage === "unknown" ? 502 : 200 ,
77+ )
78+ : pathname === "/graphql" &&
79+ token === "Bearer fake-app" &&
80+ options . appCoverage !== "covered"
81+ ? json ( { data : { repository : null , _0_repository : null } } )
82+ : pathname === "/user"
83+ ? json ( { id : 123 , login : "Chinoman10" } )
84+ : restAnswer !== undefined
85+ ? new Response ( restAnswer )
86+ : pathname . startsWith ( "/repos/" )
87+ ? json ( {
88+ full_name : pathname . slice ( "/repos/" . length ) ,
89+ html_url : `https://github.com/${ pathname . slice ( 7 ) } ` ,
90+ ssh_url :
`[email protected] :${ pathname . slice ( 7 ) } .git` , 91+ } )
92+ : successfulGraphql
93+ ? json ( {
94+ data : {
95+ repository : {
96+ pullRequest : { id : "PR_1" } ,
97+ pullRequests : { nodes : [ ] } ,
98+ } ,
99+ addComment : { clientMutationId : null } ,
100+ addReaction : { reaction : { content : "THUMBS_UP" } } ,
101+ _0_markFileAsViewed : { clientMutationId : null } ,
102+ _1_unmarkFileAsViewed : { clientMutationId : null } ,
103+ _0_repository : { pullRequests : { nodes : [ ] } } ,
104+ } ,
105+ } )
106+ : json ( { message : "Not Found" } , 404 ) ;
89107 return Effect . succeed ( HttpClientResponse . fromWeb ( request , result ) ) ;
90108 } ) ,
91109 ) ,
92110 ) ;
93111 const host = TestSourceControlHost . layer ( {
94112 settings : applyServerSettingsPatch ( DEFAULT_SERVER_SETTINGS , {
95113 sourceControlHosts : {
96- github : { tokens : options . fallbackGh ? { } : { "github.com" : "host-default" } } ,
114+ github : {
115+ tokens : options . fallbackGh ? { } : { "github.com" : "host-default" } ,
116+ signIns :
117+ options . appCoverage === undefined
118+ ? { }
119+ : {
120+ "github.com" : JSON . stringify ( {
121+ accessToken : "fake-app" ,
122+ accessTokenExpiresAt : 28_800_000 ,
123+ refreshToken : "fake-refresh" ,
124+ refreshTokenExpiresAt : 28_800_000 ,
125+ } ) ,
126+ } ,
127+ } ,
97128 } ,
98129 } ) ,
99130 process : {
@@ -138,7 +169,12 @@ function harness(
138169 Layer . provideMerge ( api ) ,
139170 Layer . provideMerge ( NodeServices . layer ) ,
140171 Layer . provide (
141- Layer . succeed ( HostProcess . Environment , { T3CODE_GITHUB_USE_GIT_CREDENTIALS : "1" } ) ,
172+ Layer . succeed ( HostProcess . Environment , {
173+ T3CODE_GITHUB_USE_GIT_CREDENTIALS : "1" ,
174+ ...( options . appCoverage === undefined
175+ ? { }
176+ : { [ GitHubAppSignIn . CLIENT_ID_VARIABLE ] : "Iv-synthetic" } ) ,
177+ } ) ,
142178 ) ,
143179 Layer . provide ( Layer . succeed ( HostProcess . WorkingDirectory , "/trusted" ) ) ,
144180 ) ;
@@ -980,6 +1016,46 @@ describe("native GitHub repository routing", () => {
9801016 } ,
9811017 ) ;
9821018
1019+ it . effect . each ( [ "covered" , "not-covered" , "unknown" ] as const ) (
1020+ "selects a source GraphQL credential before pinning when app coverage is %s" ,
1021+ ( appCoverage ) => {
1022+ const { layer, requests, helperPaths } = harness ( 401 , true , {
1023+ missingOwners : [ "OwnerA" ] ,
1024+ fallbackGh : true ,
1025+ appCoverage,
1026+ } ) ;
1027+ return Effect . gen ( function * ( ) {
1028+ const provider = yield * GitHubSourceControlProvider . make ;
1029+ const pending = yield * provider
1030+ . listChangeRequests ( {
1031+ cwd : "/w" ,
1032+ state : "open" ,
1033+ headSelector : "feature" ,
1034+ context : {
1035+ provider : {
1036+ kind : SourceControlProviderKind . make ( "github" ) ,
1037+ name : "GitHub" ,
1038+ baseUrl : "https://github.com" ,
1039+ } ,
1040+ remoteName : "origin" ,
1041+ remoteUrl : "https://github.com/OwnerA/Repo.git" ,
1042+ } ,
1043+ } )
1044+ . pipe ( Effect . forkChild ) ;
1045+ yield * TestClock . adjust ( "500 millis" ) ;
1046+ expect ( yield * Fiber . join ( pending ) ) . toEqual ( [ ] ) ;
1047+ const queries = requests . filter ( ( request ) => new URL ( request . url ) . pathname === "/graphql" ) ;
1048+ expect ( queries . map ( ( request ) => request . headers . authorization ) ) . toEqual ( [
1049+ appCoverage === "covered" ? "Bearer fake-app" : "Bearer fake-gh-1" ,
1050+ ] ) ;
1051+ expect ( helperPaths ) . toEqual ( [ "OwnerA/Repo.git" ] ) ;
1052+ } ) . pipe (
1053+ Effect . provide ( layer ) ,
1054+ Effect . provideService ( HostProcess . Environment , { T3CODE_GITHUB_USE_GIT_CREDENTIALS : "1" } ) ,
1055+ ) ;
1056+ } ,
1057+ ) ;
1058+
9831059 it . effect . each ( [ 401 , 403 , 404 ] ) ( "makes only one GraphQL attempt after HTTP %s" , ( status ) => {
9841060 const { layer, requests, refused } = harness ( status ) ;
9851061 refused . add ( "Bearer fake-OwnerA-1" ) ;
0 commit comments