@@ -81,99 +81,75 @@ const makeSuccessfulHandle = (stdout: string) =>
8181 } ) ;
8282
8383describe ( "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 ( ( ) =>
84+ // Git writes in arbitrary chunk sizes; one byte per chunk splits every
85+ // multibyte character across reads.
86+ const byteChunks = ( text : string ) =>
87+ Stream . fromIterable ( Array . from ( new TextEncoder ( ) . encode ( text ) , ( byte ) => Uint8Array . of ( byte ) ) ) ;
88+ const makeDriver = ( output : { stdout ?: string ; stderr ?: string } ) =>
89+ makeGitVcsDriverCore ( ) . pipe (
90+ Effect . provideService (
91+ ChildProcessSpawner . ChildProcessSpawner ,
92+ ChildProcessSpawner . make ( ( ) =>
9593 Effect . succeed (
9694 ChildProcessSpawner . makeHandle ( {
9795 ...makeSuccessfulHandle ( "" ) ,
98- stdout : chunks ( stdout ) ,
99- stderr : chunks ( stderr ) ,
96+ stdout : byteChunks ( output . stdout ?? "" ) ,
97+ stderr : byteChunks ( output . stderr ?? "" ) ,
10098 } ) ,
10199 ) ,
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 ) ) ) ) ,
100+ ) ,
101+ ) ,
102+ ) ;
103+
104+ it . effect ( "returns the same split UTF-8 and NUL output with and without line callbacks" , ( ) =>
105+ Effect . gen ( function * ( ) {
106+ const stdout = "a\\b\0雪\nlast " ;
107+ const stderr = "Receiving é\r\nUpdating 雪\rdone" ;
108+ const driver = yield * makeDriver ( { stdout, stderr } ) ;
109+ const input = { operation : "test.chunkedGitOutput" , cwd : "/repo" , args : [ "status" ] } ;
110+ const expected = {
111+ exitCode : 0 ,
112+ stdout,
113+ stderr,
114+ stdoutTruncated : false ,
115+ stderrTruncated : false ,
116+ } ;
117+
118+ assert . deepEqual ( yield * driver . execute ( input ) , expected ) ;
119+
120+ const stdoutLines : string [ ] = [ ] ;
121+ const stderrLines : string [ ] = [ ] ;
122+ const withCallbacks = yield * driver . execute ( {
123+ ...input ,
124+ progress : {
125+ onStdoutLine : ( line ) => Effect . sync ( ( ) => void stdoutLines . push ( line ) ) ,
126+ onStderrLine : ( line ) => Effect . sync ( ( ) => void stderrLines . push ( line ) ) ,
127+ } ,
128+ } ) ;
129+ assert . deepEqual ( withCallbacks , expected ) ;
130+ assert . deepEqual ( stdoutLines , [ "a\\b\0雪" , "last " ] ) ;
131+ assert . deepEqual ( stderrLines , [ "Receiving é" , "Updating 雪" , "done" ] ) ;
132+ } ) . pipe ( Effect . provide ( layerServerConfig . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
131133 ) ;
132134
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 ) ) ) ) ,
135+ it . effect ( "caps output without line callbacks" , ( ) =>
136+ Effect . gen ( function * ( ) {
137+ const driver = yield * makeDriver ( { stderr : "é雪\rdone" } ) ;
138+ const input = {
139+ operation : "test.cappedGitOutput" ,
140+ cwd : "/repo" ,
141+ args : [ "status" ] ,
142+ maxOutputBytes : 3 ,
143+ } ;
144+
145+ const truncated = yield * driver . execute ( { ...input , appendTruncationMarker : true } ) ;
146+ assert . equal ( truncated . stderr , "é\uFFFD" ) ;
147+ assert . isTrue ( truncated . stderrTruncated ) ;
148+
149+ const error = yield * driver . execute ( input ) . pipe ( Effect . flip ) ;
150+ assert . equal ( error . outputLength , 4 ) ;
151+ assert . include ( error . detail , "exceeded 3 bytes" ) ;
152+ } ) . pipe ( Effect . provide ( layerServerConfig . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
177153 ) ;
178154} ) ;
179155
0 commit comments