Skip to content

Commit e8cc437

Browse files
sahrizviclaude
andcommitted
fix: address round-6 cubic finding, decline incorrect Kilo finding on #1274
- cubic (valid): the round-5 regression test didn't wrap its first assertion in try/finally, so a failure there would skip restoreTTY() and leak the mutated process.stdout.isTTY into every later test. Fixed. - Kilo (declined — verified factually wrong): claimed `isTTY` is "an inherited prototype property... regardless of whether stdout is a TTY" and that the `if (ORIGINAL_TTY_DESCRIPTOR)` branch in restoreTTY() is dead code, suggesting it be simplified to an unconditional `delete`. Checked empirically in a real pty (`tmux new-session ... bun -e`, because the sandboxed shell always pipes stdout) rather than trusting either the bot's claim or my own prior comment: when process.stdout genuinely IS a TTY, `isTTY` IS a real own property (`{value: true, writable: true, enumerable: true, configurable: true}`), not inherited, not undefined. Applying Kilo's suggested "fix" would have made restoreTTY() permanently delete the real isTTY property instead of restoring it whenever these tests run in an actual interactive terminal — a regression, not a fix. Left the conditional as-is; expanded the comment to document the verification so this doesn't get relitigated incorrectly again. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JsVwcBQP6VUwqEej3vK2zG
1 parent e3dc954 commit e8cc437

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,23 @@ 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.)
32+
// Whether `isTTY` is an own property of process.stdout genuinely depends
33+
// on whether stdout IS a real TTY — it is NOT always inherited/undefined
34+
// (a later review round claimed otherwise; verified wrong empirically, see
35+
// below). Node backs `process.stdout` with different stream classes
36+
// depending on what fd 1 actually is: a `tty.WriteStream` when it's a
37+
// terminal (which sets `this.isTTY = true` as a genuine own instance
38+
// property — confirmed via `Object.getOwnPropertyDescriptor` inside a real
39+
// pty, e.g. `tmux new-session ... bun -e '...'`, where it returns
40+
// `{value: true, writable: true, enumerable: true, configurable: true}`,
41+
// not undefined), versus a plain stream with no `isTTY` at all when piped/
42+
// redirected (which is how it always runs under `bun test`/CI, hence
43+
// ORIGINAL_TTY_DESCRIPTOR being undefined in THAT case specifically).
44+
// So: re-define when there was a real descriptor to restore (interactive
45+
// `bun test` run), delete when there wasn't (everywhere else) — both
46+
// branches are reachable and necessary, not dead code. (cubic, PR #1274
47+
// round 5, on the previous version of this function that always no-op'd
48+
// for the common non-TTY case.)
4149
if (ORIGINAL_TTY_DESCRIPTOR) Object.defineProperty(process.stdout, "isTTY", ORIGINAL_TTY_DESCRIPTOR)
4250
else delete (process.stdout as { isTTY?: boolean }).isTTY
4351
}
@@ -46,8 +54,14 @@ describe("restoreTTY (test-helper regression)", () => {
4654
test("actually removes the isTTY property setTTY() added, instead of leaving it dangling", () => {
4755
const before = Object.getOwnPropertyDescriptor(process.stdout, "isTTY")
4856
setTTY(true)
49-
expect(Object.getOwnPropertyDescriptor(process.stdout, "isTTY")).toBeDefined()
50-
restoreTTY()
57+
// If the assertion below throws, restoreTTY() must still run — otherwise
58+
// this test's own process-global mutation leaks into every test after
59+
// it. (cubic, PR #1274 round 6.)
60+
try {
61+
expect(Object.getOwnPropertyDescriptor(process.stdout, "isTTY")).toBeDefined()
62+
} finally {
63+
restoreTTY()
64+
}
5165
expect(Object.getOwnPropertyDescriptor(process.stdout, "isTTY")).toEqual(before)
5266
})
5367
})

0 commit comments

Comments
 (0)