Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Fix zsh compinit insecure directories warning on CI (#353)
Maximilian Roosfc425957dea4
diff --git a/src/commands/config.rs b/src/commands/config.rsindex 161d7a208..e7ca5bac4 100644--- a/src/commands/config.rs+++ b/src/commands/config.rs@@ -520,6 +520,9 @@ fn check_zsh_compinit_missing() -> bool {// The (( ... )) arithmetic returns exit 0 if true (compdef exists), 1 if falselet mut cmd = Command::new("zsh");cmd.args(["--no-globalrcs", "-ic", "(( $+functions[compdef] ))"]);+ // Suppress zsh's "insecure directories" warning from compinit.+ // See detailed rationale in shell::detect_zsh_compinit().+ cmd.env("ZSH_DISABLE_COMPFIX", "true");let Ok(output) = run(&mut cmd, None) else {return false; // Can't determine, don't warn};diff --git a/src/shell.rs b/src/shell.rsindex 1f6c73fd3..03f177fe8 100644--- a/src/shell.rs+++ b/src/shell.rs@@ -377,8 +377,21 @@ pub fn detect_zsh_compinit() -> Option<bool> {let mut child = Command::new("zsh").arg("-ic").arg(probe_cmd)+ .stdin(Stdio::null()) // Prevent compinit from prompting interactively.stdout(Stdio::piped()).stderr(Stdio::null()) // Suppress user's zsh startup messages+ // Suppress zsh's "insecure directories" warning from compinit.+ //+ // When fpath contains directories with insecure permissions, compinit prompts:+ // "zsh compinit: insecure directories, run compaudit for list."+ // "Ignore insecure directories and continue [y] or abort compinit [n]?"+ //+ // This prompt goes to the TTY (not stderr), so it leaks through even with+ // stderr redirected. It's safe to suppress because:+ // 1. Users with this issue already see the warning every time they open a terminal+ // 2. We're only probing zsh's state, not doing anything security-sensitive+ // 3. This only affects our subprocess, not the user's actual shell+ .env("ZSH_DISABLE_COMPFIX", "true")// Prevent subprocesses from writing to the directive file.env_remove(crate::shell_exec::DIRECTIVE_FILE_ENV_VAR).spawn()diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rsindex 9304c59fc..76ac9b0b7 100644--- a/tests/integration_tests/configure_shell.rs+++ b/tests/integration_tests/configure_shell.rs@@ -946,8 +946,11 @@ mod pty_tests {configure_pty_command(&mut cmd);cmd.env("HOME", temp_home.path());cmd.env("SHELL", "/bin/zsh");- // Disable zsh compinit security check (avoids "insecure directories" warning on CI)- cmd.env("ZSH_DISABLE_COMPFIX", "true");+ // Skip compinit detection probe. The probe spawns `zsh -ic` which may trigger compinit's+ // "insecure directories" warning on CI. That warning goes to /dev/tty (not stdout/stderr),+ // so it leaks into PTY output despite ZSH_DISABLE_COMPFIX. This test is about install+ // preview formatting, not compinit detection.+ cmd.env("WORKTRUNK_TEST_COMPINIT_CONFIGURED", "1");let mut child = pair.slave.spawn_command(cmd).unwrap();drop(pair.slave);@@ -986,7 +989,6 @@ mod pty_tests {/// Test that `wt config shell install` shows preview with gutter-formatted config lines#[rstest]- #[ignore = "flaky on CI due to zsh compinit warnings about insecure directories"]fn test_install_preview_with_gutter(repo: TestRepo, temp_home: TempDir) {// Create zsh config filelet zshrc_path = temp_home.path().join(".zshrc");diff --git a/tests/integration_tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap b/tests/integration_tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snapindex 06dd4628c..2e00b9f29 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap@@ -13,6 +13,4 @@ y↳ Skipped fish; ~/.config/fish/conf.d not found✓ Configured 1 shell-▲ Completions require compinit; add to ~/.zshrc before the wt line:- autoload -Uz compinit && compinit↳ Restart shell or run: source ~/.zshrc