@@ -71,6 +71,7 @@ const remoteStatusWithPr: VcsStatusRemoteResult = {
7171function layerTestFor ( state : {
7272 currentLocalStatus : VcsStatusLocalResult ;
7373 currentRemoteStatus : VcsStatusRemoteResult | null ;
74+ currentDivergence ?: Pick < VcsStatusRemoteResult , "aheadCount" | "behindCount" > ;
7475 localStatusCalls : number ;
7576 remoteStatusCalls : number ;
7677 localInvalidationCalls : number ;
@@ -133,6 +134,16 @@ function layerTestFor(state: {
133134 : ( state . beforeCurrentBranch ?? Effect . void ) . pipe (
134135 Effect . andThen ( Effect . sync ( ( ) => state . currentLocalStatus . refName ) ) ,
135136 ) ,
137+ upstreamDivergence : ( ) =>
138+ Effect . sync ( ( ) =>
139+ state . currentRemoteStatus ?. hasUpstream && state . currentLocalStatus . refName !== null
140+ ? {
141+ refName : state . currentLocalStatus . refName ,
142+ aheadCount : ( state . currentDivergence ?? state . currentRemoteStatus ) . aheadCount ,
143+ behindCount : ( state . currentDivergence ?? state . currentRemoteStatus ) . behindCount ,
144+ }
145+ : null ,
146+ ) ,
136147 remoteStatus : ( _input , options ) =>
137148 Effect . suspend ( ( ) => {
138149 return ( state . beforeRemoteStatus ?? Effect . void ) . pipe (
@@ -528,6 +539,48 @@ describe("VcsStatusBroadcaster", () => {
528539 } ,
529540 ) ;
530541
542+ it . effect . each ( [ 0 , 2 ] ) (
543+ "refreshes merge divergence while a lookup ends with %s commits behind" ,
544+ ( behindAfterLookup ) => {
545+ const state : Parameters < typeof layerTestFor > [ 0 ] = {
546+ currentLocalStatus : baseLocalStatus ,
547+ currentRemoteStatus : { ...baseRemoteStatus , aheadCount : 2 , behindCount : 3 } ,
548+ localStatusCalls : 0 ,
549+ remoteStatusCalls : 0 ,
550+ localInvalidationCalls : 0 ,
551+ remoteInvalidationCalls : 0 ,
552+ backgroundWorkEnabled : false ,
553+ } ;
554+ return Effect . gen ( function * ( ) {
555+ const broadcaster = yield * VcsStatusBroadcaster . VcsStatusBroadcaster ;
556+ yield * broadcaster . getStatus ( { cwd : "/repo" } ) ;
557+ const started = yield * Deferred . make < void > ( ) ;
558+ const release = yield * Deferred . make < void > ( ) ;
559+ state . beforeRemoteStatus = Deferred . succeed ( started , undefined ) . pipe (
560+ Effect . andThen ( Deferred . await ( release ) ) ,
561+ ) ;
562+ const lookup = yield * broadcaster . refreshPullRequestStatus ( "/repo" ) . pipe ( Effect . forkScoped ) ;
563+ yield * Deferred . await ( started ) ;
564+ state . currentRemoteStatus = { ...baseRemoteStatus , aheadCount : 4 , behindCount : 0 } ;
565+ yield * broadcaster . refreshLocalStatus ( "/repo" ) ;
566+ const status = yield * broadcaster . getStatus ( { cwd : "/repo" } ) ;
567+ assert . equal ( status . aheadCount , 4 ) ;
568+ assert . equal ( status . behindCount , 0 ) ;
569+ assert . equal ( state . remoteStatusCalls , 1 ) ;
570+ state . currentDivergence = { aheadCount : 4 , behindCount : behindAfterLookup } ;
571+ state . currentRemoteStatus =
572+ behindAfterLookup > 0
573+ ? { ...baseRemoteStatus , ...state . currentDivergence }
574+ : { ...baseRemoteStatus , aheadCount : 2 , behindCount : 3 } ;
575+ yield * Deferred . succeed ( release , undefined ) ;
576+ yield * Fiber . join ( lookup ) ;
577+ const afterLookup = yield * broadcaster . getStatus ( { cwd : "/repo" } ) ;
578+ assert . equal ( afterLookup . aheadCount , 4 ) ;
579+ assert . equal ( afterLookup . behindCount , behindAfterLookup ) ;
580+ } ) . pipe ( Effect . provide ( layerTestFor ( state ) ) , Effect . scoped ) ;
581+ } ,
582+ ) ;
583+
531584 it . effect ( "a local-only refresh after a branch switch leaves the PR refresh able to read" , ( ) => {
532585 const state : Parameters < typeof layerTestFor > [ 0 ] = {
533586 currentLocalStatus : baseLocalStatus ,
0 commit comments