Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Fix: Remove generic `cargo build` error message
Maximilian Roosc80cf8a6b628
diff --git a/templates/bash.sh b/templates/bash.shindex df5439bff..4fbcce299 100644--- a/templates/bash.sh+++ b/templates/bash.sh@@ -69,8 +69,7 @@ if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then# If --source was specified, build and use local debug binaryif [[ "$use_source" == true ]]; then- if ! cargo build --quiet >/dev/null 2>&1; then- echo "Error: cargo build failed" >&2+ if ! cargo build --quiet; then_WORKTRUNK_CMD="$saved_cmd"return 1fidiff --git a/templates/fish.fish b/templates/fish.fishindex 0429dc06e..71ff4d84c 100644--- a/templates/fish.fish+++ b/templates/fish.fish@@ -105,8 +105,7 @@ if type -q {{ cmd_prefix }}; or set -q WORKTRUNK_BIN# If --source was specified, build and use local debug binaryif test $use_source = true- if not cargo build --quiet >/dev/null 2>&1- echo "Error: cargo build failed" >&2+ if not cargo build --quietset _WORKTRUNK_CMD $saved_cmdreturn 1enddiff --git a/templates/zsh.zsh b/templates/zsh.zshindex 4bf366dc2..c1ee35607 100644--- a/templates/zsh.zsh+++ b/templates/zsh.zsh@@ -59,27 +59,59 @@ if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then# Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and merge{{ cmd_prefix }}() {- local subcommand="$1"-- case "$subcommand" in- switch|remove|merge)- # Commands that need --internal for directory change support- shift- _wt_exec --internal "$subcommand" "$@"- ;;- beta)- # Check if beta subcommand is select- if [[ "$2" == "select" ]]; then- _wt_exec --internal "$@"- else- command "$_WORKTRUNK_CMD" "$@"- fi- ;;- *)- # All other commands pass through directly- command "$_WORKTRUNK_CMD" "$@"- ;;- esac+ local use_source=false+ local -a args+ local saved_cmd="$_WORKTRUNK_CMD"++ # Check for --source flag and strip it+ for arg in "$@"; do+ if [[ "$arg" == "--source" ]]; then+ use_source=true+ else+ args+=("$arg")+ fi+ done++ # If --source was specified, build and use local debug binary+ if [[ "$use_source" == true ]]; then+ if ! cargo build --quiet; then+ _WORKTRUNK_CMD="$saved_cmd"+ return 1+ fi+ _WORKTRUNK_CMD="./target/debug/wt"+ fi++ # Dispatch based on subcommand (zsh arrays are 1-indexed)+ if [[ ${{ '{' }}#args[@]} -gt 0 ]]; then+ local subcommand="${args[1]}"++ case "$subcommand" in+ switch|remove|merge)+ # Commands that need --internal for directory change support+ _wt_exec --internal "${args[@]}"+ ;;+ beta)+ # Check if beta subcommand is select+ if [[ ${{ '{' }}#args[@]} -gt 1 ]] && [[ "${args[2]}" == "select" ]]; then+ _wt_exec --internal "${args[@]}"+ else+ command "$_WORKTRUNK_CMD" "${args[@]}"+ fi+ ;;+ *)+ # All other commands pass through directly+ command "$_WORKTRUNK_CMD" "${args[@]}"+ ;;+ esac+ else+ # No arguments, just run the command+ command "$_WORKTRUNK_CMD"+ fi++ # Restore original command+ local result=$?+ _WORKTRUNK_CMD="$saved_cmd"+ return $result}# Dynamic completion function for zshdiff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rsindex b2dcc475a..d34993b02 100644--- a/tests/integration_tests/shell_wrapper.rs+++ b/tests/integration_tests/shell_wrapper.rs@@ -1020,4 +1020,136 @@ approved-commands = ["echo 'fish background task'"]// Normalize paths in output for snapshot testingassert_snapshot!(output.normalized());}++ // ========================================================================+ // --source Flag Error Passthrough Tests+ // ========================================================================+ //+ // These tests verify that actual error messages pass through correctly+ // when using the --source flag (instead of being hidden with generic+ // wrapper error messages like "Error: cargo build failed").++ #[rstest]+ #[case("bash")]+ #[case("zsh")]+ #[case("fish")]+ fn test_source_flag_forwards_errors(#[case] shell: &str) {+ use std::env;++ let repo = TestRepo::new();+ repo.commit("Initial commit");++ // Get the worktrunk source directory (where this test is running from)+ // This is the directory that contains Cargo.toml with the workspace+ let worktrunk_source = env::current_dir()+ .expect("Failed to get current directory")+ .canonicalize()+ .expect("Failed to canonicalize path");++ // Build a shell script that runs from the worktrunk source directory+ let wt_bin = get_cargo_bin("wt");+ let wrapper_script = generate_wrapper(&repo, shell);+ let mut script = String::new();++ // Set environment variables+ match shell {+ "fish" => {+ script.push_str(&format!("set -x WORKTRUNK_BIN '{}'\n", wt_bin.display()));+ script.push_str(&format!(+ "set -x WORKTRUNK_CONFIG_PATH '{}'\n",+ repo.test_config_path().display()+ ));+ script.push_str("set -x CLICOLOR_FORCE 1\n");+ }+ "zsh" => {+ script.push_str("autoload -Uz compinit && compinit -i 2>/dev/null\n");+ script.push_str(&format!("export WORKTRUNK_BIN='{}'\n", wt_bin.display()));+ script.push_str(&format!(+ "export WORKTRUNK_CONFIG_PATH='{}'\n",+ repo.test_config_path().display()+ ));+ script.push_str("export CLICOLOR_FORCE=1\n");+ }+ _ => {+ // bash+ script.push_str(&format!("export WORKTRUNK_BIN='{}'\n", wt_bin.display()));+ script.push_str(&format!(+ "export WORKTRUNK_CONFIG_PATH='{}'\n",+ repo.test_config_path().display()+ ));+ script.push_str("export CLICOLOR_FORCE=1\n");+ }+ }++ // Source the wrapper+ script.push_str(&wrapper_script);+ script.push('\n');++ // Try to run wt --source with an invalid subcommand+ // The --source flag triggers cargo build (which succeeds)+ // Then it tries to run 'wt foo' which should fail with "unrecognized subcommand"+ script.push_str("wt --source foo\n");++ // Wrap in subshell to merge stderr+ let final_script = match shell {+ "fish" => format!("begin\n{}\nend 2>&1", script),+ _ => format!("( {} ) 2>&1", script),+ };++ let env_vars = vec![+ ("CLICOLOR_FORCE".to_string(), "1".to_string()),+ (+ "WORKTRUNK_CONFIG_PATH".to_string(),+ repo.test_config_path().to_string_lossy().to_string(),+ ),+ ("TERM".to_string(), "xterm".to_string()),+ ("GIT_AUTHOR_NAME".to_string(), "Test User".to_string()),+ (+ "GIT_AUTHOR_EMAIL".to_string(),+ "[email protected]".to_string(),+ ),+ ("GIT_COMMITTER_NAME".to_string(), "Test User".to_string()),+ (+ "GIT_COMMITTER_EMAIL".to_string(),+ "[email protected]".to_string(),+ ),+ (+ "GIT_AUTHOR_DATE".to_string(),+ "2025-10-28T12:00:00Z".to_string(),+ ),+ (+ "GIT_COMMITTER_DATE".to_string(),+ "2025-10-28T12:00:00Z".to_string(),+ ),+ ("LANG".to_string(), "C".to_string()),+ ("LC_ALL".to_string(), "C".to_string()),+ ("SOURCE_DATE_EPOCH".to_string(), "1761609600".to_string()),+ ];++ let (combined, exit_code) = exec_in_pty(shell, &final_script, &worktrunk_source, &env_vars);++ // Shell-agnostic assertions+ assert_ne!(exit_code, 0, "{}: Command should fail", shell);++ // CRITICAL: Should see wt's actual error message about unrecognized subcommand+ assert!(+ combined.contains("unrecognized subcommand"),+ "{}: Should show actual wt error message 'unrecognized subcommand'.\nOutput:\n{}",+ shell,+ combined+ );++ // CRITICAL: Should NOT see the old generic wrapper error message+ assert!(+ !combined.contains("Error: cargo build failed"),+ "{}: Should not contain old generic error message",+ shell+ );++ // Consolidated snapshot - output should be identical across shells+ // (wt error messages are deterministic)+ insta::allow_duplicates! {+ assert_snapshot!("source_flag_error_passthrough", combined);+ }+ }}diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__source_flag_error_passthrough.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__source_flag_error_passthrough.snapnew file mode 100644index 000000000..90177f437--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__source_flag_error_passthrough.snap@@ -0,0 +1,9 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: combined+---+[1m[31merror:[0m unrecognized subcommand '[33mfoo[0m'++[1m[4mUsage:[0m [1mwt[0m [OPTIONS] <COMMAND>++For more information, try '[1m--help[0m'.diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex fff5dd2bd..2b543d652 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpA4ttAG/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpCRPK4I/test-config.toml---success: trueexit_code: 0@@ -92,8 +92,7 @@ if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then# If --source was specified, build and use local debug binaryif [[ "$use_source" == true ]]; then- if ! cargo build --quiet >/dev/null 2>&1; then- echo "Error: cargo build failed" >&2+ if ! cargo build --quiet; then_WORKTRUNK_CMD="$saved_cmd"return 1fidiff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snapindex 003f854da..6ec46f075 100644--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmppG1KoR/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpLSFnWp/test-config.toml---success: trueexit_code: 0@@ -128,8 +128,7 @@ if type -q wt; or set -q WORKTRUNK_BIN# If --source was specified, build and use local debug binaryif test $use_source = true- if not cargo build --quiet >/dev/null 2>&1- echo "Error: cargo build failed" >&2+ if not cargo build --quietset _WORKTRUNK_CMD $saved_cmdreturn 1enddiff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex e9bfe6682..903a5c4fd 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpgJM1Ra/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpm0uTSY/test-config.toml---success: trueexit_code: 0@@ -82,27 +82,59 @@ if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then# Override wt command to add --internal flag for switch, remove, and mergewt() {- local subcommand="$1"+ local use_source=false+ local -a args+ local saved_cmd="$_WORKTRUNK_CMD"- case "$subcommand" in- switch|remove|merge)- # Commands that need --internal for directory change support- shift- _wt_exec --internal "$subcommand" "$@"- ;;- beta)- # Check if beta subcommand is select- if [[ "$2" == "select" ]]; then- _wt_exec --internal "$@"- else- command "$_WORKTRUNK_CMD" "$@"- fi- ;;- *)- # All other commands pass through directly- command "$_WORKTRUNK_CMD" "$@"- ;;- esac+ # Check for --source flag and strip it+ for arg in "$@"; do+ if [[ "$arg" == "--source" ]]; then+ use_source=true+ else+ args+=("$arg")+ fi+ done++ # If --source was specified, build and use local debug binary+ if [[ "$use_source" == true ]]; then+ if ! cargo build --quiet; then+ _WORKTRUNK_CMD="$saved_cmd"+ return 1+ fi+ _WORKTRUNK_CMD="./target/debug/wt"+ fi++ # Dispatch based on subcommand (zsh arrays are 1-indexed)+ if [[ ${#args[@]} -gt 0 ]]; then+ local subcommand="${args[1]}"++ case "$subcommand" in+ switch|remove|merge)+ # Commands that need --internal for directory change support+ _wt_exec --internal "${args[@]}"+ ;;+ beta)+ # Check if beta subcommand is select+ if [[ ${#args[@]} -gt 1 ]] && [[ "${args[2]}" == "select" ]]; then+ _wt_exec --internal "${args[@]}"+ else+ command "$_WORKTRUNK_CMD" "${args[@]}"+ fi+ ;;+ *)+ # All other commands pass through directly+ command "$_WORKTRUNK_CMD" "${args[@]}"+ ;;+ esac+ else+ # No arguments, just run the command+ command "$_WORKTRUNK_CMD"+ fi++ # Restore original command+ local result=$?+ _WORKTRUNK_CMD="$saved_cmd"+ return $result}# Dynamic completion function for zsh