@@ -121,3 +121,106 @@ it.effect("filters listed pull requests by the requested state", () =>
121121 assert . deepStrictEqual ( yield * numbers ( "open" ) , [ ] ) ;
122122 } ) ,
123123) ;
124+
125+ const fastForwardOnly = {
126+ cwd : "/forgejo" ,
127+ repository : "maria/project" ,
128+ host : "forge.example:3000" ,
129+ number : 3 ,
130+ } ;
131+ const fastForwardOnlySettings = {
132+ allow_merge_commits : false ,
133+ allow_squash_merge : false ,
134+ allow_rebase : false ,
135+ allow_rebase_explicit : false ,
136+ allow_fast_forward_only_merge : true ,
137+ default_merge_style : "fast-forward-only" ,
138+ } ;
139+ const fastForwardOnlyProvider = (
140+ writes : Array < { path : string ; body : unknown } > ,
141+ mergeSettings : object = fastForwardOnlySettings ,
142+ ) =>
143+ ForgejoPullRequestProvider . make . pipe (
144+ Effect . provide (
145+ Layer . mock ( ForgejoCli . ForgejoCli ) ( {
146+ api : ( input ) => {
147+ const [ path ] = input . path . split ( "?" ) ;
148+ const reply = ( value : unknown ) =>
149+ Effect . succeed ( TestSourceControlHost . processOutput ( JSON . stringify ( value ) ) ) ;
150+ if ( input . method === "POST" ) {
151+ writes . push ( { path : input . path , body : input . body } ) ;
152+ return reply ( "" ) ;
153+ }
154+ switch ( path ) {
155+ case "user" :
156+ return reply ( { login : "maria" } ) ;
157+ case "repos/maria/project" :
158+ return reply ( {
159+ full_name : "maria/project" ,
160+ permissions : { push : true , admin : true } ,
161+ ...mergeSettings ,
162+ } ) ;
163+ case "repos/maria/project/pulls/3" :
164+ return reply ( {
165+ number : 3 ,
166+ title : "Fast-forward me" ,
167+ body : "" ,
168+ html_url : "https://forge.example:3000/maria/project/pulls/3" ,
169+ user : { login : "maria" } ,
170+ state : "open" ,
171+ merged : false ,
172+ mergeable : true ,
173+ head : { ref : "feature" , sha : "head-sha" , repo : null } ,
174+ base : { ref : "main" , sha : "base-sha" , repo : null } ,
175+ merge_base : "base-sha" ,
176+ created_at : "2026-10-12T00:00:00Z" ,
177+ updated_at : "2026-10-12T00:00:00Z" ,
178+ closed_at : null ,
179+ merged_at : null ,
180+ labels : [ ] ,
181+ } ) ;
182+ case "repos/maria/project/branches/main" :
183+ return reply ( { } ) ;
184+ default :
185+ return reply ( [ ] ) ;
186+ }
187+ } ,
188+ } ) ,
189+ ) ,
190+ ) ;
191+
192+ it . effect ( "offers a fast-forward merge on a repository that only allows fast-forward" , ( ) =>
193+ Effect . gen ( function * ( ) {
194+ const provider = yield * fastForwardOnlyProvider ( [ ] ) ;
195+ const detail = yield * provider . getChangeRequest ( fastForwardOnly ) ;
196+ const allowed = provider . capabilities . mergeMethods . filter (
197+ ( method ) => detail . mergeCapabilities [ method ] ,
198+ ) ;
199+ assert . deepStrictEqual ( allowed , [ "fast-forward" ] ) ;
200+ } ) ,
201+ ) ;
202+
203+ it . effect ( "does not offer fast-forward when Forgejo omits the setting" , ( ) =>
204+ Effect . gen ( function * ( ) {
205+ const provider = yield * fastForwardOnlyProvider ( [ ] , { } ) ;
206+ const detail = yield * provider . getChangeRequest ( fastForwardOnly ) ;
207+ const allowed = provider . capabilities . mergeMethods . filter (
208+ ( method ) => detail . mergeCapabilities [ method ] ,
209+ ) ;
210+ assert . deepStrictEqual ( allowed , [ "merge" , "squash" , "rebase" ] ) ;
211+ } ) ,
212+ ) ;
213+
214+ it . effect ( "merges with Forgejo's fast-forward-only style" , ( ) =>
215+ Effect . gen ( function * ( ) {
216+ const writes : Array < { path : string ; body : unknown } > = [ ] ;
217+ const provider = yield * fastForwardOnlyProvider ( writes ) ;
218+ yield * provider . runAction ( { ...fastForwardOnly , action : "merge" , mergeMethod : "fast-forward" } ) ;
219+ assert . deepStrictEqual ( writes , [
220+ {
221+ path : "repos/maria/project/pulls/3/merge" ,
222+ body : { Do : "fast-forward-only" , delete_branch_after_merge : false } ,
223+ } ,
224+ ] ) ;
225+ } ) ,
226+ ) ;
0 commit comments