Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor tests to use rstest fixture for TestRepo
Maximilian Roosebc1d0154d5f
diff --git a/tests/integration_tests/approval_ui.rs b/tests/integration_tests/approval_ui.rsindex 3ae1b920f..8bf03f608 100644--- a/tests/integration_tests/approval_ui.rs+++ b/tests/integration_tests/approval_ui.rs@@ -1,7 +1,8 @@//! Tests for command approval UI-use crate::common::{TestRepo, make_snapshot_cmd, setup_snapshot_settings};+use crate::common::{TestRepo, make_snapshot_cmd, repo, setup_snapshot_settings};use insta_cmd::assert_cmd_snapshot;+use rstest::rstest;use std::fs;use std::io::Write;use std::process::{Command, Stdio};@@ -40,10 +41,8 @@ fn snapshot_approval(test_name: &str, repo: &TestRepo, args: &[&str], approve: b});}-#[test]-fn test_approval_single_command() {- let repo = TestRepo::new();-+#[rstest]+fn test_approval_single_command(repo: TestRepo) {repo.write_project_config(r#"post-create = "echo 'Worktree path: {{ worktree }}'""#);repo.commit("Add config");@@ -56,10 +55,8 @@ fn test_approval_single_command() {);}-#[test]-fn test_approval_multiple_commands() {- let repo = TestRepo::new();-+#[rstest]+fn test_approval_multiple_commands(repo: TestRepo) {repo.write_project_config(r#"[post-create]branch = "echo 'Branch: {{ branch }}'"@@ -79,10 +76,8 @@ pwd = "cd {{ worktree }} && pwd");}-#[test]-fn test_approval_mixed_approved_unapproved() {- let repo = TestRepo::new();-+#[rstest]+fn test_approval_mixed_approved_unapproved(repo: TestRepo) {repo.write_project_config(r#"[post-create]first = "echo 'First command'"@@ -111,11 +106,9 @@ approved-commands = ["echo 'Second command'"]}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_force_flag_does_not_save_approvals() {- let repo = TestRepo::new();-+fn test_force_flag_does_not_save_approvals(repo: TestRepo) {repo.write_project_config(r#"post-create = "echo 'test command' > output.txt""#);repo.commit("Add config");@@ -151,11 +144,9 @@ fn test_force_flag_does_not_save_approvals() {}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_already_approved_commands_skip_prompt() {- let repo = TestRepo::new();-+fn test_already_approved_commands_skip_prompt(repo: TestRepo) {repo.write_project_config(r#"post-create = "echo 'approved' > output.txt""#);repo.commit("Add config");@@ -177,10 +168,8 @@ approved-commands = ["echo 'approved' > output.txt"]});}-#[test]-fn test_decline_approval_skips_only_unapproved() {- let repo = TestRepo::new();-+#[rstest]+fn test_decline_approval_skips_only_unapproved(repo: TestRepo) {repo.write_project_config(r#"[post-create]first = "echo 'First command'"@@ -212,10 +201,8 @@ approved-commands = ["echo 'Second command'"]);}-#[test]-fn test_approval_named_commands() {- let repo = TestRepo::new();-+#[rstest]+fn test_approval_named_commands(repo: TestRepo) {repo.write_project_config(r#"[post-create]install = "echo 'Installing dependencies...'"@@ -272,10 +259,8 @@ fn snapshot_run_hook(test_name: &str, repo: &TestRepo, hook_type: &str, approve:////// This verifies the fix for the security issue where hooks were bypassing approval./// Before the fix, pre-merge hooks ran with auto_trust=true, skipping approval prompts.-#[test]-fn test_run_hook_pre_merge_requires_approval() {- let repo = TestRepo::new();-+#[rstest]+fn test_run_hook_pre_merge_requires_approval(repo: TestRepo) {repo.write_project_config(r#"pre-merge = "echo 'Running pre-merge checks on {{ branch }}'""#);repo.commit("Add pre-merge hook");@@ -293,10 +278,8 @@ fn test_run_hook_pre_merge_requires_approval() {////// This verifies the fix for the security issue where hooks were bypassing approval./// Before the fix, post-merge hooks ran with auto_trust=true, skipping approval prompts.-#[test]-fn test_run_hook_post_merge_requires_approval() {- let repo = TestRepo::new();-+#[rstest]+fn test_run_hook_post_merge_requires_approval(repo: TestRepo) {repo.write_project_config(r#"post-merge = "echo 'Post-merge cleanup for {{ branch }}'""#);repo.commit("Add post-merge hook");@@ -314,10 +297,8 @@ fn test_run_hook_post_merge_requires_approval() {////// When stdin is not a TTY (e.g., CI/CD, piped input), approval prompts cannot be shown./// The command should fail with a clear error telling users to use --force.-#[test]-fn test_approval_fails_in_non_tty() {- let repo = TestRepo::new();-+#[rstest]+fn test_approval_fails_in_non_tty(repo: TestRepo) {repo.write_project_config(r#"post-create = "echo 'test command'""#);repo.commit("Add config");@@ -334,11 +315,9 @@ fn test_approval_fails_in_non_tty() {////// Even in non-TTY environments, --force should allow commands to execute./// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_force_bypasses_tty_check() {- let repo = TestRepo::new();-+fn test_force_bypasses_tty_check(repo: TestRepo) {repo.write_project_config(r#"post-create = "echo 'test command'""#);repo.commit("Add config");@@ -361,11 +340,9 @@ fn test_force_bypasses_tty_check() {/// variable should be the current branch, not always the default branch./// This allows hooks to behave correctly when testing from feature worktrees./// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_hook_post_merge_target_is_current_branch() {- let repo = TestRepo::new();-+fn test_hook_post_merge_target_is_current_branch(repo: TestRepo) {// Hook that writes {{ target }} to a file so we can verify its valuerepo.write_project_config(r#"post-merge = "echo '{{ target }}' > target-branch.txt""#);repo.commit("Add post-merge hook");@@ -402,11 +379,9 @@ fn test_hook_post_merge_target_is_current_branch() {/// Test that `{{ target }}` is the current branch for pre-merge standalone/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_hook_pre_merge_target_is_current_branch() {- let repo = TestRepo::new();-+fn test_hook_pre_merge_target_is_current_branch(repo: TestRepo) {// Hook that writes {{ target }} to a file so we can verify its valuerepo.write_project_config(r#"pre-merge = "echo '{{ target }}' > target-branch.txt""#);repo.commit("Add pre-merge hook");@@ -443,11 +418,9 @@ fn test_hook_pre_merge_target_is_current_branch() {/// Test running a specific named hook command/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_step_hook_run_named_command() {- let repo = TestRepo::new();-+fn test_step_hook_run_named_command(repo: TestRepo) {// Config with multiple named commandsrepo.write_project_config(r#"[pre-merge]@@ -488,10 +461,8 @@ build = "echo 'running build' > build.txt"}/// Test error message when named hook command doesn't exist-#[test]-fn test_step_hook_unknown_name_error() {- let repo = TestRepo::new();-+#[rstest]+fn test_step_hook_unknown_name_error(repo: TestRepo) {// Config with multiple named commandsrepo.write_project_config(r#"[pre-merge]@@ -515,10 +486,8 @@ lint = "echo 'lint'"}/// Test error message when hook has no named commands-#[test]-fn test_step_hook_name_filter_on_unnamed_command() {- let repo = TestRepo::new();-+#[rstest]+fn test_step_hook_name_filter_on_unnamed_command(repo: TestRepo) {// Config with a single unnamed command (no table)repo.write_project_config(r#"pre-merge = "echo 'test'""#);repo.commit("Add pre-merge hook");@@ -533,11 +502,9 @@ fn test_step_hook_name_filter_on_unnamed_command() {/// Test running all hooks (no name filter) still works/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_step_hook_run_all_commands() {- let repo = TestRepo::new();-+fn test_step_hook_run_all_commands(repo: TestRepo) {// Config with multiple named commandsrepo.write_project_config(r#"[pre-merge]diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rsindex 69fa13352..fc9de7cdb 100644--- a/tests/integration_tests/configure_shell.rs+++ b/tests/integration_tests/configure_shell.rs@@ -1,12 +1,12 @@-use crate::common::{TestRepo, set_temp_home_env, setup_home_snapshot_settings, wt_command};+use crate::common::{TestRepo, repo, set_temp_home_env, setup_home_snapshot_settings, wt_command};use insta_cmd::assert_cmd_snapshot;+use rstest::rstest;use std::fs;use tempfile::TempDir;/// Test `wt config shell install` with --force flag (skips confirmation)-#[test]-fn test_configure_shell_with_yes() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_with_yes(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create a fake .zshrc file@@ -50,9 +50,8 @@ fn test_configure_shell_with_yes() {}/// Test `wt config shell install` with specific shell-#[test]-fn test_configure_shell_specific_shell() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_specific_shell(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create a fake .zshrc file@@ -95,9 +94,8 @@ fn test_configure_shell_specific_shell() {}/// Test `wt config shell install` when line already exists-#[test]-fn test_configure_shell_already_exists() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_already_exists(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create a fake .zshrc file with the line already present@@ -139,9 +137,8 @@ fn test_configure_shell_already_exists() {}/// Test `wt config shell install` for Fish (creates new file in conf.d/)-#[test]-fn test_configure_shell_fish() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_fish(repo: TestRepo) {let temp_home = TempDir::new().unwrap();let settings = setup_home_snapshot_settings(&temp_home);@@ -185,9 +182,8 @@ fn test_configure_shell_fish() {/// Test `wt config shell install` when fish extension already exists/// Fish completions are now inline in the init script, so no separate file is needed-#[test]-fn test_configure_shell_fish_extension_exists() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_fish_extension_exists(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create fish conf.d directory with wt.fish (extension exists)@@ -242,9 +238,8 @@ fn test_configure_shell_fish_extension_exists() {}/// Test `wt config shell install` when no config files exist-#[test]-fn test_configure_shell_no_files() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_no_files(repo: TestRepo) {let temp_home = TempDir::new().unwrap();let settings = setup_home_snapshot_settings(&temp_home);@@ -274,9 +269,8 @@ fn test_configure_shell_no_files() {}/// Test `wt config shell install` with multiple existing config files-#[test]-fn test_configure_shell_multiple_configs() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_multiple_configs(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create multiple shell config files@@ -331,9 +325,8 @@ fn test_configure_shell_multiple_configs() {}/// Test `wt config shell install` shows both shells needing updates and already configured shells-#[test]-fn test_configure_shell_mixed_states() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_mixed_states(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create bash config with wt already configured@@ -396,9 +389,8 @@ fn test_configure_shell_mixed_states() {}/// Test `wt config shell uninstall` removes shell integration-#[test]-fn test_uninstall_shell() {- let repo = TestRepo::new();+#[rstest]+fn test_uninstall_shell(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create a fake .zshrc file with wt integration@@ -450,9 +442,8 @@ fn test_uninstall_shell() {}/// Test `wt config shell uninstall` with multiple shells-#[test]-fn test_uninstall_shell_multiple() {- let repo = TestRepo::new();+#[rstest]+fn test_uninstall_shell_multiple(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create multiple shell configs with wt integration@@ -512,9 +503,8 @@ fn test_uninstall_shell_multiple() {}/// Test `wt config shell uninstall` when not installed-#[test]-fn test_uninstall_shell_not_found() {- let repo = TestRepo::new();+#[rstest]+fn test_uninstall_shell_not_found(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create a fake .zshrc file without wt integration@@ -546,9 +536,8 @@ fn test_uninstall_shell_not_found() {}/// Test `wt config shell uninstall` for Fish (deletes file)-#[test]-fn test_uninstall_shell_fish() {- let repo = TestRepo::new();+#[rstest]+fn test_uninstall_shell_fish(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create fish conf.d directory with wt.fish@@ -592,9 +581,8 @@ fn test_uninstall_shell_fish() {}/// Test install and then uninstall roundtrip-#[test]-fn test_install_uninstall_roundtrip() {- let repo = TestRepo::new();+#[rstest]+fn test_install_uninstall_roundtrip(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create initial config file@@ -660,9 +648,8 @@ fn test_install_uninstall_roundtrip() {}/// Test that compinit warning does NOT show when .zshrc has compinit enabled-#[test]-fn test_configure_shell_no_warning_when_compinit_enabled() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_no_warning_when_compinit_enabled(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create a .zshrc that enables compinit - detection should find it@@ -704,9 +691,8 @@ fn test_configure_shell_no_warning_when_compinit_enabled() {/// Test that compinit warning does NOT show when $SHELL is bash (not a zsh user)/// Even when installing all shells, we don't warn bash users about zsh compinit-#[test]-fn test_configure_shell_no_warning_for_bash_user() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_no_warning_for_bash_user(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create config files for both shells (no compinit in zshrc)@@ -746,9 +732,8 @@ fn test_configure_shell_no_warning_for_bash_user() {/// Test that compinit warning does NOT show when installing fish (even if SHELL=zsh)/// Only `install zsh` or `install` (all) should trigger zsh-specific warnings-#[test]-fn test_configure_shell_no_warning_for_fish_install() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_no_warning_for_fish_install(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create fish conf.d directory@@ -784,9 +769,8 @@ fn test_configure_shell_no_warning_for_fish_install() {}/// Test that compinit warning does NOT show when zsh is already configured-#[test]-fn test_configure_shell_no_warning_when_already_configured() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_no_warning_when_already_configured(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create a .zshrc that ALREADY has wt integration (no compinit)@@ -824,9 +808,8 @@ fn test_configure_shell_no_warning_when_already_configured() {}/// Test that compinit warning does NOT show when $SHELL is unset-#[test]-fn test_configure_shell_no_warning_when_shell_unset() {- let repo = TestRepo::new();+#[rstest]+fn test_configure_shell_no_warning_when_shell_unset(repo: TestRepo) {let temp_home = TempDir::new().unwrap();// Create zsh and bash config files (no compinit)diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rsindex 5d6fe6ea8..341a3f2f0 100644--- a/tests/integration_tests/post_start_commands.rs+++ b/tests/integration_tests/post_start_commands.rs@@ -1,9 +1,11 @@use crate::common::{- TestRepo, make_snapshot_cmd, resolve_git_common_dir, setup_snapshot_settings, wait_for_file,- wait_for_file_content, wait_for_file_count, wait_for_file_lines, wait_for_valid_json,+ TestRepo, make_snapshot_cmd, repo, resolve_git_common_dir, setup_snapshot_settings,+ wait_for_file, wait_for_file_content, wait_for_file_count, wait_for_file_lines,+ wait_for_valid_json,};use insta::assert_snapshot;use insta_cmd::assert_cmd_snapshot;+use rstest::rstest;use std::fs;use std::thread;use std::time::Duration;@@ -36,20 +38,16 @@ fn snapshot_switch(test_name: &str, repo: &TestRepo, args: &[&str]) {// Post-Create Command Tests (sequential, blocking)// ============================================================================-#[test]-fn test_post_create_no_config() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_create_no_config(repo: TestRepo) {// Switch without project config should work normallysnapshot_switch("post_create_no_config", &repo, &["--create", "feature"]);}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_post_create_single_command() {- let repo = TestRepo::new();-+fn test_post_create_single_command(repo: TestRepo) {// Create project config with a single command (string format)repo.write_project_config(r#"post-create = "echo 'Setup complete'""#);@@ -73,11 +71,9 @@ approved-commands = ["echo 'Setup complete'"]}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_post_create_named_commands() {- let repo = TestRepo::new();-+fn test_post_create_named_commands(repo: TestRepo) {// Create project config with named commands (table format)repo.write_project_config(r#"[post-create]@@ -109,11 +105,9 @@ approved-commands = [}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_post_create_failing_command() {- let repo = TestRepo::new();-+fn test_post_create_failing_command(repo: TestRepo) {// Create project config with a command that will failrepo.write_project_config(r#"post-create = "exit 1""#);@@ -138,10 +132,8 @@ approved-commands = ["exit 1"]/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_create_template_expansion() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_create_template_expansion(repo: TestRepo) {// Create project config with template variablesrepo.write_project_config(r#"[post-create]@@ -206,10 +198,8 @@ approved-commands = [/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_create_default_branch_template() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_create_default_branch_template(repo: TestRepo) {// Create project config with default_branch template variablerepo.write_project_config(r#"post-create = "echo 'Default: {{ default_branch }}' > default.txt""#,@@ -252,9 +242,8 @@ approved-commands = ["echo 'Default: {{ default_branch }}' > default.txt"]/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_create_git_variables_template() {- let mut repo = TestRepo::new();+#[rstest]+fn test_post_create_git_variables_template(mut repo: TestRepo) {repo.setup_remote("main");// Set up an upstream tracking branch@@ -329,9 +318,8 @@ worktree_name = "echo 'Worktree Name: {{ worktree_name }}' >> git_vars.txt"/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_create_upstream_template() {- let mut repo = TestRepo::new();+#[rstest]+fn test_post_create_upstream_template(mut repo: TestRepo) {repo.setup_remote("main");// Push main to set up tracking@@ -372,13 +360,11 @@ fn test_post_create_upstream_template() {/// Test that hooks receive JSON context on stdin/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_post_create_json_stdin() {+fn test_post_create_json_stdin(repo: TestRepo) {use crate::common::wt_command;- let repo = TestRepo::new();-// Create project config with a command that reads JSON from stdin// Use cat to capture stdin to a filerepo.write_project_config(r#"post-create = "cat > context.json""#);@@ -456,14 +442,12 @@ approved-commands = ["cat > context.json"]}/// Test that an actual script file can read JSON from stdin-#[test]+#[rstest]#[cfg(unix)]-fn test_post_create_script_reads_json() {+fn test_post_create_script_reads_json(repo: TestRepo) {use crate::common::wt_command;use std::os::unix::fs::PermissionsExt;- let repo = TestRepo::new();-// Create a scripts directory and a Python script that reads JSON from stdinlet scripts_dir = repo.root_path().join("scripts");fs::create_dir_all(&scripts_dir).unwrap();@@ -558,13 +542,11 @@ approved-commands = ["./scripts/setup.py"]/// Test that background hooks also receive JSON context on stdin////// Skipped on Windows: Uses `cat` command which is not available natively on Windows.-#[test]+#[rstest]#[cfg_attr(windows, ignore)]-fn test_post_start_json_stdin() {+fn test_post_start_json_stdin(repo: TestRepo) {use crate::common::wt_command;- let repo = TestRepo::new();-// Create project config with a background command that reads JSON from stdinrepo.write_project_config(r#"post-start = "cat > context.json""#);@@ -624,10 +606,8 @@ approved-commands = ["cat > context.json"]/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_start_single_background_command() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_start_single_background_command(repo: TestRepo) {// Create project config with a background commandrepo.write_project_config(r#"post-start = "sleep 0.1 && echo 'Background task done' > background.txt""#,@@ -664,10 +644,8 @@ approved-commands = ["sleep 0.1 && echo 'Background task done' > background.txt"/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_start_multiple_background_commands() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_start_multiple_background_commands(repo: TestRepo) {// Create project config with multiple background commands (table format)repo.write_project_config(r#"[post-start]@@ -711,10 +689,8 @@ approved-commands = [/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_both_post_create_and_post_start() {- let repo = TestRepo::new();-+#[rstest]+fn test_both_post_create_and_post_start(repo: TestRepo) {// Create project config with both command typesrepo.write_project_config(r#"post-create = "echo 'Setup done' > setup.txt"@@ -755,10 +731,8 @@ approved-commands = [);}-#[test]-fn test_invalid_toml() {- let repo = TestRepo::new();-+#[rstest]+fn test_invalid_toml(repo: TestRepo) {// Create invalid TOMLrepo.write_project_config("post-create = [invalid syntax\n");@@ -774,10 +748,8 @@ fn test_invalid_toml() {/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_start_log_file_captures_output() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_start_log_file_captures_output(repo: TestRepo) {// Create command that writes to both stdout and stderrrepo.write_project_config(r#"post-start = "echo 'stdout output' && echo 'stderr output' >&2""#);@@ -832,10 +804,8 @@ approved-commands = ["echo 'stdout output' && echo 'stderr output' >&2"]");}-#[test]-fn test_post_start_invalid_command_handling() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_start_invalid_command_handling(repo: TestRepo) {// Create command with syntax error (missing quote)repo.write_project_config(r#"post-start = "echo 'unclosed quote""#);@@ -867,10 +837,8 @@ approved-commands = ["echo 'unclosed quote"]/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_start_multiple_commands_separate_logs() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_start_multiple_commands_separate_logs(repo: TestRepo) {// Create multiple background commands with distinct outputrepo.write_project_config(r#"[post-start]@@ -952,10 +920,8 @@ approved-commands = [/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_execute_flag_with_post_start_commands() {- let repo = TestRepo::new();-+#[rstest]+fn test_execute_flag_with_post_start_commands(repo: TestRepo) {// Create post-start commandrepo.write_project_config(r#"post-start = "echo 'Background task' > background.txt""#);@@ -999,10 +965,8 @@ approved-commands = ["echo 'Background task' > background.txt"]/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_start_complex_shell_commands() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_start_complex_shell_commands(repo: TestRepo) {// Create command with pipes and redirectsrepo.write_project_config(r#"post-start = "echo 'line1\nline2\nline3' | grep line2 > filtered.txt""#,@@ -1032,10 +996,8 @@ approved-commands = ["echo 'line1\nline2\nline3' | grep line2 > filtered.txt"]/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_start_multiline_commands_with_newlines() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_start_multiline_commands_with_newlines(repo: TestRepo) {// Create command with actual newlines (using TOML triple-quoted string)repo.write_project_config(r#"post-start = """@@ -1084,10 +1046,8 @@ approved-commands = ["""/// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_create_multiline_with_control_structures() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_create_multiline_with_control_structures(repo: TestRepo) {// Test multiline command with if-else control structurerepo.write_project_config(r#"post-create = """@@ -1147,10 +1107,8 @@ approved-commands = ["""/// `wt switch` operations instead of only on `wt switch --create`./// Skipped on Windows: snapshot output differs due to shell/path differences.#[cfg_attr(windows, ignore)]-#[test]-fn test_post_start_skipped_on_existing_worktree() {- let repo = TestRepo::new();-+#[rstest]+fn test_post_start_skipped_on_existing_worktree(repo: TestRepo) {// Create project config with post-start commandrepo.write_project_config(r#"post-start = "echo 'POST-START-RAN' > post_start_marker.txt""#);diff --git a/tests/integration_tests/user_hooks.rs b/tests/integration_tests/user_hooks.rsindex e204f84c8..0c035fc02 100644--- a/tests/integration_tests/user_hooks.rs+++ b/tests/integration_tests/user_hooks.rs@@ -7,9 +7,11 @@//! - Skipped together with project hooks via --no-verifyuse crate::common::{- TestRepo, make_snapshot_cmd, setup_snapshot_settings, wait_for_file, wait_for_file_content,+ TestRepo, make_snapshot_cmd, repo, setup_snapshot_settings, wait_for_file,+ wait_for_file_content,};use insta_cmd::assert_cmd_snapshot;+use rstest::rstest;use std::fs;use std::process::Command;use std::thread;@@ -32,11 +34,9 @@ fn snapshot_switch(test_name: &str, repo: &TestRepo, args: &[&str]) {}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_post_create_hook_executes() {- let repo = TestRepo::new();-+fn test_user_post_create_hook_executes(repo: TestRepo) {// Write user config with post-create hook (no project config)repo.write_test_config(r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"@@ -64,11 +64,9 @@ log = "echo 'USER_POST_CREATE_RAN' > user_hook_marker.txt"}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_hooks_run_before_project_hooks() {- let repo = TestRepo::new();-+fn test_user_hooks_run_before_project_hooks(repo: TestRepo) {// Create project config with post-create hookrepo.write_project_config(r#"post-create = "echo 'PROJECT_HOOK' >> hook_order.txt""#);repo.commit("Add project config");@@ -101,11 +99,9 @@ approved-commands = ["echo 'PROJECT_HOOK' >> hook_order.txt"]}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_hooks_no_approval_required() {- let repo = TestRepo::new();-+fn test_user_hooks_no_approval_required(repo: TestRepo) {// Write user config with hook but NO pre-approved commands// (unlike project hooks, user hooks don't require approval)repo.write_test_config(@@ -127,10 +123,8 @@ setup = "echo 'NO_APPROVAL_NEEDED' > no_approval.txt");}-#[test]-fn test_no_verify_flag_skips_all_hooks() {- let repo = TestRepo::new();-+#[rstest]+fn test_no_verify_flag_skips_all_hooks(repo: TestRepo) {// Create project config with post-create hookrepo.write_project_config(r#"post-create = "echo 'PROJECT_HOOK' > project_marker.txt""#);repo.commit("Add project config");@@ -172,11 +166,9 @@ approved-commands = ["echo 'PROJECT_HOOK' > project_marker.txt"]}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_post_create_hook_failure() {- let repo = TestRepo::new();-+fn test_user_post_create_hook_failure(repo: TestRepo) {// Write user config with failing hookrepo.write_test_config(r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"@@ -202,11 +194,9 @@ failing = "exit 1"// ============================================================================/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_post_start_hook_executes() {- let repo = TestRepo::new();-+fn test_user_post_start_hook_executes(repo: TestRepo) {// Write user config with post-start hook (background)repo.write_test_config(r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"@@ -230,10 +220,8 @@ bg = "echo 'USER_POST_START_RAN' > user_bg_marker.txt");}-#[test]-fn test_user_post_start_skipped_with_no_verify() {- let repo = TestRepo::new();-+#[rstest]+fn test_user_post_start_skipped_with_no_verify(repo: TestRepo) {// Write user config with post-start hookrepo.write_test_config(r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"@@ -274,11 +262,9 @@ fn snapshot_merge(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<&}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_pre_merge_hook_executes() {- let mut repo = TestRepo::new();-+fn test_user_pre_merge_hook_executes(mut repo: TestRepo) {// Create feature worktree with a commitlet feature_wt = repo.add_worktree("feature");fs::write(feature_wt.join("feature.txt"), "feature content").unwrap();@@ -319,11 +305,9 @@ check = "echo 'USER_PRE_MERGE_RAN' > user_premerge.txt"}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_pre_merge_hook_failure_blocks_merge() {- let mut repo = TestRepo::new();-+fn test_user_pre_merge_hook_failure_blocks_merge(mut repo: TestRepo) {// Create feature worktree with a commitlet feature_wt = repo.add_worktree("feature");fs::write(feature_wt.join("feature.txt"), "feature content").unwrap();@@ -360,10 +344,8 @@ check = "exit 1");}-#[test]-fn test_user_pre_merge_skipped_with_no_verify() {- let mut repo = TestRepo::new();-+#[rstest]+fn test_user_pre_merge_skipped_with_no_verify(mut repo: TestRepo) {// Create feature worktree with a commitlet feature_wt = repo.add_worktree("feature");fs::write(feature_wt.join("feature.txt"), "feature content").unwrap();@@ -406,15 +388,13 @@ check = "echo 'USER_PRE_MERGE' > user_premerge_marker.txt");}-#[test]+#[rstest]#[cfg(unix)]-fn test_pre_merge_hook_receives_sigint() {+fn test_pre_merge_hook_receives_sigint(repo: TestRepo) {use nix::sys::signal::{Signal, kill};use nix::unistd::Pid;use std::io::Read;use std::process::Stdio;-- let repo = TestRepo::new();repo.commit("Initial commit");// Project pre-merge hook: write start, then sleep, then write done (if not interrupted)@@ -469,11 +449,9 @@ long = "sh -c 'echo start >> hook.log; sleep 30; echo done >> hook.log'"// ============================================================================/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_post_merge_hook_executes() {- let mut repo = TestRepo::new();-+fn test_user_post_merge_hook_executes(mut repo: TestRepo) {// Create feature worktree with a commitlet feature_wt = repo.add_worktree("feature");fs::write(feature_wt.join("feature.txt"), "feature content").unwrap();@@ -531,11 +509,9 @@ fn snapshot_remove(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<}/// Skipped on Windows: Uses /tmp path and file locking prevents worktree removal.-#[test]+#[rstest]#[cfg_attr(windows, ignore)]-fn test_user_pre_remove_hook_executes() {- let mut repo = TestRepo::new();-+fn test_user_pre_remove_hook_executes(mut repo: TestRepo) {// Create a worktree to removelet _feature_wt = repo.add_worktree("feature");@@ -563,11 +539,9 @@ cleanup = "echo 'USER_PRE_REMOVE_RAN' > /tmp/user_preremove_marker.txt"}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_pre_remove_failure_blocks_removal() {- let mut repo = TestRepo::new();-+fn test_user_pre_remove_failure_blocks_removal(mut repo: TestRepo) {// Create a worktree to removelet feature_wt = repo.add_worktree("feature");@@ -595,11 +569,9 @@ block = "exit 1"}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_pre_remove_skipped_with_no_verify() {- let mut repo = TestRepo::new();-+fn test_user_pre_remove_skipped_with_no_verify(mut repo: TestRepo) {// Create a worktree to removelet feature_wt = repo.add_worktree("feature");@@ -639,11 +611,9 @@ block = "exit 1"// ============================================================================/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_pre_commit_hook_executes() {- let mut repo = TestRepo::new();-+fn test_user_pre_commit_hook_executes(mut repo: TestRepo) {// Create feature worktreelet feature_wt = repo.add_worktree("feature");@@ -672,11 +642,9 @@ lint = "echo 'USER_PRE_COMMIT_RAN' > user_precommit.txt"}/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_pre_commit_failure_blocks_commit() {- let mut repo = TestRepo::new();-+fn test_user_pre_commit_failure_blocks_commit(mut repo: TestRepo) {// Create feature worktreelet feature_wt = repo.add_worktree("feature");@@ -706,11 +674,9 @@ lint = "exit 1"// ============================================================================/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_hook_template_variables() {- let repo = TestRepo::new();-+fn test_user_hook_template_variables(repo: TestRepo) {// Write user config with hook using template variablesrepo.write_test_config(r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"@@ -745,11 +711,9 @@ vars = "echo 'repo={{ repo }} branch={{ branch }}' > template_vars.txt"// ============================================================================/// Skipped on Windows: snapshot output differs due to shell/path differences.+#[rstest]#[cfg_attr(windows, ignore)]-#[test]-fn test_user_and_project_post_start_both_run() {- let repo = TestRepo::new();-+fn test_user_and_project_post_start_both_run(repo: TestRepo) {// Create project config with post-start hookrepo.write_project_config(r#"post-start = "echo 'PROJECT_POST_START' > project_bg.txt""#);repo.commit("Add project config");