Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor: Load completion system in zsh tests instead of guarding compdef
Maximilian Roos8901934ab3c5
diff --git a/src/commands/init.rs b/src/commands/init.rsindex 9e8406390..bc6eb4601 100644--- a/src/commands/init.rs+++ b/src/commands/init.rs@@ -70,22 +70,7 @@ pub fn handle_init(shell_name: &str, cmd_name: &str, cli_cmd: &mut Command) -> Rline.to_string()};- // For zsh, wrap the final compdef call in a guard to prevent errors in --no-rcs mode- // The clap-generated completions end with:- // if [ "$funcstack[1]" = "_wt" ]; then- // _wt "$@"- // else- // compdef _wt wt- // fi- // We need to check if compdef exists before calling it in the else branch- if matches!(shell, shell::Shell::Zsh) && line.trim() == "compdef _wt wt" {- // Wrap the compdef call in a guard (preserve 4-space indentation from else block)- println!(" if (( $+functions[compdef] )); then");- println!(" compdef _wt wt");- println!(" fi");- } else {- println!("{}", line);- }+ println!("{}", line);}Ok(())diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rsindex 10230caad..86889083a 100644--- a/tests/integration_tests/shell_wrapper.rs+++ b/tests/integration_tests/shell_wrapper.rs@@ -106,8 +106,22 @@ fn build_shell_script(shell: &str, repo: &TestRepo, subcommand: &str, args: &[&s));script.push_str("set -x CLICOLOR_FORCE 1\n");}+ "zsh" => {+ // For zsh, initialize the completion system first+ // This allows static completions (which call compdef) to work in isolated mode+ // We run with --no-rcs to prevent user rc files from touching /dev/tty,+ // but compinit is safe since it only sets up completion functions+ 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, zsh+ // bashscript.push_str(&format!("export WORKTRUNK_BIN='{}'\n", wt_bin.display()));script.push_str(&format!("export WORKTRUNK_CONFIG_PATH='{}'\n",diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex 868cbe0ff..d933f99f9 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/.tmpw2OXOa/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpfnWawP/test-config.toml---success: trueexit_code: 0@@ -382,9 +382,7 @@ _wt__switch_commands() {if [ "$funcstack[1]" = "_wt" ]; then_wt "$@"else- if (( $+functions[compdef] )); then- compdef _wt wt- fi+ compdef _wt wtfi----- stderr -----