diff --git a/crates/spaceshd/src/lifecycle.rs b/crates/spaceshd/src/lifecycle.rs index 3412c45..5e46db4 100644 --- a/crates/spaceshd/src/lifecycle.rs +++ b/crates/spaceshd/src/lifecycle.rs @@ -19,6 +19,11 @@ pub fn socket_path() -> Result { } pub fn lock_path() -> Result { + if let Ok(p) = std::env::var("SPACESH_LOCK") { + if !p.is_empty() { + return Ok(PathBuf::from(p)); + } + } Ok(spacesh_dir()?.join("daemon.lock")) } @@ -64,6 +69,11 @@ mod tests { #[test] fn lock_is_exclusive_within_process() { + let _serial = crate::test_support::serial(); + // Use a private lock path so a real running daemon (which holds the + // global ~/.spacesh/daemon.lock) can't make this test flake. + let tmp = std::env::temp_dir().join("spacesh-lock-exclusive-test.lock"); + std::env::set_var("SPACESH_LOCK", &tmp); let first = acquire_instance_lock().unwrap(); assert!(first.is_some(), "first acquire should succeed"); // A second attempt from the same process on the same fd path: @@ -72,6 +82,8 @@ mod tests { let second = acquire_instance_lock().unwrap(); assert!(second.is_none(), "second acquire should be blocked"); drop(first); + std::env::remove_var("SPACESH_LOCK"); + let _ = std::fs::remove_file(&tmp); } #[test]