Skip to content

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

test: add coverage tests for --dry-run flag (#545)

Maximilian Roos9425c78c5999
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index 73e75cd6f..34cfa0ec9 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -899,6 +899,221 @@ fn test_configure_shell_no_warning_when_shell_unset(repo: TestRepo, temp_home: T
});
}
+#[rstest]
+fn test_configure_shell_dry_run(repo: TestRepo, temp_home: TempDir) {
+ // Create a fake .zshrc file
+ let zshrc_path = temp_home.path().join(".zshrc");
+ fs::write(&zshrc_path, "# Existing config\n").unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("install")
+ .arg("zsh")
+ .arg("--dry-run")
+ .current_dir(repo.root_path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // Verify the file was NOT modified
+ let content = fs::read_to_string(&zshrc_path).unwrap();
+ assert!(
+ !content.contains("wt config shell init"),
+ "File should not be modified with --dry-run"
+ );
+ assert_eq!(content, "# Existing config\n", "File should be unchanged");
+}
+
+#[rstest]
+fn test_configure_shell_dry_run_multiple(repo: TestRepo, temp_home: TempDir) {
+ // Create multiple shell config files
+ let bash_config_path = temp_home.path().join(".bashrc");
+ let zshrc_path = temp_home.path().join(".zshrc");
+ fs::write(&bash_config_path, "# Existing bash config\n").unwrap();
+ fs::write(&zshrc_path, "# Existing zsh config\n").unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("install")
+ .arg("--dry-run")
+ .current_dir(repo.root_path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // Verify no files were modified
+ let bash_content = fs::read_to_string(&bash_config_path).unwrap();
+ assert!(
+ !bash_content.contains("wt config shell init"),
+ "Bash config should not be modified with --dry-run"
+ );
+ let zsh_content = fs::read_to_string(&zshrc_path).unwrap();
+ assert!(
+ !zsh_content.contains("wt config shell init"),
+ "Zsh config should not be modified with --dry-run"
+ );
+}
+
+#[rstest]
+fn test_configure_shell_dry_run_already_configured(repo: TestRepo, temp_home: TempDir) {
+ // Create a fake .zshrc file with the line already present
+ let zshrc_path = temp_home.path().join(".zshrc");
+ fs::write(
+ &zshrc_path,
+ "# Existing config\nif command -v wt >/dev/null 2>&1; then eval \"$(command wt config shell init zsh)\"; fi\n",
+ )
+ .unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("install")
+ .arg("zsh")
+ .arg("--dry-run")
+ .current_dir(repo.root_path());
+
+ // Already configured - nothing to preview
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
+#[rstest]
+fn test_uninstall_shell_dry_run(repo: TestRepo, temp_home: TempDir) {
+ // Create a fake .zshrc file with wt integration
+ let zshrc_path = temp_home.path().join(".zshrc");
+ fs::write(
+ &zshrc_path,
+ "# Existing config\nif command -v wt >/dev/null 2>&1; then eval \"$(command wt config shell init zsh)\"; fi\n",
+ )
+ .unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("uninstall")
+ .arg("zsh")
+ .arg("--dry-run")
+ .current_dir(repo.root_path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // Verify the file was NOT modified
+ let content = fs::read_to_string(&zshrc_path).unwrap();
+ assert!(
+ content.contains("wt config shell init"),
+ "File should not be modified with --dry-run"
+ );
+}
+
+#[rstest]
+fn test_uninstall_shell_dry_run_fish(repo: TestRepo, temp_home: TempDir) {
+ // Create fish conf.d directory with wt.fish and completions
+ let conf_d = temp_home.path().join(".config/fish/conf.d");
+ fs::create_dir_all(&conf_d).unwrap();
+ let fish_config = conf_d.join("wt.fish");
+ fs::write(
+ &fish_config,
+ "if type -q wt; command wt config shell init fish | source; end\n",
+ )
+ .unwrap();
+
+ // Create completions file
+ let completions_d = temp_home.path().join(".config/fish/completions");
+ fs::create_dir_all(&completions_d).unwrap();
+ let completions_file = completions_d.join("wt.fish");
+ fs::write(&completions_file, "# fish completions").unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/fish");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("uninstall")
+ .arg("fish")
+ .arg("--dry-run")
+ .current_dir(repo.root_path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // Verify files were NOT modified
+ assert!(fish_config.exists(), "Fish config should still exist");
+ assert!(
+ completions_file.exists(),
+ "Fish completions should still exist"
+ );
+}
+
+#[rstest]
+fn test_uninstall_shell_dry_run_multiple(repo: TestRepo, temp_home: TempDir) {
+ // Create multiple shell configs with wt integration
+ let bash_config_path = temp_home.path().join(".bashrc");
+ let zshrc_path = temp_home.path().join(".zshrc");
+ fs::write(
+ &bash_config_path,
+ "# Bash config\nif command -v wt >/dev/null 2>&1; then eval \"$(command wt config shell init bash)\"; fi\n",
+ )
+ .unwrap();
+ fs::write(
+ &zshrc_path,
+ "# Zsh config\nif command -v wt >/dev/null 2>&1; then eval \"$(command wt config shell init zsh)\"; fi\n",
+ )
+ .unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("uninstall")
+ .arg("--dry-run")
+ .current_dir(repo.root_path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // Verify no files were modified
+ let bash_content = fs::read_to_string(&bash_config_path).unwrap();
+ assert!(
+ bash_content.contains("wt config shell init"),
+ "Bash config should not be modified with --dry-run"
+ );
+ let zsh_content = fs::read_to_string(&zshrc_path).unwrap();
+ assert!(
+ zsh_content.contains("wt config shell init"),
+ "Zsh config should not be modified with --dry-run"
+ );
+}
+
// PTY-based tests for interactive install preview
#[cfg(all(unix, feature = "shell-integration-tests"))]
mod pty_tests {
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run.snap b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run.snap
new file mode 100644
index 000000000..58613de7e
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run.snap
@@ -0,0 +1,40 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - install
+ - zsh
+ - "--dry-run"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ 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
+ SHELL: /bin/zsh
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Will add shell extension & completions for zsh @ ~/.zshrc
+  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run_already_configured.snap b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run_already_configured.snap
new file mode 100644
index 000000000..42accad98
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run_already_configured.snap
@@ -0,0 +1,38 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - install
+ - zsh
+ - "--dry-run"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ 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
+ SHELL: /bin/zsh
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run_multiple.snap b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run_multiple.snap
new file mode 100644
index 000000000..672ff8fca
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run_multiple.snap
@@ -0,0 +1,42 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - install
+ - "--dry-run"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ 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
+ SHELL: /bin/zsh
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Will add shell extension & completions for bash @ ~/.bashrc
+  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init bash)"; fi
+
+○ Will add shell extension & completions for zsh @ ~/.zshrc
+  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run.snap b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run.snap
new file mode 100644
index 000000000..79f6a0147
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run.snap
@@ -0,0 +1,39 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - uninstall
+ - zsh
+ - "--dry-run"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ 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
+ SHELL: /bin/zsh
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Will remove shell extension & completions for zsh @ ~/.zshrc
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_fish.snap b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_fish.snap
new file mode 100644
index 000000000..b08b4ca69
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_fish.snap
@@ -0,0 +1,40 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - uninstall
+ - fish
+ - "--dry-run"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ 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
+ SHELL: /bin/fish
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Will remove shell extension for fish @ ~/.config/fish/conf.d/wt.fish
+○ Will remove completions for fish @ ~/.config/fish/completions/wt.fish
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_multiple.snap b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_multiple.snap
new file mode 100644
index 000000000..54e3cb6ae
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_multiple.snap
@@ -0,0 +1,39 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - uninstall
+ - "--dry-run"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ 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
+ SHELL: /bin/zsh
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Will remove shell extension & completions for bash @ ~/.bashrc
+○ Will remove shell extension & completions for zsh @ ~/.zshrc