@@ -137,7 +137,8 @@ it.effect("reads Forgejo checks without repository or viewer requests", () => {
137137 } ) ;
138138 assert . strictEqual ( result . state , "open" ) ;
139139 assert . strictEqual ( result . checks [ 0 ] ?. status , "failure" ) ;
140- assert . deepStrictEqual ( paths , [
140+ assert . deepStrictEqual ( paths . toSorted ( ) , [
141+ "repos/acme/web/branches/main" ,
141142 "repos/acme/web/pulls/1" ,
142143 "repos/acme/web/statuses/head?sort=recentupdate&limit=50&page=1" ,
143144 "repos/acme/web/statuses/head?sort=recentupdate&limit=50&page=2" ,
@@ -147,16 +148,18 @@ it.effect("reads Forgejo checks without repository or viewer requests", () => {
147148 Layer . mock ( ForgejoCli . ForgejoCli ) ( {
148149 api : ( input ) => {
149150 paths . push ( input . path ) ;
150- assert . match ( input . path , / ^ r e p o s \/ a c m e \/ w e b \/ ( p u l l s \/ 1 | s t a t u s e s \/ h e a d ) / ) ;
151+ assert . match ( input . path , / ^ r e p o s \/ a c m e \/ w e b \/ ( p u l l s \/ 1 | s t a t u s e s \/ h e a d | b r a n c h e s \/ m a i n ) / ) ;
151152 return Effect . succeed (
152153 processOutput (
153- input . path . endsWith ( "pulls/1" )
154- ? `{"number":1,"title":"Checks","body":"","html_url":"https://forgejo.test/acme/web/pulls/1", "user":null,"state":"open","merged":false,
154+ input . path . endsWith ( "branches/main" )
155+ ? `{"name":"main","protected":false,"enable_status_check":false,"status_check_contexts":[]}`
156+ : input . path . endsWith ( "pulls/1" )
157+ ? `{"number":1,"title":"Checks","body":"","html_url":"https://forgejo.test/acme/web/pulls/1", "user":null,"state":"open","merged":false,
155158 "head":{"ref":"feature","sha":"head","repo":null},"base":{"ref":"main","sha":"base","repo":null},
156159 "created_at":"2026-09-16T00:00:00Z","updated_at":"2026-09-16T00:00:00Z","closed_at":null,"merged_at":null,"labels":[]}`
157- : input . path . endsWith ( "page=1" )
158- ? `[{"context":"build","status":"failure","description":null,"target_url":null,"updated_at":"2026-09-16T00:00:00Z"}]`
159- : "[]" ,
160+ : input . path . endsWith ( "page=1" )
161+ ? `[{"context":"build","status":"failure","description":null,"target_url":null,"updated_at":"2026-09-16T00:00:00Z"}]`
162+ : "[]" ,
160163 ) ,
161164 ) ;
162165 } ,
@@ -165,6 +168,105 @@ it.effect("reads Forgejo checks without repository or viewer requests", () => {
165168 ) ;
166169} ) ;
167170
171+ const requiredChecksPullRequest = {
172+ number : 7 ,
173+ title : "Required checks" ,
174+ body : "" ,
175+ html_url : "https://forgejo.test/acme/web/pulls/7" ,
176+ user : { login : "maria" } ,
177+ state : "open" ,
178+ merged : false ,
179+ head : { ref : "feature" , sha : "head" , repo : null } ,
180+ base : { ref : "release/1.x" , sha : "base" , repo : null } ,
181+ created_at : "2026-10-12T00:00:00Z" ,
182+ updated_at : "2026-10-12T00:00:00Z" ,
183+ closed_at : null ,
184+ merged_at : null ,
185+ labels : [ ] ,
186+ } ;
187+ const requiredChecksStatuses = [
188+ [ "ci/required-build" , "success" ] ,
189+ [ "ci/required-test" , "success" ] ,
190+ [ "ci/optional-lint" , "failure" ] ,
191+ ] . map ( ( [ context , status ] ) => ( {
192+ context,
193+ status,
194+ description : null ,
195+ target_url : null ,
196+ updated_at : "2026-10-12T00:00:00Z" ,
197+ } ) ) ;
198+
199+ it . effect . each ( [
200+ [
201+ "marks the statuses a readable base branch requires" ,
202+ Effect . succeed ( {
203+ name : "release/1.x" ,
204+ protected : true ,
205+ enable_status_check : true ,
206+ status_check_contexts : [ "ci/required-*" ] ,
207+ } ) ,
208+ [ true , true , undefined ] ,
209+ ] ,
210+ [
211+ "keeps every Forgejo status gating when the base branch cannot be read" ,
212+ Effect . fail (
213+ new ForgejoCli . ForgejoCliError ( {
214+ command : "fj" ,
215+ cwd : "/repo" ,
216+ reason : "forbidden" ,
217+ detail : "Forgejo API request failed with HTTP 403." ,
218+ } ) ,
219+ ) ,
220+ [ undefined , undefined , undefined ] ,
221+ ] ,
222+ ] as const ) ( "%s" , ( [ , branch , required ] ) =>
223+ Effect . gen ( function * ( ) {
224+ const provider = yield * ForgejoPullRequestProvider . make ;
225+ const readChecks = provider . getChangeRequestChecks ;
226+ if ( readChecks === undefined ) return yield * Effect . die ( "checks read missing" ) ;
227+ const input = { cwd : "/repo" , repository : "acme/web" , host : "forgejo.test" , number : 7 } ;
228+ const summary = yield * readChecks ( input ) ;
229+ const detail = yield * provider . getChangeRequest ( input ) ;
230+ for ( const checks of [ summary . checks , detail . checks ] ) {
231+ assert . deepStrictEqual (
232+ checks . map ( ( check ) => [ check . name , check . status , check . required ] ) ,
233+ [
234+ [ "ci/required-build" , "success" , required [ 0 ] ] ,
235+ [ "ci/required-test" , "success" , required [ 1 ] ] ,
236+ [ "ci/optional-lint" , "failure" , required [ 2 ] ] ,
237+ ] ,
238+ ) ;
239+ }
240+ } ) . pipe (
241+ Effect . provide (
242+ Layer . mock ( ForgejoCli . ForgejoCli ) ( {
243+ api : ( input ) => {
244+ const [ path , query ] = input . path . split ( "?" ) ;
245+ const respond = ( response : unknown ) =>
246+ encodeJsonEffect ( response ) . pipe ( Effect . orDie , Effect . map ( processOutput ) ) ;
247+ switch ( path ) {
248+ case "repos/acme/web/pulls/7" :
249+ return respond ( requiredChecksPullRequest ) ;
250+ case "repos/acme/web/statuses/head" :
251+ return respond (
252+ new URLSearchParams ( query ) . get ( "page" ) === "1" ? requiredChecksStatuses : [ ] ,
253+ ) ;
254+ // Branch names keep their slashes; each segment is encoded on its own.
255+ case "repos/acme/web/branches/release/1.x" :
256+ return Effect . flatMap ( branch , respond ) ;
257+ case "repos/acme/web" :
258+ return respond ( { full_name : "acme/web" , permissions : { push : true , admin : false } } ) ;
259+ case "user" :
260+ return respond ( { login : "maria" } ) ;
261+ default :
262+ return Effect . die ( `Unexpected Forgejo request: ${ input . path } ` ) ;
263+ }
264+ } ,
265+ } ) ,
266+ ) ,
267+ ) ,
268+ ) ;
269+
168270it . effect . each ( [
169271 [ "Ready" , false , true , false , "mergeable" ] ,
170272 [ "Draft" , true , false , true , "unknown" ] ,
@@ -236,6 +338,9 @@ it.effect.each([
236338 case "repos/maria/project/statuses/head" :
237339 response = [ ] ;
238340 break ;
341+ case "repos/maria/project/branches/main" :
342+ response = { name : "main" , protected : false } ;
343+ break ;
239344 default :
240345 return Effect . die ( `Unexpected Forgejo request: ${ input . path } ` ) ;
241346 }
0 commit comments