@@ -80,6 +80,103 @@ const makeSuccessfulHandle = (stdout: string) =>
8080 getOutputFd : ( ) => Stream . empty ,
8181 } ) ;
8282
83+ describe ( "Git output collection" , ( ) => {
84+ it . effect . each ( [ false , true ] ) (
85+ "preserves chunked UTF-8 and NUL output with callbacks=%s" ,
86+ ( callbacks ) =>
87+ Effect . gen ( function * ( ) {
88+ const stdout = "a\\b\0雪\nlast " ;
89+ const stderr = "Receiving é\r\nUpdating 雪\rdone" ;
90+ const chunks = ( text : string ) =>
91+ Stream . fromIterable (
92+ Array . from ( new TextEncoder ( ) . encode ( text ) , ( byte ) => Uint8Array . of ( byte ) ) ,
93+ ) ;
94+ const spawner = ChildProcessSpawner . make ( ( ) =>
95+ Effect . succeed (
96+ ChildProcessSpawner . makeHandle ( {
97+ ...makeSuccessfulHandle ( "" ) ,
98+ stdout : chunks ( stdout ) ,
99+ stderr : chunks ( stderr ) ,
100+ } ) ,
101+ ) ,
102+ ) ;
103+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
104+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
105+ ) ;
106+ const stdoutLines : string [ ] = [ ] ;
107+ const stderrLines : string [ ] = [ ] ;
108+ const result = yield * driver . execute ( {
109+ operation : "test.chunkedGitOutput" ,
110+ cwd : "/repo" ,
111+ args : [ "status" ] ,
112+ ...( callbacks
113+ ? {
114+ progress : {
115+ onStdoutLine : ( line : string ) => Effect . sync ( ( ) => void stdoutLines . push ( line ) ) ,
116+ onStderrLine : ( line : string ) => Effect . sync ( ( ) => void stderrLines . push ( line ) ) ,
117+ } ,
118+ }
119+ : { } ) ,
120+ } ) ;
121+ assert . deepEqual ( result , {
122+ exitCode : 0 ,
123+ stdout,
124+ stderr,
125+ stdoutTruncated : false ,
126+ stderrTruncated : false ,
127+ } ) ;
128+ assert . deepEqual ( stdoutLines , callbacks ? [ "a\\b\0雪" , "last " ] : [ ] ) ;
129+ assert . deepEqual ( stderrLines , callbacks ? [ "Receiving é" , "Updating 雪" , "done" ] : [ ] ) ;
130+ } ) . pipe ( Effect . provide ( layerServerConfig . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
131+ ) ;
132+
133+ it . effect . each ( [
134+ { callbacks : false , keep : false } ,
135+ { callbacks : false , keep : true } ,
136+ { callbacks : true , keep : false } ,
137+ { callbacks : true , keep : true } ,
138+ ] ) (
139+ "preserves byte caps with callbacks=$callbacks and continued callbacks=$keep" ,
140+ ( { callbacks, keep } ) =>
141+ Effect . gen ( function * ( ) {
142+ const bytes = new TextEncoder ( ) . encode ( "é雪\rdone" ) ;
143+ const spawner = ChildProcessSpawner . make ( ( ) =>
144+ Effect . succeed (
145+ ChildProcessSpawner . makeHandle ( {
146+ ...makeSuccessfulHandle ( "" ) ,
147+ stderr : Stream . fromIterable ( Array . from ( bytes , ( byte ) => Uint8Array . of ( byte ) ) ) ,
148+ } ) ,
149+ ) ,
150+ ) ;
151+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
152+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
153+ ) ;
154+ const lines : string [ ] = [ ] ;
155+ const input = {
156+ operation : "test.cappedGitOutput" ,
157+ cwd : "/repo" ,
158+ args : [ "status" ] ,
159+ maxOutputBytes : 3 ,
160+ keepLineCallbacksAfterTruncation : keep ,
161+ ...( callbacks
162+ ? {
163+ progress : {
164+ onStderrLine : ( line : string ) => Effect . sync ( ( ) => void lines . push ( line ) ) ,
165+ } ,
166+ }
167+ : { } ) ,
168+ } ;
169+ const result = yield * driver . execute ( { ...input , appendTruncationMarker : true } ) ;
170+ assert . equal ( result . stderr , "é\uFFFD" ) ;
171+ assert . isTrue ( result . stderrTruncated ) ;
172+ assert . deepEqual ( lines , callbacks ? ( keep ? [ "é雪" , "done" ] : [ "é\uFFFD" ] ) : [ ] ) ;
173+ const error = yield * driver . execute ( input ) . pipe ( Effect . flip ) ;
174+ assert . equal ( error . outputLength , 4 ) ;
175+ assert . include ( error . detail , "exceeded 3 bytes" ) ;
176+ } ) . pipe ( Effect . provide ( layerServerConfig . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
177+ ) ;
178+ } ) ;
179+
83180const makeTmpDir = (
84181 prefix = "git-vcs-driver-test-" ,
85182) : Effect . Effect < string , PlatformError . PlatformError , FileSystem . FileSystem | Scope . Scope > =>
0 commit comments