Skip to content

test(main): deflake worktree-watch non-ENOENT readdir test with atomic EACCES injection - #10261

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-worktree-watch-readdir-flake
Jul 24, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-worktree-watch-readdir-flake

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Deflakes worktree-git-common-watch.test.ts > does not fabricate worktree deletions when the readdir fails non-ENOENT (transient), which failed verify on #9970's CI run (failed job) and passed on rerun.

The race

The test simulated a non-ENOENT readdir failure by replacing the worktrees dir with a file (rmSync + writeFileSync), reasoning that a synchronous swap leaves no event-loop turn to observe the transient ENOENT window. That reasoning misses libuv threadpool concurrency: an in-flight poll tick's async opendir executes on a worker thread and can land in the wall-clock window between the two sync calls. It then legitimately observes ENOENT (dir gone = all worktrees removed) and emits exactly the delete keep + update worktrees events seen in the CI failure.

There is no atomic way to replace a non-empty directory with a file, so the window cannot be closed by reordering.

The fix

Inject the failure with chmodSync(worktreesDir, 0o000) instead — one atomic syscall, zero ENOENT window. A concurrent opendir observes either success or EACCES, never ENOENT, and EACCES exercises the same retain-previous-entries branch in snapshotGitCommon that the test protects. Gated with it.runIf off Windows and root, where chmod 0 cannot revoke directory listing and the injection would be inert.

Validation

  • Mutation check: with the non-ENOENT guard in worktree-git-common-snapshot.ts temporarily broken (old catch-all behavior), the reworked test fails — it still catches the regression it exists for.
  • 30 consecutive runs of the test: 0 failures.
  • Full file 14/14 passing; tsc --noEmit -p config/tsconfig.node.json clean; oxlint clean.

Notes

  • Test-only change; no production code touched.
  • process.getuid?.() optional-chaining keeps the gate expression portable on Windows, where the API is absent.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 938c666f-ead5-42bf-a5db-0197e2a59d77

📥 Commits

Reviewing files that changed from the base of the PR and between 6eb70d8 and 9d7abab.

📒 Files selected for processing (1)
  • src/main/ipc/worktree-git-common-watch.test.ts

📝 Walkthrough

Walkthrough

Updated the worktree watcher regression test to replace directory-to-file swapping with permission revocation using chmodSync. The test now skips Windows and root environments, waits through polling while the directory is inaccessible, restores permissions for cleanup, and continues verifying that transient non-ENOENT readdir failures do not emit deletion events.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers Summary, Testing, and Notes, but the required Screenshots, AI Review Report, and Security Audit sections are missing. Add the missing template sections: Screenshots (or 'No visual change'), AI Review Report with cross-platform checks, and a brief Security Audit.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the test deflake and EACCES-injection change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025
brennanb2025 merged commit 4e27e8e into main Jul 24, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant