From 18f6c50eb9d12c2ba0ea0e73e6524f1c0eb15dec Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Tue, 28 Jul 2026 13:51:18 -0700 Subject: [PATCH] fix(cli): keep the R4-pinned stdin branch shape in applyStdinParam (#3513) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shard 10's R4 regression pin (test/cycle/regression-pr-wave-r1-r2-r4.test.ts, protecting PR #1325's Windows /dev/stdin → fd 0 fix) asserts three source literals in src/cli.ts: `readFileSync(0, ...)`, the `op.cliHints?.stdin` + `MAX_STDIN = 5_000_000` branch, and the `!process.stdin.isTTY` gate. The bounded-read refactor kept the first two but inverted the TTY gate into a positive early-return, dropping the pinned `!process.stdin.isTTY` spelling. Restore the original branch shape inside applyStdinParam (guard + read + cap + assign), unchanged semantics. The #1325 protection itself was never at risk: no '/dev/stdin' anywhere, readFileSync(0) remains the read for non-pipe stdin, and pipes drain through process.stdin (fd 0, cross-platform). The pin now passes unmodified. A comment marks the shape as R4-pinned so the next refactor doesn't trip it. Co-Authored-By: Claude Opus 5 --- src/cli.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 65091bfa6..f1c47012b 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -837,15 +837,19 @@ export async function applyStdinParam( op: Operation, params: Record, ): Promise { - if (!op.cliHints?.stdin || params[op.cliHints.stdin] || process.stdin.isTTY) return; - const content = await readStdinBounded(); - if (content === null) return; // no input arrived — let the required-param check fail fast - const MAX_STDIN = 5_000_000; // 5MB - if (Buffer.byteLength(content, 'utf-8') > MAX_STDIN) { - console.error(`Error: stdin content exceeds ${MAX_STDIN} bytes. Split into smaller inputs.`); - process.exit(1); + // Branch shape (stdin hint + missing param + `!process.stdin.isTTY` gate + + // 5MB cap) is pinned by the R4 regression test for PR #1325's Windows fix + // (test/cycle/regression-pr-wave-r1-r2-r4.test.ts) — keep the spelling. + if (op.cliHints?.stdin && !params[op.cliHints.stdin] && !process.stdin.isTTY) { + const content = await readStdinBounded(); + if (content === null) return; // no input arrived — let the required-param check fail fast + const MAX_STDIN = 5_000_000; // 5MB + if (Buffer.byteLength(content, 'utf-8') > MAX_STDIN) { + console.error(`Error: stdin content exceeds ${MAX_STDIN} bytes. Split into smaller inputs.`); + process.exit(1); + } + params[op.cliHints.stdin] = content; } - params[op.cliHints.stdin] = content; } /** First-byte deadline for pipe/socket stdin (#3513). Env-overridable escape hatch. */