@@ -87,6 +87,79 @@ const makeFailedHandle = (stderr: string) =>
8787 stderr : Stream . encodeText ( Stream . make ( stderr ) ) ,
8888 } ) ;
8989
90+ describe ( "Git output collection" , ( ) => {
91+ // Git writes in arbitrary chunk sizes; one byte per chunk splits every
92+ // multibyte character across reads.
93+ const byteChunks = ( text : string ) =>
94+ Stream . fromIterable ( Array . from ( new TextEncoder ( ) . encode ( text ) , ( byte ) => Uint8Array . of ( byte ) ) ) ;
95+ const makeDriver = ( output : { stdout ?: string ; stderr ?: string } ) =>
96+ makeGitVcsDriverCore ( ) . pipe (
97+ Effect . provideService (
98+ ChildProcessSpawner . ChildProcessSpawner ,
99+ ChildProcessSpawner . make ( ( ) =>
100+ Effect . succeed (
101+ ChildProcessSpawner . makeHandle ( {
102+ ...makeSuccessfulHandle ( "" ) ,
103+ stdout : byteChunks ( output . stdout ?? "" ) ,
104+ stderr : byteChunks ( output . stderr ?? "" ) ,
105+ } ) ,
106+ ) ,
107+ ) ,
108+ ) ,
109+ ) ;
110+
111+ it . effect ( "returns the same split UTF-8 and NUL output with and without line callbacks" , ( ) =>
112+ Effect . gen ( function * ( ) {
113+ const stdout = "a\\b\0雪\nlast " ;
114+ const stderr = "Receiving é\r\nUpdating 雪\rdone" ;
115+ const driver = yield * makeDriver ( { stdout, stderr } ) ;
116+ const input = { operation : "test.chunkedGitOutput" , cwd : "/repo" , args : [ "status" ] } ;
117+ const expected = {
118+ exitCode : 0 ,
119+ stdout,
120+ stderr,
121+ stdoutTruncated : false ,
122+ stderrTruncated : false ,
123+ } ;
124+
125+ assert . deepEqual ( yield * driver . execute ( input ) , expected ) ;
126+
127+ const stdoutLines : string [ ] = [ ] ;
128+ const stderrLines : string [ ] = [ ] ;
129+ const withCallbacks = yield * driver . execute ( {
130+ ...input ,
131+ progress : {
132+ onStdoutLine : ( line ) => Effect . sync ( ( ) => void stdoutLines . push ( line ) ) ,
133+ onStderrLine : ( line ) => Effect . sync ( ( ) => void stderrLines . push ( line ) ) ,
134+ } ,
135+ } ) ;
136+ assert . deepEqual ( withCallbacks , expected ) ;
137+ assert . deepEqual ( stdoutLines , [ "a\\b\0雪" , "last " ] ) ;
138+ assert . deepEqual ( stderrLines , [ "Receiving é" , "Updating 雪" , "done" ] ) ;
139+ } ) . pipe ( Effect . provide ( layerServerConfig . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
140+ ) ;
141+
142+ it . effect ( "caps output without line callbacks" , ( ) =>
143+ Effect . gen ( function * ( ) {
144+ const driver = yield * makeDriver ( { stderr : "é雪\rdone" } ) ;
145+ const input = {
146+ operation : "test.cappedGitOutput" ,
147+ cwd : "/repo" ,
148+ args : [ "status" ] ,
149+ maxOutputBytes : 3 ,
150+ } ;
151+
152+ const truncated = yield * driver . execute ( { ...input , appendTruncationMarker : true } ) ;
153+ assert . equal ( truncated . stderr , "é\uFFFD" ) ;
154+ assert . isTrue ( truncated . stderrTruncated ) ;
155+
156+ const error = yield * driver . execute ( input ) . pipe ( Effect . flip ) ;
157+ assert . equal ( error . outputLength , 4 ) ;
158+ assert . include ( error . detail , "exceeded 3 bytes" ) ;
159+ } ) . pipe ( Effect . provide ( layerServerConfig . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
160+ ) ;
161+ } ) ;
162+
90163const makeTmpDir = (
91164 prefix = "git-vcs-driver-test-" ,
92165) : Effect . Effect < string , PlatformError . PlatformError , FileSystem . FileSystem | Scope . Scope > =>
0 commit comments