From 5bd939fbfc92a8073d0eac11dfb02a31ea638b15 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Wed, 22 Apr 2026 01:53:32 +0300 Subject: [PATCH] fix: clean up shared-checkout test servers --- tests/support/mod.rs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 7342fde3..52a05578 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -223,7 +223,7 @@ fn iter_worktree_server_pids() -> std::io::Result> { continue; } - if is_worktree_herdr_server_process(pid) { + if is_test_herdr_server_process(pid) { pids.push(pid); } } @@ -231,12 +231,12 @@ fn iter_worktree_server_pids() -> std::io::Result> { Ok(pids) } -fn is_worktree_herdr_server_process(pid: u32) -> bool { +fn is_test_herdr_server_process(pid: u32) -> bool { let Some(exe_path) = proc_link_target(pid, "exe") else { return false; }; - if !is_worktree_herdr_binary(&exe_path) { + if !is_test_herdr_binary(&exe_path) { return false; } @@ -296,11 +296,12 @@ fn runtime_dir_owner_alive(runtime_dir: &Path) -> bool { process_exists(owner_pid) } -fn is_worktree_herdr_binary(path: &Path) -> bool { - path.ends_with("target/debug/herdr") - && path - .components() - .any(|component| component.as_os_str() == "herdr-worktrees") +fn current_checkout_root() -> &'static Path { + Path::new(env!("CARGO_MANIFEST_DIR")) +} + +fn is_test_herdr_binary(path: &Path) -> bool { + path.ends_with("target/debug/herdr") && path.starts_with(current_checkout_root()) } extern "C" fn run_atexit_cleanup() { @@ -421,4 +422,21 @@ mod tests { "missing runtime dirs that are session-owned should be considered killable" ); } + + #[test] + fn test_binary_matcher_accepts_current_checkout_debug_binary() { + let binary = current_checkout_root().join("target/debug/herdr"); + assert!( + is_test_herdr_binary(&binary), + "current checkout debug binary should be considered test-owned" + ); + } + + #[test] + fn test_binary_matcher_rejects_installed_binary() { + assert!( + !is_test_herdr_binary(Path::new("/home/can/.local/bin/herdr")), + "installed binaries must not be considered test-owned" + ); + } }