@@ -186,14 +186,64 @@ describe("VcsStatusBroadcaster", () => {
186186 assert . isNull ( refreshed . pr ) ;
187187 assert . equal ( state . localInvalidationCalls , 1 ) ;
188188 assert . equal ( state . remoteStatusCalls , 1 ) ;
189- assert . equal ( state . remoteInvalidationCalls , 0 ) ;
189+ assert . equal ( state . remoteInvalidationCalls , 1 ) ;
190190 assert . deepStrictEqual ( ( yield * Fiber . join ( events ) ) [ 1 ] , {
191- _tag : "localUpdated" ,
191+ _tag : "snapshot" ,
192+ local : state . currentLocalStatus ,
193+ remote : null ,
194+ } ) ;
195+ assert . isNull ( ( yield * broadcaster . getStatus ( { cwd : "/repo" } ) ) . pr ) ;
196+ const snapshot = yield * broadcaster
197+ . streamStatus ( { cwd : "/repo" , includeRemote : false } )
198+ . pipe ( Stream . take ( 1 ) , Stream . runCollect ) ;
199+ assert . deepStrictEqual ( snapshot [ 0 ] , {
200+ _tag : "snapshot" ,
192201 local : state . currentLocalStatus ,
202+ remote : null ,
193203 } ) ;
194204 } ) . pipe ( Effect . provide ( layerTestFor ( state ) ) ) ;
195205 } ) ;
196206
207+ it . effect ( "clears the previous branch's remote status after an in-flight PR refresh" , ( ) => {
208+ const remoteReadStarted = Deferred . makeUnsafe < void > ( ) ;
209+ const releaseRemoteRead = Deferred . makeUnsafe < void > ( ) ;
210+ const state = {
211+ currentLocalStatus : baseLocalStatus ,
212+ currentRemoteStatus : remoteStatusWithPr ,
213+ localStatusCalls : 0 ,
214+ remoteStatusCalls : 0 ,
215+ localInvalidationCalls : 0 ,
216+ remoteInvalidationCalls : 0 ,
217+ beforeRemoteStatus : Effect . void ,
218+ } ;
219+
220+ return Effect . gen ( function * ( ) {
221+ const broadcaster = yield * VcsStatusBroadcaster . VcsStatusBroadcaster ;
222+ yield * broadcaster . getStatus ( { cwd : "/repo" } ) ;
223+ state . beforeRemoteStatus = Deferred . succeed ( remoteReadStarted , undefined ) . pipe (
224+ Effect . andThen ( Deferred . await ( releaseRemoteRead ) ) ,
225+ ) ;
226+ const remoteRefresh = yield * broadcaster
227+ . refreshPullRequestStatus ( "/repo" )
228+ . pipe ( Effect . forkScoped ) ;
229+ yield * Deferred . await ( remoteReadStarted ) ;
230+ state . currentLocalStatus = { ...baseLocalStatus , refName : "main" } ;
231+ const localRefresh = yield * broadcaster
232+ . refreshStatus ( "/repo" , { localOnly : true } )
233+ . pipe ( Effect . forkScoped ) ;
234+ yield * Deferred . succeed ( releaseRemoteRead , undefined ) ;
235+ yield * Fiber . join ( remoteRefresh ) ;
236+ yield * Fiber . join ( localRefresh ) ;
237+
238+ const status = yield * broadcaster . getStatus ( { cwd : "/repo" } ) ;
239+ assert . equal ( status . refName , "main" ) ;
240+ assert . isNull ( status . pr ) ;
241+ assert . equal ( status . aheadCount , 0 ) ;
242+ assert . equal ( status . behindCount , 0 ) ;
243+ assert . equal ( state . remoteStatusCalls , 2 ) ;
244+ } ) . pipe ( Effect . provide ( layerTestFor ( state ) ) ) ;
245+ } ) ;
246+
197247 it . effect . skipIf ( ! symlinksSupported ) (
198248 "automatically pulls an enabled clean default branch when status detects it is behind" ,
199249 ( ) => {
0 commit comments