Skip to content

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

Refactor: Simplify command approval logging and list item rendering

Maximilian Roos1e9887837e67
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index c656cf69d..a2a7f4eb3 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -65,8 +65,7 @@ pub fn check_and_approve_command(
match prompt_for_approval(command, project_id) {
Ok(approved) => approved,
Err(e) => {
- use worktrunk::styling::eprintln;
- eprintln!("{WARNING_EMOJI} {WARNING}Failed to read user input: {e}{WARNING:#}");
+ log_approval_warning("Failed to read user input", e);
return Ok(false);
}
}
@@ -80,17 +79,13 @@ pub fn check_and_approve_command(
fresh_config.approve_command(project_id.to_string(), command.to_string())
{
use worktrunk::styling::eprintln;
- eprintln!(
- "{WARNING_EMOJI} {WARNING}Failed to save command approval: {e}{WARNING:#}"
- );
+ log_approval_warning("Failed to save command approval", e);
eprintln!("You will be prompted again next time.");
}
}
Err(e) => {
use worktrunk::styling::eprintln;
- eprintln!(
- "{WARNING_EMOJI} {WARNING}Failed to reload config for saving approval: {e}{WARNING:#}"
- );
+ log_approval_warning("Failed to reload config for saving approval", e);
eprintln!("You will be prompted again next time.");
}
}
@@ -100,6 +95,12 @@ pub fn check_and_approve_command(
}
}
+/// Log a warning message for command approval failures
+fn log_approval_warning(message: &str, error: impl std::fmt::Display) {
+ use worktrunk::styling::eprintln;
+ eprintln!("{WARNING_EMOJI} {WARNING}{message}: {error}{WARNING:#}");
+}
+
/// Prompt the user to approve a command for execution
///
/// Displays a formatted prompt asking the user to approve a command,
diff --git a/src/commands/list/render.rs b/src/commands/list/render.rs
index 302948146..fb6fd78e9 100644
--- a/src/commands/list/render.rs
+++ b/src/commands/list/render.rs
@@ -138,14 +138,6 @@ pub fn format_list_item_line(
item: &ListItem,
layout: &LayoutConfig,
current_worktree_path: Option<&std::path::PathBuf>,
-) {
- format_item_line(item, layout, current_worktree_path)
-}
-
-fn format_item_line(
- item: &ListItem,
- layout: &LayoutConfig,
- current_worktree_path: Option<&std::path::PathBuf>,
) {
let widths = &layout.widths;
diff --git a/tests/integration_tests/e2e_shell_post_start.rs b/tests/integration_tests/e2e_shell_post_start.rs
index 70f3ac84a..7047957e3 100644
--- a/tests/integration_tests/e2e_shell_post_start.rs
+++ b/tests/integration_tests/e2e_shell_post_start.rs
@@ -333,7 +333,7 @@ command = "sleep 0.5 && echo 'Task 2' > task2.txt"
.root_path()
.parent()
.unwrap()
- .join("main.parallel-test");
+ .join("test-repo.parallel-test");
assert!(
worktree_path.join("task1.txt").exists(),
"Task 1 should have completed"
@@ -498,7 +498,11 @@ command = "sleep 0.5 && echo 'Fish background done' > fish_bg.txt"
thread::sleep(Duration::from_secs(1));
// Verify background command ran
- let worktree_path = repo.root_path().parent().unwrap().join("main.fish-bg-test");
+ let worktree_path = repo
+ .root_path()
+ .parent()
+ .unwrap()
+ .join("test-repo.fish-bg-test");
let marker_file = worktree_path.join("fish_bg.txt");
assert!(
marker_file.exists(),
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index 1319447d7..8420dd4d6 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -74,7 +74,7 @@ fn test_post_create_single_command() {
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'Setup complete'"
"#,
)
@@ -114,11 +114,11 @@ fn test_post_create_multiple_commands_array() {
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'First'"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'Second'"
"#,
)
@@ -161,11 +161,11 @@ setup = "echo 'Running setup'"
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'Installing deps'"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'Running setup'"
"#,
)
@@ -205,7 +205,7 @@ fn test_post_create_failing_command() {
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "exit 1"
"#,
)
@@ -334,7 +334,7 @@ fn test_post_start_single_background_command() {
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "sleep 1 && echo 'Background task done' > background.txt"
"#,
)
@@ -393,11 +393,11 @@ task2 = "echo 'Task 2 running' > task2.txt"
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'Task 1 running' > task1.txt"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'Task 2 running' > task2.txt"
"#,
)
@@ -449,11 +449,11 @@ server = "sleep 0.5 && echo 'Server running' > server.txt"
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'Setup done' > setup.txt"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "sleep 0.5 && echo 'Server running' > server.txt"
"#,
)
@@ -533,7 +533,7 @@ fn test_post_start_log_file_captures_output() {
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'stdout output' && echo 'stderr output' >&2"
"#,
)
@@ -610,7 +610,7 @@ fn test_post_start_invalid_command_handling() {
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'unclosed quote"
"#,
)
@@ -661,15 +661,15 @@ task3 = "echo 'TASK3_OUTPUT'"
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'TASK1_OUTPUT'"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'TASK2_OUTPUT'"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'TASK3_OUTPUT'"
"#,
)
@@ -763,7 +763,7 @@ fn test_execute_flag_with_post_start_commands() {
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'Background task' > background.txt"
"#,
)
@@ -825,7 +825,7 @@ fn test_post_start_complex_shell_commands() {
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
-project = "main"
+project = "test-repo"
command = "echo 'line1\nline2\nline3' | grep line2 > filtered.txt"
"#,
)