Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Add TTY check to select command with test

Maximilian Roose7716250ba2e
diff --git a/src/commands/select.rs b/src/commands/select.rs
index fbadb30a6..73fe507d6 100644
--- a/src/commands/select.rs
+++ b/src/commands/select.rs
@@ -799,6 +799,13 @@ where
}
pub fn handle_select() -> anyhow::Result<()> {
+ use std::io::IsTerminal;
+
+ // Select requires an interactive terminal for the TUI
+ if !std::io::stdin().is_terminal() {
+ anyhow::bail!("wt select requires an interactive terminal");
+ }
+
let repo = Repository::current();
// Initialize preview mode state file (auto-cleanup on drop)
diff --git a/tests/integration_tests/approval_ui.rs b/tests/integration_tests/approval_ui.rs
index a8a3b208a..199574fb2 100644
--- a/tests/integration_tests/approval_ui.rs
+++ b/tests/integration_tests/approval_ui.rs
@@ -606,3 +606,16 @@ third = "echo 'third' >> output.txt"
"All commands should have run in order"
);
}
+
+/// Test that `wt select` fails in non-TTY environment with clear error message
+///
+/// The select command requires an interactive terminal for its TUI.
+/// When stdin is not a TTY, it should fail with a clear error.
+#[rstest]
+fn test_select_fails_in_non_tty(repo: TestRepo) {
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "select", &[], None);
+ assert_cmd_snapshot!("select_fails_in_non_tty", cmd);
+ });
+}
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__select_fails_in_non_tty.snap b/tests/snapshots/integration__integration_tests__approval_ui__select_fails_in_non_tty.snap
new file mode 100644
index 000000000..70dc95903
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approval_ui__select_fails_in_non_tty.snap
@@ -0,0 +1,32 @@
+---
+source: tests/integration_tests/approval_ui.rs
+info:
+ program: wt
+ args:
+ - select
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+✗ wt select requires an interactive terminal