@@ -12,6 +12,7 @@ import {
1212} from "@t3tools/contracts" ;
1313import * as Cause from "effect/Cause" ;
1414import * as Deferred from "effect/Deferred" ;
15+ import * as Duration from "effect/Duration" ;
1516import * as Effect from "effect/Effect" ;
1617import * as Exit from "effect/Exit" ;
1718import * as Fiber from "effect/Fiber" ;
@@ -88,6 +89,7 @@ interface HarnessOptions {
8889 readonly currentBranch ?: string | null ;
8990 readonly notARepo ?: boolean ;
9091 readonly newWorktreesStartFromOrigin ?: boolean ;
92+ readonly automaticGitFetchInterval ?: Duration . Duration ;
9193 readonly setupScript ?: "started" | "no-script" | "fails" | "dies" ;
9294 readonly dispatchFails ?: boolean ;
9395 readonly dispatchDies ?: boolean ;
@@ -256,7 +258,9 @@ const makeHarness = (options: HarnessOptions = {}) => {
256258 workingTree : { files : [ ] , insertions : 0 , deletions : 0 } ,
257259 } ) ,
258260 ) ;
259- const refreshStatus = vi . fn ( ( _ : string ) => Effect . die ( "refreshStatus stub" ) ) ;
261+ const refreshStatus = vi . fn <
262+ VcsStatusBroadcaster . VcsStatusBroadcaster [ "Service" ] [ "refreshStatus" ]
263+ > ( ( ) => Effect . die ( "refreshStatus stub" ) ) ;
260264 const runForThread = vi . fn ( ( input : { readonly worktreePath : string } ) => {
261265 switch ( options . setupScript ?? "started" ) {
262266 case "no-script" :
@@ -313,6 +317,9 @@ const makeHarness = (options: HarnessOptions = {}) => {
313317 } satisfies Partial < ProjectService . ProjectService [ "Service" ] > ) ,
314318 ServerSettings . layerTest ( {
315319 newWorktreesStartFromOrigin : options . newWorktreesStartFromOrigin ?? false ,
320+ ...( options . automaticGitFetchInterval === undefined
321+ ? { }
322+ : { automaticGitFetchInterval : options . automaticGitFetchInterval } ) ,
316323 } ) ,
317324 Layer . mock ( GitWorkflowService . GitWorkflowService ) ( {
318325 listRefs,
@@ -347,6 +354,7 @@ const makeHarness = (options: HarnessOptions = {}) => {
347354 deleteLocalBranch,
348355 localStatus,
349356 runForThread,
357+ refreshStatus,
350358 } ;
351359} ;
352360
@@ -426,6 +434,27 @@ describe("t3_worktree_handoff", () => {
426434 } ) ;
427435 } ) ;
428436
437+ it . effect ( "refreshes the new worktree's status with the configured Git fetch interval" , ( ) =>
438+ Effect . gen ( function * ( ) {
439+ for ( const [ configured , expected ] of [
440+ [ Duration . zero , Duration . zero ] ,
441+ [ undefined , Duration . seconds ( 30 ) ] ,
442+ ] as const ) {
443+ const harness = makeHarness (
444+ configured === undefined ? { } : { automaticGitFetchInterval : configured } ,
445+ ) ;
446+ yield * runHandoff ( harness , { branch : "feature/refresh" } ) ;
447+
448+ expect ( harness . refreshStatus ) . toHaveBeenCalledTimes ( 1 ) ;
449+ const [ cwd , refreshOptions ] = harness . refreshStatus . mock . calls [ 0 ] ! ;
450+ expect ( cwd ) . toBe ( "/worktrees/project/feature/refresh" ) ;
451+ const interval = refreshOptions ?. automaticRemoteRefreshInterval ;
452+ if ( interval === undefined ) return expect . fail ( "refreshStatus got no fetch interval" ) ;
453+ expect ( Duration . toMillis ( yield * interval ) ) . toBe ( Duration . toMillis ( expected ) ) ;
454+ }
455+ } ) ,
456+ ) ;
457+
429458 it . effect ( "skips the continuation when no continuationPrompt is given" , ( ) => {
430459 const harness = makeHarness ( ) ;
431460 return Effect . gen ( function * ( ) {
0 commit comments