From 6e8477334de4910a65f24a44e32b9bc9b9391302 Mon Sep 17 00:00:00 2001 From: Hunter Bown Date: Sun, 31 May 2026 02:47:48 -0700 Subject: [PATCH] test(shell): cover tty controlling terminal (#2414) Harvested from #2408 with thanks to @axobase001. Adds regression coverage proving tty:true shell commands receive a controlling terminal, with a longer wait margin so the test is stable on slower CI hosts. Partially addresses #2372. --- crates/tui/src/tools/shell/tests.rs | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/tui/src/tools/shell/tests.rs b/crates/tui/src/tools/shell/tests.rs index 7bcd643c..c460f230 100644 --- a/crates/tui/src/tools/shell/tests.rs +++ b/crates/tui/src/tools/shell/tests.rs @@ -241,6 +241,40 @@ fn test_write_stdin_streams_output() { assert!(delta2.result.stdout.is_empty()); } +#[test] +#[cfg(unix)] +fn background_tty_command_has_controlling_terminal() { + let tmp = tempdir().expect("tempdir"); + let mut manager = ShellManager::new(tmp.path().to_path_buf()); + + let result = manager + .execute_with_options( + "sh -c 'exec 3<>/dev/tty && printf tty-ok && exec 3>&-'", + None, + 5000, + true, + None, + true, + Some(ExecutionSandboxPolicy::DangerFullAccess), + ) + .expect("execute tty command"); + + let task_id = result + .task_id + .expect("background tty execution should return task_id"); + + let done = manager + .get_output(&task_id, true, 10_000) + .expect("get tty command output"); + + assert_eq!(done.status, ShellStatus::Completed); + assert_eq!(done.exit_code, Some(0)); + assert!( + done.stdout.contains("tty-ok"), + "tty output should confirm /dev/tty opened; got {done:?}" + ); +} + #[test] fn test_job_list_poll_cancel_and_stale_snapshot() { let tmp = tempdir().expect("tempdir");