aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorakbash <akbash@herdr.dev>2026-09-09 22:37:53 +0300
committerGitHub <noreply@github.com>2026-09-09 22:37:53 +0300
commit1f1b20cb5d2a62437e1b21e237164478f9582f52 (patch)
tree1915b0e64cd0feee72c21c290cc1afcf9eb12fc7 /tests
parent1682cab3263b27b296f477552a4e79ab54923091 (diff)
fix: retain double-click selections and make tests root-safe (#3854)
refs #3847 Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/support/mod.rs57
1 files changed, 44 insertions, 13 deletions
diff --git a/tests/support/mod.rs b/tests/support/mod.rs
index b2dae4be..f4ccebe8 100644
--- a/tests/support/mod.rs
+++ b/tests/support/mod.rs
@@ -749,12 +749,14 @@ fn runtime_dir_owner_alive(runtime_dir: &Path) -> bool {
process_exists(owner_pid)
}
-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())
+ // /proc resolves executable symlinks. Match only this Cargo build, including
+ // custom target directories; binary identity alone never grants ownership.
+ static TEST_BINARY: OnceLock<Option<PathBuf>> = OnceLock::new();
+ TEST_BINARY
+ .get_or_init(|| fs::canonicalize(env!("CARGO_BIN_EXE_herdr")).ok())
+ .as_deref()
+ .is_some_and(|binary| path == binary)
}
extern "C" fn run_atexit_cleanup() {
@@ -877,19 +879,48 @@ mod tests {
}
#[test]
- fn test_binary_matcher_accepts_current_checkout_debug_binary() {
- let binary = current_checkout_root().join("target/debug/herdr");
+ fn watchdog_scoping_preserves_registered_live_owner() {
+ let runtime_dir = unique_missing_runtime_dir("live-owner");
+ fs::create_dir_all(&runtime_dir).unwrap();
+ fs::write(
+ runtime_dir.join(RUNTIME_OWNER_MARKER),
+ std::process::id().to_string(),
+ )
+ .unwrap();
+ let registered_runtime_dirs = HashSet::from([runtime_dir.clone()]);
+ let should_terminate = should_terminate_runtime_dir(&runtime_dir, &registered_runtime_dirs);
+ fs::remove_dir_all(runtime_dir).unwrap();
+ assert!(!should_terminate, "a live test owner must remain protected");
+ }
+
+ #[test]
+ fn test_binary_matcher_accepts_cargo_test_binary() {
+ let binary = std::fs::canonicalize(env!("CARGO_BIN_EXE_herdr"))
+ .expect("Cargo-built binary must exist");
assert!(
is_test_herdr_binary(&binary),
- "current checkout debug binary should be considered test-owned"
+ "Cargo-built binary should be considered test-owned regardless of target directory"
);
}
#[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"
- );
+ fn test_binary_matcher_rejects_other_binaries() {
+ let nested_build = Path::new(env!("CARGO_MANIFEST_DIR")).join("other/target/debug/herdr");
+ let sibling_build = Path::new(env!("CARGO_BIN_EXE_herdr"))
+ .parent()
+ .unwrap()
+ .join("other-build/herdr");
+ for binary in [
+ Path::new("/home/can/.local/bin/herdr"),
+ Path::new("/tmp/other-checkout/target/debug/herdr"),
+ nested_build.as_path(),
+ sibling_build.as_path(),
+ ] {
+ assert!(
+ !is_test_herdr_binary(binary),
+ "other binaries must not be considered test-owned: {}",
+ binary.display()
+ );
+ }
}
}