Skip to content

Commit e3dc954

Browse files
sahrizviclaude
andcommitted
fix: address round-5 cubic finding on #1274 — restoreTTY() was a silent no-op
The round-4 fix for the TTY-descriptor-restoration finding introduced a new bug of its own: `process.stdout.isTTY` has no OWN property descriptor in the common case (stdout piped/redirected, which is how it always runs under a test runner) — Node only sets it as an own property when the stream genuinely is a TTY. So `ORIGINAL_TTY_DESCRIPTOR` was `undefined` in virtually every real test run, and `restoreTTY()`'s `if (descriptor)` guard made it a complete no-op: the property `setTTY()` added stayed shadowed on `process.stdout` for the rest of the process instead of being restored, contradicting the comment's stated intent. Verified empirically (bun -e) before fixing: process.stdout.isTTY genuinely has no own descriptor and isn't found anywhere on its prototype chain when not a real TTY. Fixed by deleting the property when there was no original descriptor to restore. Added a regression test, and confirmed by temporarily reverting the fix that the test actually fails without it (not vacuously green). Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JsVwcBQP6VUwqEej3vK2zG
1 parent 4c0b0b2 commit e3dc954

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎packages/opencode/test/cli/cmd/link.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,29 @@ function setTTY(value: boolean) {
2929
}
3030

3131
function restoreTTY() {
32+
// `isTTY` is not an own property of process.stdout in the common case
33+
// (stdout piped/redirected, as it always is under a test runner) — Node
34+
// only sets it as an own property when the stream genuinely is a TTY. So
35+
// ORIGINAL_TTY_DESCRIPTOR is `undefined` in virtually every real test run,
36+
// and restoring by re-defining only when it's truthy was a no-op: the
37+
// property setTTY() added stayed shadowed on process.stdout for the rest
38+
// of the process. Delete it in that case instead of leaving it dangling.
39+
// (cubic, PR #1274 round 5 — caught in the very helper meant to fix the
40+
// previous round's descriptor-restoration finding.)
3241
if (ORIGINAL_TTY_DESCRIPTOR) Object.defineProperty(process.stdout, "isTTY", ORIGINAL_TTY_DESCRIPTOR)
42+
else delete (process.stdout as { isTTY?: boolean }).isTTY
3343
}
3444

45+
describe("restoreTTY (test-helper regression)", () => {
46+
test("actually removes the isTTY property setTTY() added, instead of leaving it dangling", () => {
47+
const before = Object.getOwnPropertyDescriptor(process.stdout, "isTTY")
48+
setTTY(true)
49+
expect(Object.getOwnPropertyDescriptor(process.stdout, "isTTY")).toBeDefined()
50+
restoreTTY()
51+
expect(Object.getOwnPropertyDescriptor(process.stdout, "isTTY")).toEqual(before)
52+
})
53+
})
54+
3555
describe("stripControlChars", () => {
3656
test("removes C0 control bytes including ESC", () => {
3757
expect(stripControlChars("a\x1bb\x00c")).toBe("abc")

0 commit comments

Comments
 (0)