Repository navigation
test(daemon): stop mutating process-global cwd in the daemon cwd-repair tests - #14750
Conversation
📝 WalkthroughWalkthroughAdded 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/daemon/pty-subprocess-test-harness.ts (1)
18-27: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten this JSDoc.
Keep the non-obvious reason for the stub. Remove the detailed history and implementation description.
As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Proposed change
-/** - * Makes the daemon look like it is sitting in a deleted cwd, without moving the - * test process there. - * - * Why: `process.cwd()` and `process.chdir()` are process-global. The previous - * version of these tests really did chdir into a temp dir and delete it, so every - * other test file sharing the worker saw a missing cwd for that window — an - * intermittent failure that got likelier once this suite was split across files. - * Stubbing keeps the cwd-repair assertion exact and the process untouched. - */ +/** Stubs a missing daemon cwd without mutating the shared test-process cwd. */Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8cd508e3-8bca-473f-8a4b-bb421d24cd15
📒 Files selected for processing (2)
src/main/daemon/pty-subprocess-test-harness.tssrc/main/daemon/pty-subprocess.test.ts
…ir tests The two cwd-repair tests really did `process.chdir()` into a temp directory and delete it, so for that window every other test file sharing the worker process saw a missing cwd. That was already a hazard; splitting pty-subprocess.test.ts into ten files made the window overlap far more work, and the tests started failing intermittently in full-suite runs while passing in isolation. Stub the boundary instead: report a non-existent daemon cwd via `process.cwd()` and spy on `process.chdir()` to capture the repair target. The assertion gets stricter rather than weaker — it now names the directory the repair chose instead of observing where the process happened to land — and no process-global state moves. Both cwd-repair tests had failed at least once in prior full-suite runs; the suite is green across repeated runs with this change.
f2163a0 to
36aa100
Compare
…ir tests (stablyai#14750) The two cwd-repair tests really did `process.chdir()` into a temp directory and delete it, so for that window every other test file sharing the worker process saw a missing cwd. That was already a hazard; splitting pty-subprocess.test.ts into ten files made the window overlap far more work, and the tests started failing intermittently in full-suite runs while passing in isolation. Stub the boundary instead: report a non-existent daemon cwd via `process.cwd()` and spy on `process.chdir()` to capture the repair target. The assertion gets stricter rather than weaker — it now names the directory the repair chose instead of observing where the process happened to land — and no process-global state moves. Both cwd-repair tests had failed at least once in prior full-suite runs; the suite is green across repeated runs with this change.
The problem
The two daemon cwd-repair tests really did move the test process:
process.cwd()andprocess.chdir()are process-global, so for that window every other test file sharing the worker process saw a deleted working directory.That was already a latent hazard. Splitting
pty-subprocess.test.tsinto ten files (#14728) made the window overlap far more concurrent work, and these two started failing intermittently in full-suite runs while passing in isolation — they failed in two separate full runs, one the macOS variant and one the Linux variant.The fix
Stub the boundary instead of moving the process: report a non-existent daemon cwd from
process.cwd(), and spy onprocess.chdir()to capture the repair target.The assertion gets stricter, not weaker. It previously observed where the process happened to land; it now names the directory
repairDaemonCwd()actually selected:The shared helper lives in
pty-subprocess-test-harness.tsnext to the other daemon env lifecycle helpers.Verification
pty-subprocessfamily: 131 passing across 4 consecutive runsgrepforprocess.chdiroutside the spy returns nothing)Note
The product behavior is unchanged —
repairDaemonCwd()still callsprocess.chdir()for real; only the tests stop doing so.