Skip to content

fix: flaky test_run_with_telemetry_end_to_end due to set_current_dir race #29

Description

@iamclaude697

Problem

test_run_with_telemetry_end_to_end in crates/chaffra-cli/src/main.rs intermittently fails in CI with:

called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }

Root cause

The test calls std::env::set_current_dir(dir.path()) to force the churn state file to be written in a temp directory. set_current_dir mutates process-global state. When cargo test runs tests in parallel (default), any other test that relies on the current working directory — or any test whose TempDir is being resolved relative to cwd — can race with this mutation.

The test passes reliably in isolation (cargo test -- test_run_with_telemetry_end_to_end) but fails non-deterministically under parallel execution.

Observed in

Preferred fix

Remove the set_current_dir call entirely. Instead, pass an explicit state file path to run_with_telemetry (or inject it via config/environment) so the test doesn't need to manipulate global process state. This eliminates the race without requiring --test-threads=1.

Alternatives

  • #[serial] attribute (from serial_test crate) on tests that mutate cwd
  • Run this test with --test-threads=1 in a separate CI step
  • #[ignore] with a link to this issue (least preferred)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions