@@ -262,6 +262,63 @@ describe("VcsStatusBroadcaster", () => {
262262 } ) . pipe ( Effect . provide ( testLayer ) ) ;
263263 } ) ;
264264
265+ it . effect ( "does not pull automatically on the initial poll when the interval is zero" , ( ) => {
266+ let pullCalls = 0 ;
267+ // Settles on the first remote update or pull, whichever the poll reaches.
268+ const settled = Deferred . makeUnsafe < void > ( ) ;
269+ const behindRemote : VcsStatusRemoteResult = { ...baseRemoteStatus , behindCount : 2 } ;
270+ const testLayer = VcsStatusBroadcaster . layer . pipe (
271+ Layer . provideMerge ( NodeServices . layer ) ,
272+ Layer . provide ( makeBackgroundPolicyLayer ( ( ) => true ) ) ,
273+ Layer . provide (
274+ Layer . succeed ( VcsStatusBroadcaster . VcsAutoPullPolicy , {
275+ isEnabled : ( ) => Effect . succeed ( true ) ,
276+ } ) ,
277+ ) ,
278+ Layer . provide (
279+ Layer . mock ( GitWorkflowService . GitWorkflowService ) ( {
280+ localStatus : ( ) =>
281+ Effect . succeed ( { ...baseLocalStatus , isDefaultRef : true , refName : "main" } ) ,
282+ remoteStatus : ( ) => Effect . succeed ( behindRemote ) ,
283+ invalidateLocalStatus : ( ) => Effect . void ,
284+ invalidateRemoteStatus : ( ) => Effect . void ,
285+ invalidateStatus : ( ) => Effect . void ,
286+ pullCurrentBranch : ( ) =>
287+ Effect . sync ( ( ) => {
288+ pullCalls += 1 ;
289+ return { status : "pulled" as const , refName : "main" , upstreamRef : "origin/main" } ;
290+ } ) . pipe ( Effect . tap ( ( ) => Deferred . succeed ( settled , undefined ) ) ) ,
291+ } ) ,
292+ ) ,
293+ ) ;
294+
295+ return Effect . gen ( function * ( ) {
296+ const broadcaster = yield * VcsStatusBroadcaster . VcsStatusBroadcaster ;
297+ const scope = yield * Scope . make ( ) ;
298+ let remoteUpdated : VcsStatusStreamEvent | undefined ;
299+ yield * Stream . runForEach (
300+ broadcaster . streamStatus (
301+ { cwd : "/repo" } ,
302+ { automaticRemoteRefreshInterval : Effect . succeed ( Duration . zero ) } ,
303+ ) ,
304+ ( event ) => {
305+ if ( event . _tag !== "remoteUpdated" ) return Effect . void ;
306+ remoteUpdated = event ;
307+ return Deferred . succeed ( settled , undefined ) ;
308+ } ,
309+ ) . pipe ( Effect . forkIn ( scope ) ) ;
310+
311+ yield * Deferred . await ( settled ) ;
312+ assert . equal ( pullCalls , 0 ) ;
313+ assert . deepStrictEqual ( remoteUpdated , {
314+ _tag : "remoteUpdated" ,
315+ remote : behindRemote ,
316+ } satisfies VcsStatusStreamEvent ) ;
317+
318+ yield * Scope . close ( scope , Exit . void ) ;
319+ } ) . pipe ( Effect . provide ( testLayer ) ) ;
320+ } ) ;
321+
265322 it . effect ( "reuses the cached VCS status across repeated reads" , ( ) => {
266323 const state = {
267324 currentLocalStatus : baseLocalStatus ,
0 commit comments