fix(process-host): accept string stdin in synchronous runs (#28225)

fix(process-host): accept string stdin in synchronous runs

Request raw subprocess output with null encoding so Node can encode string stdin as UTF-8. Preserve explicit text decoding and byte capture, with real-runner coverage for both output modes.

Co-authored-by: Joe Esposito <joeespo@gmail.com>
This commit is contained in:
Neil
2026-10-13 17:16:03 -07:00
committed by GitHub
co-authored by Joe Esposito
parent 16efc33a91
commit 3308eb3d00
2 changed files with 25 additions and 1 deletions
@@ -83,6 +83,29 @@ describe('resolveSpawn', () => {
})
describe('runProcessSync', () => {
it.each([false, true])('accepts string stdin with byte capture %s', (captureStdoutAsBytes) => {
const input = 'nonsecret-probe-λ'
const result = runProcessSync({
program: process.execPath,
args: [
'-e',
'process.stdin.pipe(process.stdout, { end: false }); process.stdin.on("end", () => { process.stdout.write(Buffer.from([0,255])); process.stderr.write("diagnostic λ") })'
],
input,
captureStdoutAsBytes
})
expect(result).toMatchObject({
code: 0,
stdout: captureStdoutAsBytes ? '' : `${input}\u0000�`,
stderr: 'diagnostic λ',
timedOut: false,
outputTruncated: false
})
expect(result.stdoutBytes).toEqual(
captureStdoutAsBytes ? Buffer.concat([Buffer.from(input), Buffer.from([0, 255])]) : undefined
)
})
it('reports a timeout as timedOut', () => {
const result = runProcessSync({
program: process.execPath,
+2 -1
View File
@@ -357,7 +357,8 @@ function runResolvedProcessSync(spec: ProcessSpec, resolved: ResolvedSpawn): Pro
input: spec.input,
timeout: spec.timeoutMs === null ? undefined : (spec.timeoutMs ?? DEFAULT_PROCESS_TIMEOUT_MS),
maxBuffer: spec.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES,
encoding: 'buffer'
// Keep raw output without applying the nonexistent 'buffer' encoding to string stdin.
encoding: null
})
const timedOut = result.error
? 'code' in result.error && result.error.code === 'ETIMEDOUT'