@@ -3499,74 +3499,117 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
34993499 } ) ,
35003500 ) ;
35013501
3502- it . effect ( "backs off default-branch failures without delaying upstream refreshes" , ( ) =>
3503- Effect . gen ( function * ( ) {
3504- const cwd = yield * makeTmpDir ( ) ;
3505- const remote = yield * makeTmpDir ( "git-vcs-driver-remote-" ) ;
3506- const updater = yield * makeTmpDir ( "git-vcs-driver-updater-" ) ;
3507- const { initialBranch } = yield * initRepoWithCommit ( cwd ) ;
3508- yield * git ( remote , [ "init" , "--bare" ] ) ;
3509- yield * git ( cwd , [ "remote" , "add" , "origin" , remote ] ) ;
3510- yield * git ( cwd , [ "push" , "-u" , "origin" , initialBranch ] ) ;
3511- yield * git ( cwd , [ "remote" , "set-head" , "origin" , initialBranch ] ) ;
3512- yield * git ( cwd , [ "checkout" , "-b" , "feature/backoff" ] ) ;
3513- yield * git ( cwd , [ "push" , "-u" , "origin" , "feature/backoff" ] ) ;
3514- yield * git ( updater , [ "clone" , "--branch" , "feature/backoff" , remote , "." ] ) ;
3515- yield * git ( updater , [ "config" , "user.email" , "[email protected] " ] ) ; 3516- yield * git ( updater , [ "config" , "user.name" , "Test" ] ) ;
3517- yield * git ( updater , [ "commit" , "--allow-empty" , "-m" , "first remote update" ] ) ;
3518- yield * git ( updater , [ "push" ] ) ;
3502+ it . effect . each ( [ "exit" , "timeout" ] as const ) (
3503+ "backs off default-branch %s failures without delaying upstream refreshes" ,
3504+ ( failureMode ) =>
3505+ Effect . gen ( function * ( ) {
3506+ const cwd = yield * makeTmpDir ( ) ;
3507+ const remote = yield * makeTmpDir ( "git-vcs-driver-remote-" ) ;
3508+ const updater = yield * makeTmpDir ( "git-vcs-driver-updater-" ) ;
3509+ const { initialBranch } = yield * initRepoWithCommit ( cwd ) ;
3510+ yield * git ( remote , [ "init" , "--bare" ] ) ;
3511+ yield * git ( cwd , [ "remote" , "add" , "origin" , remote ] ) ;
3512+ yield * git ( cwd , [ "push" , "-u" , "origin" , initialBranch ] ) ;
3513+ yield * git ( cwd , [ "remote" , "set-head" , "origin" , initialBranch ] ) ;
3514+ yield * git ( cwd , [ "checkout" , "-b" , "feature/backoff" ] ) ;
3515+ yield * git ( cwd , [ "push" , "-u" , "origin" , "feature/backoff" ] ) ;
3516+ yield * git ( updater , [ "clone" , "--branch" , "feature/backoff" , remote , "." ] ) ;
3517+ yield * git ( updater , [ "config" , "user.email" , "[email protected] " ] ) ; 3518+ yield * git ( updater , [ "config" , "user.name" , "Test" ] ) ;
3519+ yield * git ( updater , [ "commit" , "--allow-empty" , "-m" , "first remote update" ] ) ;
3520+ yield * git ( updater , [ "push" ] ) ;
35193521
3520- const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
3521- let defaultAttempts = 0 ;
3522- let failDefault = true ;
3523- const spawner = ChildProcessSpawner . make ( ( command ) =>
3524- Effect . gen ( function * ( ) {
3525- if (
3526- ChildProcess . isStandardCommand ( command ) &&
3527- command . args . includes ( "fetch" ) &&
3528- command . args . at ( - 1 ) ?. startsWith ( `+refs/heads/${ initialBranch } :` )
3529- ) {
3530- defaultAttempts += 1 ;
3531- if ( failDefault ) {
3532- return ChildProcessSpawner . makeHandle ( {
3533- ...makeSuccessfulHandle ( "" ) ,
3534- exitCode : Effect . succeed ( ChildProcessSpawner . ExitCode ( 1 ) ) ,
3535- } ) ;
3522+ const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
3523+ let defaultAttempts = 0 ;
3524+ let failDefault = true ;
3525+ const stalledAttempts = yield * Queue . unbounded < void > ( ) ;
3526+ const requiredFetches = yield * Queue . unbounded < Deferred . Deferred < void > > ( ) ;
3527+ const spawner = ChildProcessSpawner . make ( ( command ) =>
3528+ Effect . gen ( function * ( ) {
3529+ if (
3530+ failureMode === "timeout" &&
3531+ ChildProcess . isStandardCommand ( command ) &&
3532+ command . args . includes ( "fetch" ) &&
3533+ command . args . at ( - 1 ) ?. startsWith ( "+refs/heads/feature/backoff:" )
3534+ ) {
3535+ const release = yield * Deferred . make < void > ( ) ;
3536+ yield * Queue . offer ( requiredFetches , release ) ;
3537+ yield * Deferred . await ( release ) ;
3538+ }
3539+ if (
3540+ ChildProcess . isStandardCommand ( command ) &&
3541+ command . args . includes ( "fetch" ) &&
3542+ command . args . at ( - 1 ) ?. startsWith ( `+refs/heads/${ initialBranch } :` )
3543+ ) {
3544+ defaultAttempts += 1 ;
3545+ if ( failDefault ) {
3546+ if ( failureMode === "timeout" ) {
3547+ yield * Queue . offer ( stalledAttempts , undefined ) ;
3548+ return yield * Effect . never ;
3549+ }
3550+ return ChildProcessSpawner . makeHandle ( {
3551+ ...makeSuccessfulHandle ( "" ) ,
3552+ exitCode : Effect . succeed ( ChildProcessSpawner . ExitCode ( 1 ) ) ,
3553+ } ) ;
3554+ }
35363555 }
3556+ return yield * delegate . spawn ( command ) ;
3557+ } ) ,
3558+ ) ;
3559+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
3560+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
3561+ Effect . provide ( layerServerConfig ) ,
3562+ ) ;
3563+ const readStatus = Effect . fnUntraced ( function * ( ) {
3564+ const refresh = yield * driver
3565+ . statusDetailsRemote ( cwd )
3566+ . pipe ( Effect . forkChild ( { startImmediately : true } ) ) ;
3567+ const required = yield * Effect . race (
3568+ Queue . take ( requiredFetches ) ,
3569+ Fiber . await ( refresh ) . pipe ( Effect . as ( null ) ) ,
3570+ ) ;
3571+ if ( required !== null ) {
3572+ yield * TestClock . adjust ( "3 seconds" ) ;
3573+ yield * Deferred . succeed ( required , undefined ) ;
35373574 }
3538- return yield * delegate . spawn ( command ) ;
3539- } ) ,
3540- ) ;
3541- const driver = yield * makeGitVcsDriverCore ( ) . pipe (
3542- Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
3543- Effect . provide ( layerServerConfig ) ,
3544- ) ;
3545- assert . equal ( ( yield * driver . statusDetailsRemote ( cwd ) ) . behindCount , 1 ) ;
3546- assert . equal ( defaultAttempts , 1 ) ;
3575+ const stalled = yield * Effect . race (
3576+ Queue . take ( stalledAttempts ) . pipe ( Effect . as ( true ) ) ,
3577+ Fiber . await ( refresh ) . pipe ( Effect . as ( false ) ) ,
3578+ ) ;
3579+ if ( stalled ) yield * TestClock . adjust ( "2 seconds" ) ;
3580+ return yield * Fiber . join ( refresh ) ;
3581+ } ) ;
3582+ assert . equal ( ( yield * readStatus ( ) ) . behindCount , 1 ) ;
3583+ assert . equal ( defaultAttempts , 1 ) ;
3584+ const fs = yield * FileSystem . FileSystem ;
3585+ const path = yield * Path . Path ;
3586+ assert . deepStrictEqual (
3587+ yield * fs . readDirectory ( path . join ( cwd , ".git" , "objects" , "t3-status-fetch" ) ) ,
3588+ [ ] ,
3589+ ) ;
35473590
3548- yield * git ( updater , [ "commit" , "--allow-empty" , "-m" , "second remote update" ] ) ;
3549- yield * git ( updater , [ "push" ] ) ;
3550- yield * TestClock . adjust ( "16 seconds" ) ;
3551- assert . equal ( ( yield * driver . statusDetailsRemote ( cwd ) ) . behindCount , 2 ) ;
3552- assert . equal ( defaultAttempts , 1 ) ;
3553- for ( const expectedAttempts of [ 2 , 2 , 2 , 2 ] ) {
3591+ yield * git ( updater , [ "commit" , "--allow-empty" , "-m" , "second remote update" ] ) ;
3592+ yield * git ( updater , [ "push" ] ) ;
35543593 yield * TestClock . adjust ( "16 seconds" ) ;
3555- yield * driver . statusDetailsRemote ( cwd ) ;
3556- assert . equal ( defaultAttempts , expectedAttempts ) ;
3557- }
3594+ assert . equal ( ( yield * readStatus ( ) ) . behindCount , 2 ) ;
3595+ assert . equal ( defaultAttempts , 1 ) ;
3596+ for ( const expectedAttempts of [ 2 , 2 , 2 , 2 ] ) {
3597+ yield * TestClock . adjust ( "16 seconds" ) ;
3598+ yield * readStatus ( ) ;
3599+ assert . equal ( defaultAttempts , expectedAttempts ) ;
3600+ }
35583601
3559- failDefault = false ;
3560- yield * TestClock . adjust ( "16 seconds" ) ;
3561- yield * driver . statusDetailsRemote ( cwd ) ;
3562- assert . equal ( defaultAttempts , 3 ) ;
3563- failDefault = true ;
3564- for ( const expectedAttempts of [ 4 , 4 , 5 ] ) {
3602+ failDefault = false ;
35653603 yield * TestClock . adjust ( "16 seconds" ) ;
3566- yield * driver . statusDetailsRemote ( cwd ) ;
3567- assert . equal ( defaultAttempts , expectedAttempts ) ;
3568- }
3569- } ) ,
3604+ yield * readStatus ( ) ;
3605+ assert . equal ( defaultAttempts , 3 ) ;
3606+ failDefault = true ;
3607+ for ( const expectedAttempts of [ 4 , 4 , 5 ] ) {
3608+ yield * TestClock . adjust ( "16 seconds" ) ;
3609+ yield * readStatus ( ) ;
3610+ assert . equal ( defaultAttempts , expectedAttempts ) ;
3611+ }
3612+ } ) ,
35703613 ) ;
35713614
35723615 it . effect . each ( [ "gitdir" , "onbranch" , "global gitdir" ] as const ) (
0 commit comments