Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor: Consolidate integration tests
Maximilian Roos161cb9e8f84c
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rsindex 138f6a580..dca737159 100644--- a/tests/integration_tests/completion.rs+++ b/tests/integration_tests/completion.rs@@ -681,43 +681,33 @@ fn test_complete_remove_shows_branches() {}#[test]-fn test_complete_dev_run_hook_shows_hook_types() {+fn test_complete_dev_run_hook_all_variations() {let temp = TestRepo::new();temp.commit("initial");- // Test completion for beta run-hook+ // Test 1: No input - shows all hook typeslet output = temp.completion_cmd(&["wt", "beta", "run-hook", ""]).output().unwrap();-assert!(output.status.success());let stdout = String::from_utf8_lossy(&output.stdout);let hooks = value_suggestions(&stdout);-assert!(hooks.contains(&"post-create"), "Missing post-create");assert!(hooks.contains(&"post-start"), "Missing post-start");assert!(hooks.contains(&"pre-commit"), "Missing pre-commit");assert!(hooks.contains(&"pre-merge"), "Missing pre-merge");assert!(hooks.contains(&"post-merge"), "Missing post-merge");assert_eq!(hooks.len(), 5, "Should have exactly 5 hook types");-}--#[test]-fn test_complete_dev_run_hook_with_partial_input() {- let temp = TestRepo::new();- temp.commit("initial");- // Test completion with partial input+ // Test 2: Partial input "po" - filters to post-* hookslet output = temp.completion_cmd(&["wt", "beta", "run-hook", "po"]).output().unwrap();-assert!(output.status.success());let stdout = String::from_utf8_lossy(&output.stdout);let hooks = value_suggestions(&stdout);-assert!(hooks.contains(&"post-create"));assert!(hooks.contains(&"post-start"));assert!(hooks.contains(&"post-merge"));@@ -726,94 +716,58 @@ fn test_complete_dev_run_hook_with_partial_input() {}#[test]-fn test_complete_init_shell_shows_shells() {+fn test_complete_init_shell_all_variations() {let temp = TestRepo::new();temp.commit("initial");- // Test completion for config shell init command with no input+ // Test 1: No input - shows all supported shellslet output = temp.completion_cmd(&["wt", "config", "shell", "init", ""]).output().unwrap();-assert!(output.status.success());let stdout = String::from_utf8_lossy(&output.stdout);let shells = value_suggestions(&stdout);-- // Should show supported shells (bash, fish, zsh)assert!(shells.contains(&"bash"));assert!(shells.contains(&"fish"));assert!(shells.contains(&"zsh"));assert!(!shells.contains(&"elvish"));assert!(!shells.contains(&"nushell"));- assert!(!shells.contains(&"oil"));- assert!(!shells.contains(&"powershell"));- assert!(!shells.contains(&"xonsh"));-}-#[test]-fn test_complete_init_shell_partial() {- let temp = TestRepo::new();- temp.commit("initial");-- // Test completion with partial input "fi"+ // Test 2: Partial input "fi" - filters to fishlet output = temp.completion_cmd(&["wt", "config", "shell", "init", "fi"]).output().unwrap();-assert!(output.status.success());let stdout = String::from_utf8_lossy(&output.stdout);let shells = value_suggestions(&stdout);-- // With clap fallback, we filter by prefixassert!(shells.contains(&"fish"));- // Should NOT contain shells that don't match the prefixassert!(!shells.contains(&"bash"));-}--#[test]-fn test_complete_init_shell_with_source_flag() {- let temp = TestRepo::new();- temp.commit("initial");- // Test completion with --source flag: wt --source config shell init <tab>+ // Test 3: Partial input "z" - filters to zshlet output = temp- .completion_cmd(&["wt", "--source", "config", "shell", "init", ""])+ .completion_cmd(&["wt", "config", "shell", "init", "z"]).output().unwrap();-assert!(output.status.success());let stdout = String::from_utf8_lossy(&output.stdout);let shells = value_suggestions(&stdout);-- // Should show supported shells, same as without --source- assert!(shells.contains(&"bash"));- assert!(shells.contains(&"fish"));assert!(shells.contains(&"zsh"));- assert!(!shells.contains(&"elvish"));- assert!(!shells.contains(&"nushell"));-}--#[test]-fn test_complete_init_shell_partial_z() {- let temp = TestRepo::new();- temp.commit("initial");+ assert!(!shells.contains(&"bash"));+ assert!(!shells.contains(&"fish"));- // Test completion for config shell init with partial input "z"+ // Test 4: With --source flag - same behaviorlet output = temp- .completion_cmd(&["wt", "config", "shell", "init", "z"])+ .completion_cmd(&["wt", "--source", "config", "shell", "init", ""]).output().unwrap();-assert!(output.status.success());let stdout = String::from_utf8_lossy(&output.stdout);let shells = value_suggestions(&stdout);-- // Should filter by prefix+ assert!(shells.contains(&"bash"));+ assert!(shells.contains(&"fish"));assert!(shells.contains(&"zsh"));- assert!(!shells.contains(&"bash"));- assert!(!shells.contains(&"fish"));}// test_complete_init_shell_all_with_source removed - duplicate of test_complete_init_shell_with_source_flagdiff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rsindex 178902f86..cd826177d 100644--- a/tests/integration_tests/remove.rs+++ b/tests/integration_tests/remove.rs@@ -22,11 +22,17 @@ fn snapshot_remove_with_global_flags(});}-#[test]-fn test_remove_already_on_default() {+/// Common setup for remove tests - creates repo with initial commit and remote+fn setup_remove_repo() -> TestRepo {let mut repo = TestRepo::new();repo.commit("Initial commit");repo.setup_remote("main");+ repo+}++#[test]+fn test_remove_already_on_default() {+ let repo = setup_remove_repo();// Already on main branchsnapshot_remove("remove_already_on_default", &repo, &[], None);@@ -34,9 +40,7 @@ fn test_remove_already_on_default() {#[test]fn test_remove_switch_to_default() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let repo = setup_remove_repo();// Create and switch to a feature branch in the main repolet mut cmd = Command::new("git");@@ -51,9 +55,7 @@ fn test_remove_switch_to_default() {#[test]fn test_remove_from_worktree() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();let worktree_path = repo.add_worktree("feature-wt", "feature-wt");@@ -63,9 +65,7 @@ fn test_remove_from_worktree() {#[test]fn test_remove_internal_mode() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();let worktree_path = repo.add_worktree("feature-internal", "feature-internal");@@ -80,9 +80,7 @@ fn test_remove_internal_mode() {#[test]fn test_remove_dirty_working_tree() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let repo = setup_remove_repo();// Create a dirty filestd::fs::write(repo.root_path().join("dirty.txt"), "uncommitted changes")@@ -93,9 +91,7 @@ fn test_remove_dirty_working_tree() {#[test]fn test_remove_by_name_from_main() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();// Create a worktreelet _worktree_path = repo.add_worktree("feature-a", "feature-a");@@ -106,9 +102,7 @@ fn test_remove_by_name_from_main() {#[test]fn test_remove_by_name_from_other_worktree() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();// Create two worktreeslet worktree_a = repo.add_worktree("feature-a", "feature-a");@@ -125,9 +119,7 @@ fn test_remove_by_name_from_other_worktree() {#[test]fn test_remove_current_by_name() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();let worktree_path = repo.add_worktree("feature-current", "feature-current");@@ -142,9 +134,7 @@ fn test_remove_current_by_name() {#[test]fn test_remove_nonexistent_worktree() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let repo = setup_remove_repo();// Try to remove a worktree that doesn't existsnapshot_remove("remove_nonexistent_worktree", &repo, &["nonexistent"], None);@@ -152,9 +142,7 @@ fn test_remove_nonexistent_worktree() {#[test]fn test_remove_by_name_dirty_target() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();let worktree_path = repo.add_worktree("feature-dirty", "feature-dirty");@@ -173,9 +161,7 @@ fn test_remove_by_name_dirty_target() {#[test]fn test_remove_multiple_worktrees() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();// Create three worktreeslet _worktree_a = repo.add_worktree("feature-a", "feature-a");@@ -193,9 +179,7 @@ fn test_remove_multiple_worktrees() {#[test]fn test_remove_multiple_including_current() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();// Create three worktreeslet worktree_a = repo.add_worktree("feature-a", "feature-a");@@ -213,9 +197,7 @@ fn test_remove_multiple_including_current() {#[test]fn test_remove_branch_not_fully_merged() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();// Create a worktree with an unmerged commitlet worktree_path = repo.add_worktree("feature-unmerged", "feature-unmerged");@@ -244,9 +226,7 @@ fn test_remove_branch_not_fully_merged() {#[test]fn test_remove_foreground() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();// Create a worktreelet _worktree_path = repo.add_worktree("feature-fg", "feature-fg");@@ -262,9 +242,7 @@ fn test_remove_foreground() {#[test]fn test_remove_no_delete_branch() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");+ let mut repo = setup_remove_repo();// Create a worktreelet _worktree_path = repo.add_worktree("feature-keep", "feature-keep");diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex 8123d6f04..60fb1f10d 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -2,6 +2,13 @@ use crate::common::{TestRepo, make_snapshot_cmd_with_global_flags, setup_snapshouse insta_cmd::assert_cmd_snapshot;use std::path::Path;+/// Common setup for switch tests - creates repo with initial commit+fn setup_switch_repo() -> TestRepo {+ let repo = TestRepo::new();+ repo.commit("Initial commit");+ repo+}+/// Helper to create snapshot with normalized paths and SHAsfn snapshot_switch(test_name: &str, repo: &TestRepo, args: &[&str]) {snapshot_switch_with_home(test_name, repo, args, None, &[]);@@ -37,16 +44,14 @@ fn snapshot_switch_with_home(#[test]fn test_switch_create_new_branch() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();snapshot_switch("switch_create_new", &repo, &["--create", "feature-x"]);}#[test]fn test_switch_create_existing_branch_error() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");+ let mut repo = setup_switch_repo();// Create a branch firstrepo.add_worktree("feature-y", "feature-y");@@ -63,8 +68,7 @@ fn test_switch_create_existing_branch_error() {fn test_switch_create_with_remote_branch_only() {use std::process::Command;- let mut repo = TestRepo::new();- repo.commit("Initial commit");+ let mut repo = setup_switch_repo();// Set up a remoterepo.setup_remote("main");@@ -103,8 +107,7 @@ fn test_switch_create_with_remote_branch_only() {#[test]fn test_switch_existing_branch() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");+ let mut repo = setup_switch_repo();// Create a worktree for a branchrepo.add_worktree("feature-z", "feature-z");@@ -127,8 +130,7 @@ fn test_switch_with_base_branch() {#[test]fn test_switch_base_without_create_warning() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();snapshot_switch("switch_base_without_create",@@ -139,8 +141,7 @@ fn test_switch_base_without_create_warning() {#[test]fn test_switch_internal_mode() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();snapshot_switch_with_global_flags("switch_internal_mode",@@ -152,8 +153,7 @@ fn test_switch_internal_mode() {#[test]fn test_switch_existing_worktree_internal() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");+ let mut repo = setup_switch_repo();repo.add_worktree("existing-wt", "existing-wt");@@ -167,8 +167,7 @@ fn test_switch_existing_worktree_internal() {#[test]fn test_switch_internal_with_execute() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();let execute_cmd = "echo 'line1'\necho 'line2'";@@ -182,8 +181,7 @@ fn test_switch_internal_with_execute() {#[test]fn test_switch_error_missing_worktree_directory() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");+ let mut repo = setup_switch_repo();// Create a worktreelet wt_path = repo.add_worktree("missing-wt", "missing-wt");@@ -197,8 +195,7 @@ fn test_switch_error_missing_worktree_directory() {#[test]fn test_switch_execute_success() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();snapshot_switch("switch_execute_success",@@ -209,8 +206,7 @@ fn test_switch_execute_success() {#[test]fn test_switch_execute_creates_file() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();let create_file_cmd = "echo 'test content' > test.txt";@@ -223,8 +219,7 @@ fn test_switch_execute_creates_file() {#[test]fn test_switch_execute_failure() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();snapshot_switch("switch_execute_failure",@@ -235,8 +230,7 @@ fn test_switch_execute_failure() {#[test]fn test_switch_execute_with_existing_worktree() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");+ let mut repo = setup_switch_repo();// Create a worktree firstrepo.add_worktree("existing-exec", "existing-exec");@@ -252,8 +246,7 @@ fn test_switch_execute_with_existing_worktree() {#[test]fn test_switch_execute_multiline() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();let multiline_cmd = "echo 'line1'\necho 'line2'\necho 'line3'";@@ -266,8 +259,7 @@ fn test_switch_execute_multiline() {#[test]fn test_switch_no_config_commands_execute_still_runs() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();snapshot_switch("switch_no_hooks_execute_still_runs",@@ -288,8 +280,7 @@ fn test_switch_no_config_commands_skips_post_start_commands() {use tempfile::TempDir;let temp_home = TempDir::new().unwrap();- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();// Create project config with a command that would create a filelet config_dir = repo.root_path().join(".config");@@ -333,8 +324,7 @@ approved-commands = ["{}"]#[test]fn test_switch_no_config_commands_with_existing_worktree() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");+ let mut repo = setup_switch_repo();// Create a worktree firstrepo.add_worktree("existing-no-hooks", "existing-no-hooks");@@ -358,8 +348,7 @@ fn test_switch_no_config_commands_with_force() {use tempfile::TempDir;let temp_home = TempDir::new().unwrap();- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();// Create project config with a commandlet config_dir = repo.root_path().join(".config");@@ -384,8 +373,7 @@ fn test_switch_no_config_commands_with_force() {#[test]fn test_switch_create_no_remote() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();// Deliberately NOT calling setup_remote to test local branch inference// Create a branch without specifying base - should infer default branch locally@@ -394,8 +382,7 @@ fn test_switch_create_no_remote() {#[test]fn test_switch_primary_on_different_branch() {- let mut repo = TestRepo::new();- repo.commit("Initial commit");+ let mut repo = setup_switch_repo();repo.setup_remote("main");repo.switch_primary_to("develop");@@ -422,8 +409,7 @@ fn test_switch_primary_on_different_branch() {fn test_switch_previous_branch() {use std::process::Command;- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();// Create two brancheslet mut cmd = Command::new("git");@@ -450,8 +436,7 @@ fn test_switch_previous_branch() {#[test]fn test_switch_previous_branch_no_history() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();// No checkout history, so wt switch - should fail with helpful errorsnapshot_switch("switch_previous_branch_no_history", &repo, &["-"]);@@ -461,8 +446,7 @@ fn test_switch_previous_branch_no_history() {fn test_switch_previous_branch_with_worktrunk_history() {use std::process::Command;- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();// Create two brancheslet mut cmd = Command::new("git");@@ -505,8 +489,7 @@ fn test_switch_previous_branch_with_worktrunk_history() {fn test_switch_main_branch() {use std::process::Command;- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();// Create a feature branchlet mut cmd = Command::new("git");@@ -525,8 +508,7 @@ fn test_switch_main_branch() {#[test]fn test_create_with_base_main() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();// Create new branch from main using ^snapshot_switch(@@ -538,8 +520,7 @@ fn test_create_with_base_main() {#[test]fn test_switch_default_branch_missing_worktree() {- let repo = TestRepo::new();- repo.commit("Initial commit");+ let repo = setup_switch_repo();// Move the primary worktree off the default branch so no worktree holds itrepo.switch_primary_to("develop");