@@ -345,21 +345,25 @@ describe("process supervisor", () => {
345345 expect ( exit . stdout ) . toBe ( "" ) ;
346346 } ) ;
347347
348- it ( "bounds retained stdout and stderr while streaming full chunks" , async ( ) => {
348+ it ( "bounds retained output on UTF-16 boundaries while streaming full chunks" , async ( ) => {
349349 const adapter = createStubChildAdapter ( ) ;
350350 createChildAdapterMock . mockResolvedValue ( adapter ) ;
351351
352352 const supervisor = createProcessSupervisor ( ) ;
353353 let streamedStdout = "" ;
354354 let streamedStderr = "" ;
355- const stdoutChunk = `${ "a" . repeat ( 300 ) } stdout-tail` ;
356- const stderrChunk = `${ "b" . repeat ( 300 ) } stderr-tail` ;
355+ const maxCapturedOutputChars = 256 ;
356+ const stdoutMarker = `[openclaw: captured stdout truncated to last ${ maxCapturedOutputChars } chars]\n` ;
357+ const stderrMarker = `[openclaw: captured stderr truncated to last ${ maxCapturedOutputChars } chars]\n` ;
358+ const retainedChars = maxCapturedOutputChars - stdoutMarker . length - 1 ;
359+ const stdoutChunk = `${ "a" . repeat ( stdoutMarker . length ) } 😀${ "s" . repeat ( retainedChars ) } ` ;
360+ const stderrChunk = `${ "b" . repeat ( stderrMarker . length ) } 😀${ "e" . repeat ( retainedChars ) } ` ;
357361 const run = await spawnChild ( supervisor , {
358362 sessionId : "s-capture-cap" ,
359363 argv : createWriteStdoutArgv ( stdoutChunk ) ,
360364 timeoutMs : 1_000 ,
361365 stdinMode : "pipe-closed" ,
362- maxCapturedOutputChars : 256 ,
366+ maxCapturedOutputChars,
363367 onStdout : ( chunk ) => {
364368 streamedStdout += chunk ;
365369 } ,
@@ -375,44 +379,7 @@ describe("process supervisor", () => {
375379 const exit = await run . wait ( ) ;
376380 expect ( streamedStdout ) . toBe ( stdoutChunk ) ;
377381 expect ( streamedStderr ) . toBe ( stderrChunk ) ;
378- expect ( exit . stdout . length ) . toBeLessThanOrEqual ( 256 ) ;
379- expect ( exit . stderr . length ) . toBeLessThanOrEqual ( 256 ) ;
380- expect ( exit . stdout ) . toContain ( "captured stdout truncated" ) ;
381- expect ( exit . stderr ) . toContain ( "captured stderr truncated" ) ;
382- expect ( exit . stdout . endsWith ( "stdout-tail" ) ) . toBe ( true ) ;
383- expect ( exit . stderr . endsWith ( "stderr-tail" ) ) . toBe ( true ) ;
384- } ) ;
385-
386- it ( "keeps retained stdout and stderr tails on complete UTF-16 boundaries" , async ( ) => {
387- const adapter = createStubChildAdapter ( ) ;
388- createChildAdapterMock . mockResolvedValue ( adapter ) ;
389-
390- const supervisor = createProcessSupervisor ( ) ;
391- const maxCapturedOutputChars = 256 ;
392- const marker = `[openclaw: captured stdout truncated to last ${ maxCapturedOutputChars } chars]\n` ;
393- const tailChars = maxCapturedOutputChars - marker . length ;
394- const evictedPrefixChars = marker . length + 1 ;
395- const boundaryChunk = "a" . repeat ( evictedPrefixChars - 1 ) + "😀" + "z" . repeat ( tailChars - 1 ) ;
396- const run = await spawnChild ( supervisor , {
397- sessionId : "s-capture-unicode" ,
398- argv : createWriteStdoutArgv ( boundaryChunk ) ,
399- timeoutMs : 1_000 ,
400- stdinMode : "pipe-closed" ,
401- maxCapturedOutputChars,
402- } ) ;
403-
404- adapter . emitStdout ( boundaryChunk ) ;
405- adapter . emitStderr ( boundaryChunk ) ;
406- adapter . settle ( 0 ) ;
407-
408- const exit = await run . wait ( ) ;
409- const unpairedSurrogate =
410- / [ \uD800 - \uDBFF ] (? ! [ \uDC00 - \uDFFF ] ) | (?< ! [ \uD800 - \uDBFF ] ) [ \uDC00 - \uDFFF ] / u;
411- expect ( exit . stdout ) . not . toMatch ( unpairedSurrogate ) ;
412- expect ( exit . stderr ) . not . toMatch ( unpairedSurrogate ) ;
413- expect ( exit . stdout ) . not . toContain ( "\uFFFD" ) ;
414- expect ( exit . stderr ) . not . toContain ( "\uFFFD" ) ;
415- expect ( exit . stdout . length ) . toBeLessThanOrEqual ( maxCapturedOutputChars ) ;
416- expect ( exit . stderr . length ) . toBeLessThanOrEqual ( maxCapturedOutputChars ) ;
382+ expect ( exit . stdout ) . toBe ( `${ stdoutMarker } ${ "s" . repeat ( retainedChars ) } ` ) ;
383+ expect ( exit . stderr ) . toBe ( `${ stderrMarker } ${ "e" . repeat ( retainedChars ) } ` ) ;
417384 } ) ;
418385} ) ;
0 commit comments