@@ -25,6 +25,11 @@ const headerLength = defaultSerializer.releaseBuffer().length;
2525const headerOnly = Buffer . from ( [ 0xff , 0x0f ] ) ;
2626const oversizedLengthHeader = Buffer . from ( [ 0xff , 0x0f , 0x7f , 0xff , 0xff , 0xff ] ) ;
2727const truncatedLengthHeader = Buffer . from ( [ 0xff , 0x0f , 0x00 , 0x01 , 0x00 , 0x00 ] ) ;
28+ // Expected stdout for oversizedLengthHeader: first byte is emitted via
29+ // String.fromCharCode (byte-by-byte fallback in #drainRawBuffer), remaining
30+ // bytes go through the nonSerialized UTF-8 decode path in #processRawBuffer.
31+ const oversizedLengthStdout = String . fromCharCode ( oversizedLengthHeader [ 0 ] ) +
32+ Buffer . from ( oversizedLengthHeader . subarray ( 1 ) ) . toString ( 'utf-8' ) ;
2833
2934function collectStdout ( reported ) {
3035 return reported
@@ -98,7 +103,7 @@ describe('v8 deserializer', common.mustCall(() => {
98103 reported ,
99104 Array . from ( { length : reported . length } , ( ) => ( { type : 'test:stdout' } ) ) ,
100105 ) ;
101- assert . strictEqual ( collectStdout ( reported ) , oversizedLengthHeader . toString ( 'utf8' ) ) ;
106+ assert . strictEqual ( collectStdout ( reported ) , oversizedLengthStdout ) ;
102107 } ) ;
103108
104109 it ( 'should flush incomplete v8 frame as stdout and keep prior valid data' , async ( ) => {
@@ -108,14 +113,14 @@ describe('v8 deserializer', common.mustCall(() => {
108113 Buffer . from ( 'hello' ) ,
109114 truncatedLengthHeader ,
110115 ] ) ;
111- assert . strictEqual ( collectStdout ( reported ) , `hello${ truncatedLengthHeader . toString ( 'utf8 ' ) } ` ) ;
116+ assert . strictEqual ( collectStdout ( reported ) , `hello${ truncatedLengthHeader . toString ( 'latin1 ' ) } ` ) ;
112117 } ) ;
113118
114119 it ( 'should flush v8Header-only bytes as stdout when stream ends' , async ( ) => {
115120 // Just the two-byte v8 header with no size field at all.
116121 const reported = await collectReported ( [ headerOnly ] ) ;
117122 assert ( reported . every ( ( event ) => event . type === 'test:stdout' ) ) ;
118- assert . strictEqual ( collectStdout ( reported ) , headerOnly . toString ( 'utf8 ' ) ) ;
123+ assert . strictEqual ( collectStdout ( reported ) , headerOnly . toString ( 'latin1 ' ) ) ;
119124 } ) ;
120125
121126 it ( 'should resync and parse valid messages after false v8 header' , async ( ) => {
@@ -128,7 +133,7 @@ describe('v8 deserializer', common.mustCall(() => {
128133 ] ) ;
129134 assert . deepStrictEqual ( reported . at ( - 1 ) , diagnosticEvent ) ;
130135 assert . strictEqual ( reported . filter ( ( event ) => event . type === 'test:diagnostic' ) . length , 1 ) ;
131- assert . strictEqual ( collectStdout ( reported ) , oversizedLengthHeader . toString ( 'utf8' ) ) ;
136+ assert . strictEqual ( collectStdout ( reported ) , oversizedLengthStdout ) ;
132137 } ) ;
133138
134139 it ( 'should preserve a false v8 header split across chunks' , async ( ) => {
@@ -137,7 +142,7 @@ describe('v8 deserializer', common.mustCall(() => {
137142 oversizedLengthHeader . subarray ( 1 ) ,
138143 ] ) ;
139144 assert ( reported . every ( ( event ) => event . type === 'test:stdout' ) ) ;
140- assert . strictEqual ( collectStdout ( reported ) , oversizedLengthHeader . toString ( 'utf8' ) ) ;
145+ assert . strictEqual ( collectStdout ( reported ) , oversizedLengthStdout ) ;
141146 } ) ;
142147
143148 const headerPosition = headerLength * 2 + 4 ;
0 commit comments