mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-13 19:44:53 +08:00
Keep poisoned test locks from cascading across unrelated regressions
The repo-local backlog was effectively exhausted, so this sweep promoted the newly observed test-lock poisoning pain point into ROADMAP #74 and fixed it in place. Test-only env/cwd lock acquisition now recovers poisoned mutexes in the remaining strict call sites, and each affected surface has a regression that proves a panic no longer permanently poisons later tests. Constraint: Keep the fix test-only and avoid widening runtime behavior changes Rejected: Refactor shared helper signatures across broader call paths | unnecessary churn beyond the remaining strict test sites Confidence: high Scope-risk: narrow Reversibility: clean Directive: These guards only recover the mutex; tests that mutate env or cwd still must restore process-global state explicitly Tested: cargo fmt --all --check Tested: cargo clippy --workspace --all-targets -- -D warnings Tested: cargo test --workspace Tested: Architect review (APPROVE) Not-tested: Additional fault-injection around partially restored env/cwd state after panic Related: ROADMAP #74
This commit is contained in:
@@ -10534,7 +10534,7 @@ UU conflicted.rs",
|
||||
|
||||
#[test]
|
||||
fn managed_sessions_default_to_jsonl_and_resolve_legacy_json() {
|
||||
let _guard = cwd_lock().lock().expect("cwd lock");
|
||||
let _guard = cwd_guard();
|
||||
let workspace = temp_workspace("session-resolution");
|
||||
std::fs::create_dir_all(&workspace).expect("workspace should create");
|
||||
let previous = std::env::current_dir().expect("cwd");
|
||||
@@ -10573,7 +10573,7 @@ UU conflicted.rs",
|
||||
|
||||
#[test]
|
||||
fn latest_session_alias_resolves_most_recent_managed_session() {
|
||||
let _guard = cwd_lock().lock().expect("cwd lock");
|
||||
let _guard = cwd_guard();
|
||||
let workspace = temp_workspace("latest-session-alias");
|
||||
std::fs::create_dir_all(&workspace).expect("workspace should create");
|
||||
let previous = std::env::current_dir().expect("cwd");
|
||||
@@ -10606,7 +10606,7 @@ UU conflicted.rs",
|
||||
|
||||
#[test]
|
||||
fn load_session_reference_rejects_workspace_mismatch() {
|
||||
let _guard = cwd_lock().lock().expect("cwd lock");
|
||||
let _guard = cwd_guard();
|
||||
let workspace_a = temp_workspace("session-mismatch-a");
|
||||
let workspace_b = temp_workspace("session-mismatch-b");
|
||||
std::fs::create_dir_all(&workspace_a).expect("workspace a should create");
|
||||
@@ -10680,6 +10680,24 @@ UU conflicted.rs",
|
||||
LOCK.get_or_init(|| Mutex::new(()))
|
||||
}
|
||||
|
||||
fn cwd_guard() -> MutexGuard<'static, ()> {
|
||||
cwd_lock()
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cwd_guard_recovers_after_poisoning() {
|
||||
let poisoned = std::thread::spawn(|| {
|
||||
let _guard = cwd_guard();
|
||||
panic!("poison cwd lock");
|
||||
})
|
||||
.join();
|
||||
assert!(poisoned.is_err(), "poisoning thread should panic");
|
||||
|
||||
let _guard = cwd_guard();
|
||||
}
|
||||
|
||||
fn temp_workspace(label: &str) -> PathBuf {
|
||||
let nanos = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
|
||||
Reference in New Issue
Block a user