Skip to content

fix(xtask): recommendation_calibration test reads ./fixtures relative to cwd — races parallel with_temp_cwd tests since the #2132 RwLock change #2186

Closed

Description

@EffortlessSteven

Problem

Observed during #2119 slice-2 verification (twice reproducible as scheduling-dependent): reports::recommendation::tests::recommendation_calibration_report_counts_fixture_expectations failed with read ./fixtures/boundary_gap/expected/recommendation-calibration/outcome-receipts/already-covered.json failed: No such file or directory on one full-suite run and passed on the next with an identical tree. Main's full suite passes in isolation and as a suite.

#2132 changed CWD_LOCK to RwLock so spawning tests run in parallel. Any test that reads repo files via a cwd-relative path (like this one reading ./fixtures/...) can now race another test that changed cwd via with_temp_cwd and restored it late — the read lands in the wrong directory depending on scheduling.

A suite that passes or fails by scheduling luck is a false discriminator in both directions: a PR can go red on an unrelated flake, and a real regression in this test could be masked by a lucky pass.

Evidence

  • Branch run 1: 1212 passed / 1 failed (this test, ENOENT on ./fixtures/boundary_gap/...).
  • Branch run 2 (identical tree): 1213 passed / 0 failed.
  • Main full suite: 1205 passed / 0 failed (same test included).

Fix (pick one)

  1. Anchor the read at CARGO_MANIFEST_DIR/.. (crate-root-relative) instead of ./, matching how other tests resolve repo fixtures.
  2. Have the test take the write guard (acquire_test_cwd_write_guard) so it cannot overlap a cwd mutation.

Option 1 is the durable fix; there may be sibling tests with the same cwd-relative reads — worth a grep for other \./fixtures or Path::new(\"fixtures\") in xtask tests.

Activity

  1. coderabbitai commented on Jul 22, 2026

    @coderabbitai
    🔗 Related PRs

    #1714 - audit(goals): add fail-closed authority audit framework [merged]
    #1845 - fix(ci): unblock authority and policy gates [open]
    #2132 - perf(xtask): use RwLock for CWD_LOCK so spawning tests run in parallel (#2124) [merged]
    #2174 - security(analysis): reject path traversal in diff parser (#2099) [open]
    #2176 - perf(xtask): build ripr once and invoke the binary directly in fixtures and dogfood (#2110) [merged]


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  2. added
    status/needs-work
    on Jul 22, 2026
  3. EffortlessSteven commented on Jul 22, 2026

    @EffortlessSteven
    MemberAuthor

    Implemented in PR #2196 at exact head 550a322. The test now uses the absolute compile-time workspace root, so fixture reads cannot follow ambient cwd changes from parallel with_temp_cwd tests. Proof: focused test passes from repo root and xtask/; recommendation suite 8/8; xtask check and Clippy pass; cargo xtask precommit passes. cargo xtask check-pr is blocked by six inherited TypeScript rerun failures, reproduced unchanged on an untouched origin/main worktree.

  4. added a commit that references this issue on Jul 22, 2026
    27c71f9
  5. EffortlessSteven commented on Jul 22, 2026

    @EffortlessSteven
    MemberAuthor

    Correction to the earlier lane note: PR #2196 was superseded and closed without merge. The issue was resolved by merged PR #2194 at 27c71f9, which serializes both recommendation-calibration fixture readers with the existing CWD write guard. Main contains that fix.

  6. EffortlessSteven commented on Jul 22, 2026

    @EffortlessSteven
    MemberAuthor

    Confirmed live on CI: rust_repair_trust_report_is_reachable_from_dispatch failed in two unrelated PR branches (CX53 and GitHub-hosted runners) while passing locally — it calls set_current_dir(repository_root) with no guard and the executed report reads repo-relative paths, so it races any parallel cwd-sensitive test since #2132. Tiny unblock PR up: the test now holds acquire_test_cwd_write_guard() for the whole window. The broader #2186 fix (crate-root-anchored reads + sibling sweep) is still open; the failing-CI instance is covered by the unblock.

  7. EffortlessSteven commented on Jul 22, 2026

    @EffortlessSteven
    MemberAuthor

    Status update — residual audit after #2194 + #2201:

    Suite-wide inventory (1185 test fns in xtask/src, plus the compiled 1213-test binary run green from a foreign cwd):

    One genuinely unguarded site remained: recommendation_calibration_json_and_markdown_are_structured (xtask/src/reports/recommendation.rs) — passing only via the resolve_root_path → workspace_root() fallback, which a concurrent with_temp_cwd test could trick into the wrong tree. Fix + panic-safe with_repo_cwd hardening in #2204.

    Verdict: after #2204 the suite is fully hardened against the cwd race per this audit. Recommend closing #2186 when #2204 merges; the durable prevention is the established pattern (guard any cwd-dependent test; prefer CARGO_MANIFEST_DIR-anchored paths for new helpers).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/needs-work

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions