@@ -121,6 +121,25 @@ describe("execCommand", () => {
121121 expect ( result . stdoutTruncatedChars ) . toBe ( 3 ) ;
122122 } ) ;
123123
124+ it ( "keeps caller-capped retained output UTF-16 safe" , async ( ) => {
125+ const child = createStubChild ( ) ;
126+ const wait = createDeferred < number | null > ( ) ;
127+ spawnMock . mockReturnValue ( child ) ;
128+ waitForChildProcessMock . mockReturnValue ( wait . promise ) ;
129+ const { execCommand } = await import ( "./exec.js" ) ;
130+
131+ const resultPromise = execCommand ( "cmd" , [ ] , "/tmp" , { maxOutputChars : 2 } ) ;
132+ child . stdout . emit ( "data" , Buffer . from ( "A😀B" ) ) ;
133+ child . stderr . emit ( "data" , Buffer . from ( "C😀D" ) ) ;
134+ wait . resolve ( 0 ) ;
135+
136+ const result = await resultPromise ;
137+ expect ( result . stdout ) . toBe ( "B" ) ;
138+ expect ( result . stderr ) . toBe ( "D" ) ;
139+ expect ( result . stdoutTruncatedChars ) . toBe ( 3 ) ;
140+ expect ( result . stderrTruncatedChars ) . toBe ( 3 ) ;
141+ } ) ;
142+
124143 it ( "fails instead of silently truncating default exec output" , async ( ) => {
125144 const child = createStubChild ( ) ;
126145 const wait = createDeferred < number | null > ( ) ;
@@ -129,7 +148,7 @@ describe("execCommand", () => {
129148 const { execCommand } = await import ( "./exec.js" ) ;
130149
131150 const resultPromise = execCommand ( "cmd" , [ ] , "/tmp" ) ;
132- child . stdout . emit ( "data" , Buffer . from ( "x" . repeat ( 16 * 1024 * 1024 + 1 ) ) ) ;
151+ child . stdout . emit ( "data" , Buffer . from ( ` ${ "x" . repeat ( 16 * 1024 * 1024 - 1 ) } 😀` ) ) ;
133152 wait . resolve ( 0 ) ;
134153
135154 const result = await resultPromise ;
@@ -141,8 +160,9 @@ describe("execCommand", () => {
141160 expect ( result . code ) . toBe ( 1 ) ;
142161 expect ( result . killed ) . toBe ( true ) ;
143162 expect ( result . outputLimitExceeded ) . toBe ( "stdout" ) ;
144- expect ( result . stdout . length ) . toBe ( 16 * 1024 * 1024 ) ;
145- expect ( result . stdoutTruncatedChars ) . toBe ( 1 ) ;
163+ expect ( result . stdout . length ) . toBe ( 16 * 1024 * 1024 - 1 ) ;
164+ expect ( result . stdout . endsWith ( "x" ) ) . toBe ( true ) ;
165+ expect ( result . stdoutTruncatedChars ) . toBe ( 2 ) ;
146166 expect ( result . stderr ) . toContain ( "exec stdout exceeded output limit" ) ;
147167 } ) ;
148168
0 commit comments