Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: remove global state mutation from recover test (#1203)
Maximilian Roosdec65d8fab44
diff --git a/src/git/recover.rs b/src/git/recover.rsindex 99bc7afab..0018cb499 100644--- a/src/git/recover.rs+++ b/src/git/recover.rs@@ -303,9 +303,6 @@ mod tests {#[test]fn test_recover_from_path_finds_deleted_worktree() {- // Enable debug logging so log::debug! format args are evaluated for coverage- log::set_max_level(log::LevelFilter::Debug);-let tmp = tempfile::tempdir().unwrap();let base = dunce::canonicalize(tmp.path()).unwrap();let repo_dir = base.join("repo");diff --git a/tests/CLAUDE.md b/tests/CLAUDE.mdindex 0f67717b6..fc59eba3d 100644--- a/tests/CLAUDE.md+++ b/tests/CLAUDE.md@@ -256,6 +256,35 @@ cmd.env("HOME", ...);crate::common::pass_coverage_env_to_pty_cmd(&mut cmd);```+## No Global State Mutations in Tests++**Never mutate process-global state in tests.** Rust's test runner executes tests in parallel within the same process, so global mutations leak across tests and cause non-deterministic behavior.++Forbidden patterns:+- `log::set_max_level()` — affects all concurrent and subsequent tests+- `std::env::set_var()` — process-wide, races with other tests+- Setting global `static` variables without synchronization++If coverage tools flag uncovered `log::debug!()` format args, accept the gap — it's not meaningful coverage and not worth global side effects.++```rust+// ❌ BAD: Global mutation leaks across parallel tests+#[test]+fn test_something() {+ log::set_max_level(log::LevelFilter::Debug);+ // ...+}++// ❌ BAD: Environment variable race condition+#[test]+fn test_config_loading() {+ std::env::set_var("MY_CONFIG", "test_value");+ // ...+}+```++For environment-dependent tests, use `Command::new()` with `.env()` to set variables in a subprocess, or use the test isolation helpers (`repo.wt_command()`, `wt_command()`).+## Deterministic Time in TestsTests use `TEST_EPOCH` (2025-01-01) for reproducible timestamps. The constant is defined in `tests/common/mod.rs` and automatically set as `WORKTRUNK_TEST_EPOCH` in the test environment.