Skip to content

Commit 764291c

Browse files
sahrizviclaude
andcommitted
fix(question): close stdin stall + test isolation gap from PR #937 review
Two small fixes flagged by coderabbit + cubic on the prior commit (d2a8516). - `run.ts:459`: the `!process.stdin?.isTTY` null-safety guard turned a crash (undefined stdin) into a stall (we still entered the branch and awaited `Bun.stdin.text()` on a stream that would never EOF). Use `process.stdin && !process.stdin.isTTY` so undefined stdin skips the read entirely — the only sensible behavior in an embedded runtime where there is no stdin to read from. - `question.test.ts`: the `tool.question non-interactive auto-answer` describe block sets `ALTIMATE_NON_INTERACTIVE=1` in beforeEach but didn't clear `ALTIMATE_FORCE_INTERACTIVE`. A parent-shell export could silently flip the suite to the interactive path and lose non-interactive coverage. Delete in both hooks. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent d2a8516 commit 764291c

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎packages/opencode/src/cli/cmd/run.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,13 @@ export const RunCommand = cmd({
454454
message = [extractedParts.join("\n\n"), message].filter(Boolean).join("\n\n")
455455
}
456456

457-
// altimate_change start — null-safe stdin access. process.stdin can be
458-
// undefined in embedded/child runtimes (see dev-punia review on PR #937).
459-
if (!process.stdin?.isTTY) message += "\n" + (await Bun.stdin.text())
457+
// altimate_change start — null-safe stdin read. process.stdin can be
458+
// undefined in embedded/child runtimes (dev-punia review, PR #937).
459+
// Earlier revision used `!process.stdin?.isTTY`, which turned the crash
460+
// into a stall: undefined stdin satisfied the guard and we then awaited
461+
// Bun.stdin.text() on a stream that would never EOF. Skip the read
462+
// entirely when there is no stdin to read from.
463+
if (process.stdin && !process.stdin.isTTY) message += "\n" + (await Bun.stdin.text())
460464
// altimate_change end
461465

462466
if (message.trim().length === 0 && !args.command) {

‎packages/opencode/test/tool/question.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,15 @@ describe("tool.question non-interactive auto-answer", () => {
117117
let askSpy: any
118118

119119
beforeEach(() => {
120+
// Defensive: clear FORCE_INTERACTIVE so a parent-shell export can't
121+
// silently flip this suite to the interactive path and lose coverage.
122+
delete process.env["ALTIMATE_FORCE_INTERACTIVE"]
120123
process.env["ALTIMATE_NON_INTERACTIVE"] = "1"
121124
askSpy = spyOn(QuestionModule.Question, "ask").mockImplementation(async () => [])
122125
})
123126

124127
afterEach(() => {
128+
delete process.env["ALTIMATE_FORCE_INTERACTIVE"]
125129
delete process.env["ALTIMATE_NON_INTERACTIVE"]
126130
delete process.env["ALTIMATE_AUTO_ANSWER"]
127131
askSpy.mockRestore()

0 commit comments

Comments
 (0)