mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
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:
@@ -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,
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user