use crate::identity::{Liveness, ProcessId, Resolved};
#[cfg(target_os = "macos")]
use super::is_teardown_mechanism_failure;
use super::root_pid_was_recycled;
fn id(pid: u32, token: u64) -> ProcessId {
ProcessId::from_parts_for_test(pid, token)
}
#[test]
fn recycled_root_pid_resolving_gone_is_not_recycled() {
let original = id(100, 1);
assert!(!root_pid_was_recycled(original, Resolved::Gone, Liveness::Unknown));
assert!(!root_pid_was_recycled(original, Resolved::Gone, Liveness::Alive));
}
#[test]
fn recycled_root_pid_unknown_resolution_is_not_recycled() {
let original = id(100, 1);
assert!(!root_pid_was_recycled(original, Resolved::Unknown, Liveness::Unknown));
}
#[test]
fn recycled_root_pid_resolving_back_to_the_same_identity_is_not_recycled() {
let original = id(100, 1);
assert!(!root_pid_was_recycled(
original,
Resolved::Found(original),
Liveness::Alive
));
}
#[test]
fn recycled_root_pid_a_different_but_dead_identity_is_not_recycled() {
let original = id(100, 1);
let different = id(100, 2); assert!(!root_pid_was_recycled(
original,
Resolved::Found(different),
Liveness::Dead
));
assert!(!root_pid_was_recycled(
original,
Resolved::Found(different),
Liveness::Unknown
));
}
#[test]
fn recycled_root_pid_a_different_live_identity_is_recycled() {
let original = id(100, 1);
let different = id(100, 2); assert!(root_pid_was_recycled(
original,
Resolved::Found(different),
Liveness::Alive
));
}
#[cfg(target_os = "macos")]
#[test]
fn kill_tree_reports_an_ordinary_group_refusal_through_the_real_dispatch_and_classifier_path() {
let mut child = crate::Command::new()
.executable("/usr/bin/true")
.arg("true") .contain_with(crate::ContainMode::Strongest)
.spawn()
.expect("spawn a contained macOS root");
child.test_force_fdmarker_pgid(0);
let err = child
.kill_tree()
.expect_err("an unsignallable (pgid 0) group channel must report Err, not silently succeed");
assert!(
matches!(err, crate::error::Error::Unassessable { source: None, .. }),
"an invalid-pgid refusal is the ORDINARY, expected outcome unix::signal_group's own \
guard documents — got {err:?} instead"
);
assert!(
!is_teardown_mechanism_failure(&err),
"an ordinary group-signal refusal must never classify as a teardown MECHANISM \
failure — got {err:?}"
);
drop(child);
}