From 72f76280c983a52f32febed33f187d25a00f2ccb Mon Sep 17 00:00:00 2001 From: can1357 Date: Sun, 14 Jun 2026 23:24:03 +0200 Subject: [PATCH] test(pi-shell): tolerate PID-namespaced getsid(0) in session tests Same containerized-CI issue as the pi-natives wrapper test: in a PID namespace the host process's session leader lives outside the namespace, so getsid(0) returns 0 (not -1). Relax the host_sid > 0 sanity asserts in embedded_external_command_runs_in_its_own_session and embedded_pipeline_stage_runs_in_its_own_session to host_sid >= 0; the child-session invariants (own session, distinct from host) are unchanged. --- crates/pi-shell/src/shell.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/pi-shell/src/shell.rs b/crates/pi-shell/src/shell.rs index 57de9b23e..44d9e3bad 100644 --- a/crates/pi-shell/src/shell.rs +++ b/crates/pi-shell/src/shell.rs @@ -2317,9 +2317,12 @@ replace = [{ pattern = "^.+$", replacement = "PWD" }] use std::io::Read as _; // SAFETY: `getsid(0)` only queries the current process session; the return - // value is checked. + // value is checked. Inside a PID namespace (the containerized CI runner) + // the host's session leader can live outside the namespace, so `getsid(0)` + // legitimately reports 0 — only -1 is a real failure. The child-session + // invariants below (own session, distinct from host) stay meaningful. let host_sid = unsafe { libc::getsid(0) }; - assert!(host_sid > 0, "getsid(0) failed: {}", std::io::Error::last_os_error()); + assert!(host_sid >= 0, "getsid(0) failed: {}", std::io::Error::last_os_error()); // Build the same kind of session pi-natives uses in production. let config = ShellConfig { session_env: None, snapshot_path: None, minimizer: None }; @@ -2438,9 +2441,12 @@ replace = [{ pattern = "^.+$", replacement = "PWD" }] async fn embedded_pipeline_stage_runs_in_its_own_session() { use std::io::Read as _; - // SAFETY: `getsid(0)` only queries the current process session; checked below. + // SAFETY: `getsid(0)` only queries the current process session; checked + // below. In a PID namespace (containerized CI) the host's session leader + // can live outside the namespace, so `getsid(0)` reports 0, not an error; + // only -1 is a real failure. let host_sid = unsafe { libc::getsid(0) }; - assert!(host_sid > 0, "getsid(0) failed: {}", std::io::Error::last_os_error()); + assert!(host_sid >= 0, "getsid(0) failed: {}", std::io::Error::last_os_error()); let config = ShellConfig { session_env: None, snapshot_path: None, minimizer: None }; let mut session = create_session(&config).await.expect("create_session");