test(ecc2): assert test config roots differ across threads

Addresses review feedback on #3277 (CodeRabbit): the existing test only
checked that Config::config_path() is stable within one thread. Nothing
guarded the property that makes parallel tests safe, that each test thread
gets its own root. If config_root() regressed to one shared directory, the
existing tests would still pass while parallel tests that save a config
raced on the same file.

The code already behaves correctly, so the new test passes as written. To
show it can fail, I temporarily made config_root() return one process-wide
root (a OnceLock around the thread-local) and ran it:

$ cargo test config_path_under_test_is_distinct   # with that mutation
    running 1 test
    test config::tests::config_path_under_test_is_distinct_across_test_threads ... FAILED
    failures:
    ---- config::tests::config_path_under_test_is_distinct_across_test_threads stdout ----
    thread 'config::tests::config_path_under_test_is_distinct_across_test_threads' panicked at src/config/mod.rs:1167:9:
    assertion `left != right` failed
      left: "<tmp>/ecc2-test-config-958aace6-2774-481f-a50c-7684c5189e20/ecc2/config.toml"
     right: "<tmp>/ecc2-test-config-958aace6-2774-481f-a50c-7684c5189e20/ecc2/config.toml"
    failures:
        config::tests::config_path_under_test_is_distinct_across_test_threads
    test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 492 filtered out; finished in 0.00s

The mutation is reverted and is not part of this commit. With the real code:

$ cargo test config_path_under_test_is_distinct
    test config::tests::config_path_under_test_is_distinct_across_test_threads ... ok
    test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 492 filtered out

$ cargo test   # full suite
    test result: ok. 492 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out

Refs #3276

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Y54kLgLGzLGqAxwLMFEc9
This commit is contained in:
Toni AlataloandClaude Sonnet 5.5 committed 2026-10-01 17:28:06 +09:30
1 parent 2b993291d4
commit 6fae7b03b7
1 file changed
+9
+9
View File
@@ -1157,6 +1157,15 @@ focus_metrics = "e"
assert_eq!(Config::config_path(), Config::config_path());
}
#[test]
fn config_path_under_test_is_distinct_across_test_threads() {
let current = Config::config_path();
let other = std::thread::spawn(Config::config_path)
.join()
.expect("config path thread should complete");
assert_ne!(current, other);
}
#[test]
fn primary_config_path_uses_xdg_style_location() {
let path = Config::config_path();