@@ -37,6 +37,7 @@ it.effect("refreshes Forgejo viewer permissions immediately after credentials ch
3737 let account = "alice" ;
3838 const requests : string [ ] = [ ] ;
3939 const renewals : string [ ] = [ ] ;
40+ let holdViewer : Effect . Effect < void > = Effect . void ;
4041 return Effect . gen ( function * ( ) {
4142 const cli = yield * ForgejoCli . make ;
4243 const provider = yield * ForgejoPullRequestProvider . make . pipe (
@@ -47,14 +48,22 @@ it.effect("refreshes Forgejo viewer permissions immediately after credentials ch
4748 assert . deepStrictEqual ( alice . verdicts , [ "comment" ] ) ;
4849 assert . include ( alice . actions , "merge" ) ;
4950 assert . strictEqual ( alice . labels , true ) ;
51+ const started = yield * Deferred . make < void > ( ) ;
52+ const release = yield * Deferred . make < void > ( ) ;
53+ holdViewer = Deferred . succeed ( started , undefined ) . pipe ( Effect . andThen ( Deferred . await ( release ) ) ) ;
54+ const detail = yield * provider . getChangeRequest ( input ) . pipe ( Effect . forkChild ) ;
55+ yield * Deferred . await ( started ) ;
5056 account = "bob" ;
57+ holdViewer = Effect . void ;
5158 const bob = yield * provider . getViewerPermissions ( input ) ;
5259 assert . deepStrictEqual ( bob . verdicts , [ "comment" , "approve" , "request-changes" ] ) ;
5360 assert . deepStrictEqual ( bob . actions , [ ] ) ;
5461 assert . strictEqual ( bob . labels , false ) ;
5562 assert . strictEqual ( bob . requestReviewers , false ) ;
56- assert . strictEqual ( requests . length , 6 ) ;
63+ assert . strictEqual ( requests . length , 9 ) ;
5764 assert . deepStrictEqual ( renewals , [ "alice" , "bob" ] ) ;
65+ yield * Deferred . succeed ( release , undefined ) ;
66+ assert . deepStrictEqual ( ( yield * Fiber . join ( detail ) ) . viewerPermissions ?. verdicts , [ "comment" ] ) ;
5867 } ) . pipe (
5968 Effect . provideService (
6069 FileSystem . FileSystem ,
@@ -90,9 +99,11 @@ it.effect("refreshes Forgejo viewer permissions immediately after credentials ch
9099 merged_at : null ,
91100 labels : [ ] ,
92101 }
93- : { full_name : "acme/web" , permissions : { push : account === "alice" , admin : false } } ;
94- return Effect . succeed (
95- HttpClientResponse . fromWeb ( request , new Response ( encodeJson ( response ) ) ) ,
102+ : request . url . includes ( "/statuses/" )
103+ ? [ ]
104+ : { full_name : "acme/web" , permissions : { push : account === "alice" , admin : false } } ;
105+ return ( request . url . endsWith ( "/user" ) ? holdViewer : Effect . void ) . pipe (
106+ Effect . as ( HttpClientResponse . fromWeb ( request , new Response ( encodeJson ( response ) ) ) ) ,
96107 ) ;
97108 } ) ,
98109 ) ,
@@ -118,13 +129,31 @@ it.effect("refreshes Forgejo viewer permissions immediately after credentials ch
118129it . effect ( "reselects the current tea login between API requests" , ( ) => {
119130 let account = "alice" ;
120131 const selected : string [ ] = [ ] ;
132+ let holdLogin : Effect . Effect < void > = Effect . void ;
121133 return Effect . gen ( function * ( ) {
122134 const cli = yield * ForgejoCli . make ;
123- const input = { cwd : "/repo" , repository : "https://forgejo.test/acme/web" , path : "user" } ;
135+ const input = {
136+ cwd : "/repo\n%work" ,
137+ repository : "https://forgejo.test/acme/web" ,
138+ path : "user" ,
139+ } ;
124140 assert . strictEqual ( ( yield * cli . api ( input ) ) . stdout , '{"login":"alice"}' ) ;
125141 account = "bob" ;
126142 assert . strictEqual ( ( yield * cli . api ( input ) ) . stdout , '{"login":"bob"}' ) ;
127- assert . deepStrictEqual ( selected , [ "alice" , "bob" ] ) ;
143+ const started = yield * Deferred . make < void > ( ) ;
144+ const release = yield * Deferred . make < void > ( ) ;
145+ holdLogin = Deferred . succeed ( started , undefined ) . pipe ( Effect . andThen ( Deferred . await ( release ) ) ) ;
146+ const pending = yield * cli . api ( input ) . pipe ( Effect . forkChild ) ;
147+ yield * Deferred . await ( started ) ;
148+ account = "carol" ;
149+ holdLogin = Effect . void ;
150+ assert . strictEqual (
151+ ( yield * cli . api ( { ...input , freshCredentials : true } ) ) . stdout ,
152+ '{"login":"carol"}' ,
153+ ) ;
154+ yield * Deferred . succeed ( release , undefined ) ;
155+ assert . strictEqual ( ( yield * Fiber . join ( pending ) ) . stdout , '{"login":"bob"}' ) ;
156+ assert . deepStrictEqual ( selected , [ "alice" , "bob" , "carol" , "bob" ] ) ;
128157 } ) . pipe (
129158 Effect . provideService (
130159 FileSystem . FileSystem ,
@@ -139,19 +168,28 @@ it.effect("reselects the current tea login between API requests", () => {
139168 process : {
140169 run : ( input ) => {
141170 assert . strictEqual ( input . command , "tea" ) ;
171+ assert . strictEqual ( input . cwd , "/repo\n%work" ) ;
142172 if ( input . args [ 0 ] === "login" )
143- return Effect . succeed (
144- processOutput (
145- encodeJson ( [
146- { name : account , url : "https://forgejo.test" , user : account , default : "true" } ,
147- ] ) ,
173+ return holdLogin . pipe (
174+ Effect . as (
175+ processOutput (
176+ encodeJson ( [
177+ {
178+ name : account ,
179+ url : "https://forgejo.test" ,
180+ user : account ,
181+ default : "true" ,
182+ } ,
183+ ] ) ,
184+ ) ,
148185 ) ,
149186 ) ;
150187 assert . strictEqual ( input . args [ 0 ] , "api" ) ;
151- assert . strictEqual ( input . args [ input . args . indexOf ( "--login" ) + 1 ] , account ) ;
152- selected . push ( account ) ;
188+ const login = input . args [ input . args . indexOf ( "--login" ) + 1 ] ?? "" ;
189+ assert . notStrictEqual ( login , "" ) ;
190+ selected . push ( login ) ;
153191 return Effect . succeed (
154- processOutput ( encodeJson ( { login : account } ) , { stderr : "HTTP/1.1 200 OK\n" } ) ,
192+ processOutput ( encodeJson ( { login } ) , { stderr : "HTTP/1.1 200 OK\n" } ) ,
155193 ) ;
156194 } ,
157195 } ,
@@ -173,6 +211,7 @@ it.effect("shares pending Forgejo pull reads and refreshes after writes and fail
173211 Layer . mock ( ForgejoCli . ForgejoCli ) ( {
174212 api : ( input ) =>
175213 Effect . gen ( function * ( ) {
214+ assert . strictEqual ( input . cwd , "/repo\n%work" ) ;
176215 paths . push ( input . path ) ;
177216 if ( input . method === "PATCH" ) {
178217 state = "closed" ;
@@ -223,14 +262,9 @@ it.effect("shares pending Forgejo pull reads and refreshes after writes and fail
223262 const summary = provider . getChangeRequestSummary ;
224263 const checks = provider . getChangeRequestChecks ;
225264 if ( ! summary || ! checks ) return yield * Effect . die ( "narrow reads missing" ) ;
226- const input = { cwd : "/repo" , repository : "acme/web" , host : "forgejo.test" , number : 42 } ;
265+ const input = { cwd : "/repo\n%work " , repository : "acme/web" , host : "forgejo.test" , number : 42 } ;
227266 const reads = yield * Effect . all (
228- [
229- summary ( input ) ,
230- checks ( input ) ,
231- provider . getViewerPermissions ( input ) ,
232- provider . getChangeRequest ( input ) ,
233- ] ,
267+ [ summary ( input ) , checks ( input ) , provider . getChangeRequest ( input ) ] ,
234268 { concurrency : "unbounded" } ,
235269 ) . pipe ( Effect . forkChild ) ;
236270 yield * Deferred . await ( started ) ;
0 commit comments