Skip to content

test(xtask): close the last unguarded cwd read and make with_repo_cwd panic-safe (#2186) - #2204

Merged
EffortlessSteven merged 1 commit into
mainfrom
codex/xtask-cwd-hardening
Jul 22, 2026
Merged

EffortlessSteven merged 1 commit into
mainfrom
codex/xtask-cwd-hardening

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

Closes the residual #2186 audit. After #2194 and #2201, a full inventory of the xtask suite (1185 test functions; the compiled suite of 1213 tests also passes from a foreign cwd) found exactly one remaining test that reads repo-relative fixture paths without the cwd write guard:

  • recommendation_calibration_json_and_markdown_are_structured (xtask/src/reports/recommendation.rs) — it passed only because resolve_root_path falls back to workspace_root() when ./fixtures/... is missing. A concurrent with_temp_cwd test whose temp tree happens to contain a matching relative path would make the fallback pick the wrong tree. It now holds acquire_test_cwd_write_guard() like its two sibling tests (test(xtask): serialize recommendation fixture cwd access (#2186) #2194's pattern).

Also hardens the guard helper itself:

  • with_repo_cwd (xtask/src/tests.rs) now restores the process cwd via catch_unwind when the guarded body panics, mirroring with_temp_cwd. Previously a panicking body leaked the repo-root cwd (and the write guard's protection) into every other cwd-sensitive test in the process.

Evidence

  • cargo test -p xtask — 1213 passed, 0 failed
  • cargo clippy -p xtask --all-targets -- -D warnings — clean
  • cargo fmt --check -p xtask — clean
  • cargo xtask precommit — clean

Non-goals

  • No production behavior change; test-harness hardening only.
  • No change to run_with_repo_root_cwd (production twin, main.rs): the test lock is cfg(test) and cannot cover it; tests exercising those commands already hold the write guard themselves.

Refs #2186

…_repo_cwd panic-safe (#2186)

Follow-up to #2194/#2201. A full audit of the xtask suite (1213 tests,
also run green from a foreign cwd) found one remaining test reading
repo-relative fixture paths without the cwd write guard:
recommendation_calibration_json_and_markdown_are_structured passed only
because resolve_root_path falls back to workspace_root() when
./fixtures/... is missing — a concurrent with_temp_cwd test whose temp
tree happens to contain a matching relative path would make the fallback
pick the wrong tree. Guard it like its two siblings.

Also make with_repo_cwd restore the process cwd on panic (catch_unwind,
mirroring with_temp_cwd) so a panicking guarded body cannot leak the
repo-root cwd into every other cwd-sensitive test in the process.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@EffortlessSteven, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 616c2ac0-87d0-4708-8884-d785c1880022

📥 Commits

Reviewing files that changed from the base of the PR and between ce3f1bd and 39f5708.

📒 Files selected for processing (2)
  • xtask/src/reports/recommendation.rs
  • xtask/src/tests.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/xtask-cwd-hardening

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

@EffortlessSteven
EffortlessSteven merged commit e83f6df into main Jul 22, 2026
23 of 24 checks passed
@EffortlessSteven
EffortlessSteven deleted the codex/xtask-cwd-hardening branch July 22, 2026 07:00
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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