@@ -3986,45 +3986,73 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
39863986 } ) ;
39873987
39883988 describe ( "remote operations" , ( ) => {
3989- it . effect ( "shares one running fetch of a ref between concurrent callers" , ( ) =>
3990- Effect . gen ( function * ( ) {
3991- const cwd = yield * makeTmpDir ( ) ;
3992- const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
3993- const started = yield * Deferred . make < void > ( ) ;
3994- const release = yield * Deferred . make < void > ( ) ;
3995- let fetches = 0 ;
3996- const spawner = ChildProcessSpawner . make ( ( command ) =>
3997- Effect . gen ( function * ( ) {
3998- if ( ! ChildProcess . isStandardCommand ( command ) )
3999- return yield * Effect . die ( "unexpected command" ) ;
4000- if ( command . args [ 0 ] !== "fetch" ) return yield * delegate . spawn ( command ) ;
4001- fetches += 1 ;
4002- yield * Deferred . succeed ( started , undefined ) ;
4003- return ChildProcessSpawner . makeHandle ( {
4004- ...makeSuccessfulHandle ( "" ) ,
4005- exitCode : Deferred . await ( release ) . pipe ( Effect . as ( ChildProcessSpawner . ExitCode ( 0 ) ) ) ,
4006- } ) ;
4007- } ) ,
4008- ) ;
4009- const driver = yield * makeGitVcsDriverCore ( ) . pipe (
4010- Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
4011- Effect . provide ( layerServerConfig ) ,
4012- ) ;
4013- const fetch = driver . fetchRemote ( { cwd, remoteName : "origin" , refName : "main" } ) ;
4014- const first = yield * fetch . pipe ( Effect . forkChild ( { startImmediately : true } ) ) ;
4015- yield * Deferred . await ( started ) ;
4016- const joined = yield * Effect . forEach ( Array . from ( { length : 5 } ) , ( ) =>
4017- fetch . pipe ( Effect . forkChild ( { startImmediately : true } ) ) ,
4018- ) ;
4019- yield * Deferred . succeed ( release , undefined ) ;
4020- yield * Fiber . join ( first ) ;
4021- yield * Effect . forEach ( joined , Fiber . join ) ;
4022- assert . equal ( fetches , 1 ) ;
4023-
4024- // A finished fetch is not reused.
4025- yield * fetch ;
4026- assert . equal ( fetches , 2 ) ;
4027- } ) ,
3989+ it . effect . each ( [ "public" , "launch-base" ] as const ) (
3990+ "shares one running fetch between concurrent %s callers" ,
3991+ ( caller ) =>
3992+ Effect . gen ( function * ( ) {
3993+ const cwd = yield * makeTmpDir ( ) ;
3994+ const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
3995+ const started = yield * Deferred . make < void > ( ) ;
3996+ const release = yield * Deferred . make < void > ( ) ;
3997+ let fetches = 0 ;
3998+ const spawner = ChildProcessSpawner . make ( ( command ) =>
3999+ Effect . gen ( function * ( ) {
4000+ if ( ! ChildProcess . isStandardCommand ( command ) )
4001+ return yield * Effect . die ( "unexpected command" ) ;
4002+ if ( command . args [ 0 ] === "remote" ) return makeSuccessfulHandle ( "upstream\n" ) ;
4003+ if ( command . args [ 0 ] === "for-each-ref" )
4004+ return makeSuccessfulHandle ( "refs/heads/stable\tupstream\trefs/heads/release\n" ) ;
4005+ if ( command . args [ 0 ] === "rev-parse" ) return makeSuccessfulHandle ( "remote-head\n" ) ;
4006+ if ( command . args [ 0 ] !== "fetch" ) return yield * delegate . spawn ( command ) ;
4007+ assert . deepEqual ( command . args , [
4008+ "fetch" ,
4009+ "--quiet" ,
4010+ "--" ,
4011+ "upstream" ,
4012+ "+refs/heads/release:refs/remotes/upstream/release" ,
4013+ ] ) ;
4014+ fetches += 1 ;
4015+ yield * Deferred . succeed ( started , undefined ) ;
4016+ return ChildProcessSpawner . makeHandle ( {
4017+ ...makeSuccessfulHandle ( "" ) ,
4018+ exitCode : Deferred . await ( release ) . pipe ( Effect . as ( ChildProcessSpawner . ExitCode ( 0 ) ) ) ,
4019+ } ) ;
4020+ } ) ,
4021+ ) ;
4022+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
4023+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
4024+ Effect . provide ( layerServerConfig ) ,
4025+ ) ;
4026+ const fetch =
4027+ caller === "public"
4028+ ? driver
4029+ . fetchRemote ( { cwd, remoteName : "upstream" , refName : "upstream/release" } )
4030+ . pipe ( Effect . as ( null ) )
4031+ : driver . fetchWorktreeBaseCommit ( { cwd, refName : "stable" } ) ;
4032+ const first = yield * fetch . pipe ( Effect . forkChild ( { startImmediately : true } ) ) ;
4033+ yield * Deferred . await ( started ) ;
4034+ const joined = yield * Effect . forEach ( Array . from ( { length : 5 } ) , ( ) =>
4035+ fetch . pipe ( Effect . forkChild ( { startImmediately : true } ) ) ,
4036+ ) ;
4037+ yield * Deferred . succeed ( release , undefined ) ;
4038+ const result = yield * Fiber . join ( first ) ;
4039+ assert . deepEqual (
4040+ result ,
4041+ caller === "public"
4042+ ? null
4043+ : { commitSha : "remote-head" , remoteRefName : "upstream/release" } ,
4044+ ) ;
4045+ const results = yield * Effect . forEach ( joined , Fiber . join ) ;
4046+ assert . deepEqual (
4047+ results ,
4048+ Array . from ( { length : 5 } , ( ) => result ) ,
4049+ ) ;
4050+ assert . equal ( fetches , 1 ) ;
4051+
4052+ // A finished fetch is not reused.
4053+ yield * fetch ;
4054+ assert . equal ( fetches , 2 ) ;
4055+ } ) ,
40284056 ) ;
40294057
40304058 it . effect ( "creates a worktree from the latest fetched remote commit" , ( ) =>
0 commit comments