Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(priority): run the self-lowering helpers through shell_exec::Cmd (#4384)
Worktrunk Botdea4029c593a
diff --git a/src/priority.rs b/src/priority.rsindex b2c4661f3..c4b6cdb1d 100644--- a/src/priority.rs+++ b/src/priority.rs@@ -49,8 +49,6 @@use std::ffi::OsStr;use std::process::Command;-#[cfg(unix)]-use std::process::Stdio;#[cfg(all(unix, not(target_os = "macos")))]use std::sync::LazyLock;@@ -94,29 +92,19 @@ pub fn lower_current_process() {#[cfg(unix)]{let pid = std::process::id().to_string();- let quiet = |mut cmd: Command| {- let _ = cmd- .stdin(Stdio::null())- .stdout(Stdio::null())- .stderr(Stdio::null())- .status();+ let run = |program: &str, args: &[&str]| {+ let _ = crate::shell_exec::Cmd::new(program)+ .args(args.iter().copied())+ .run();};#[cfg(target_os = "macos")]- {- let mut cmd = Command::new("/usr/sbin/taskpolicy");- cmd.args(["-b", "-p", &pid]);- quiet(cmd);- }+ run("/usr/sbin/taskpolicy", &["-b", "-p", &pid]);#[cfg(not(target_os = "macos"))]{- let mut renice = Command::new("renice");- renice.args(["-n", "19", "-p", &pid]);- quiet(renice);+ run("renice", &["-n", "19", "-p", &pid]);if *HAS_IONICE {- let mut ionice = Command::new("ionice");- ionice.args(["-c", "3", "-p", &pid]);- quiet(ionice);+ run("ionice", &["-c", "3", "-p", &pid]);}}}diff --git a/tests/integration_tests/step_copy_ignored.rs b/tests/integration_tests/step_copy_ignored.rsindex ffe792919..f2e66f10a 100644--- a/tests/integration_tests/step_copy_ignored.rs+++ b/tests/integration_tests/step_copy_ignored.rs@@ -2010,3 +2010,38 @@ fn test_copy_ignored_require_include_empty_worktreeinclude(mut repo: TestRepo) {"empty .worktreeinclude matches nothing — nothing copied");}++/// Inside a background hook pipeline, copy-ignored lowers its own priority.+/// The helper it spawns for that goes through `shell_exec::Cmd`, so it shows+/// up in the `-vv` trace like every other subprocess.+#[rstest]+#[cfg(unix)]+fn test_copy_ignored_background_priority_helper_is_traced(mut repo: TestRepo) {+ let feature_path = repo.add_worktree("feature");++ let output = repo+ .wt_command()+ .args(["-vv", "step", "copy-ignored"])+ .current_dir(&feature_path)+ .env("WORKTRUNK_FOREGROUND", "-1")+ .output()+ .unwrap();+ assert!(+ output.status.success(),+ "copy-ignored should succeed: {}",+ String::from_utf8_lossy(&output.stderr)+ );++ let helper = if cfg!(target_os = "macos") {+ "/usr/sbin/taskpolicy -b -p"+ } else {+ "renice -n 19 -p"+ };+ let trace_log =+ crate::common::resolve_git_common_dir(repo.root_path()).join("wt/logs/trace.log");+ let trace = fs::read_to_string(&trace_log).unwrap();+ assert!(+ trace.contains(helper),+ "the priority helper should appear in the -vv trace. trace.log: {trace}"+ );+}