@@ -14,6 +14,7 @@ import * as FileSystem from "effect/FileSystem";
1414import * as Fiber from "effect/Fiber" ;
1515import * as Layer from "effect/Layer" ;
1616import * as Path from "effect/Path" ;
17+ import * as Queue from "effect/Queue" ;
1718import * as PlatformError from "effect/PlatformError" ;
1819import * as Ref from "effect/Ref" ;
1920import * as Result from "effect/Result" ;
@@ -129,6 +130,55 @@ const makeDriverReleasingLock = (
129130 return { driver, failures } ;
130131 } ) ;
131132
133+ it . effect ( "runs background Git in its own lane so user commands never queue behind it" , ( ) =>
134+ Effect . gen ( function * ( ) {
135+ const gate = yield * Deferred . make < void > ( ) ;
136+ const starts = yield * Queue . unbounded < string > ( ) ;
137+ const spawner = ChildProcessSpawner . make ( ( command ) =>
138+ Effect . gen ( function * ( ) {
139+ yield * Queue . offer (
140+ starts ,
141+ ChildProcess . isStandardCommand ( command ) ? String ( command . args [ 0 ] ) : "" ,
142+ ) ;
143+ return ChildProcessSpawner . makeHandle ( {
144+ ...makeSuccessfulHandle ( "ok" ) ,
145+ exitCode : Deferred . await ( gate ) . pipe ( Effect . as ( ChildProcessSpawner . ExitCode ( 0 ) ) ) ,
146+ } ) ;
147+ } ) ,
148+ ) ;
149+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
150+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
151+ Effect . provide ( layerServerConfig ) ,
152+ ) ;
153+ const run = ( args : ReadonlyArray < string > ) =>
154+ driver . execute ( { operation : "test.gitLane" , cwd : "/repo" , args : [ ...args ] } ) ;
155+ const background = yield * Effect . forEach (
156+ Array . from ( { length : 12 } ) ,
157+ ( ) => run ( [ "background" ] ) ,
158+ {
159+ concurrency : "unbounded" ,
160+ } ,
161+ ) . pipe ( Effect . provideService ( GitVcsDriver . BackgroundGitWork , true ) , Effect . forkChild ) ;
162+ const foreground = yield * Effect . forEach ( Array . from ( { length : 4 } ) , ( ) => run ( [ "foreground" ] ) , {
163+ concurrency : "unbounded" ,
164+ } ) . pipe ( Effect . forkChild ) ;
165+
166+ yield * TestClock . adjust ( "2 seconds" ) ;
167+ const started = yield * Queue . takeAll ( starts ) ;
168+ assert . deepStrictEqual ( [ ...started ] . toSorted ( ) , [
169+ "background" ,
170+ "background" ,
171+ "foreground" ,
172+ "foreground" ,
173+ "foreground" ,
174+ "foreground" ,
175+ ] ) ;
176+ yield * Deferred . succeed ( gate , undefined ) ;
177+ assert . equal ( ( yield * Fiber . join ( background ) ) . length , 12 ) ;
178+ assert . equal ( ( yield * Fiber . join ( foreground ) ) . length , 4 ) ;
179+ } ) . pipe ( Effect . provide ( Layer . mergeAll ( NodeServices . layer , NodeCrypto . layer ) ) ) ,
180+ ) ;
181+
132182describe ( "Git output collection" , ( ) => {
133183 // Git writes in arbitrary chunk sizes; one byte per chunk splits every
134184 // multibyte character across reads.
0 commit comments