Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
test: add coverage for path_mismatch_warning edge cases (#380)
Maximilian Roos4b4c31de2fcb
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex abc20fd84..c9778ab82 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -456,6 +456,63 @@ fn test_switch_path_mismatch_shows_hint(repo: TestRepo) {snapshot_switch_with_directive_file("switch_path_mismatch_shows_hint", &repo, &["feature"]);}+/// Test path mismatch warning without shell integration.+///+/// When shell integration is not active, the path mismatch warning should appear+/// alongside the "cannot change directory" warning.+#[rstest]+fn test_switch_path_mismatch_without_shell_integration(repo: TestRepo) {+ // Create a worktree at a non-standard path+ let wrong_path = repo+ .root_path()+ .parent()+ .unwrap()+ .join("wrong-path-no-shell");+ repo.run_git(&[+ "worktree",+ "add",+ wrong_path.to_str().unwrap(),+ "-b",+ "feature-mismatch",+ ]);++ // Switch without directive file (no shell integration) - should show both warnings+ snapshot_switch(+ "switch_path_mismatch_no_shell",+ &repo,+ &["feature-mismatch"],+ );+}++/// Test AlreadyAt with path mismatch.+///+/// When already in a worktree whose path doesn't match the branch name,+/// switching to that branch should show the path mismatch warning.+#[rstest]+fn test_switch_already_at_with_path_mismatch(repo: TestRepo) {+ // Create a worktree at a non-standard path+ let wrong_path = repo+ .root_path()+ .parent()+ .unwrap()+ .join("wrong-path-already");+ repo.run_git(&[+ "worktree",+ "add",+ wrong_path.to_str().unwrap(),+ "-b",+ "feature-already",+ ]);++ // Switch from within the worktree with mismatched path (AlreadyAt case)+ snapshot_switch_from_dir(+ "switch_already_at_path_mismatch",+ &repo,+ &["feature-already"],+ &wrong_path,+ );+}+/// Test that switching to a branch errors when path is occupied by worktree on different branch////// With branch-first lookup, if a worktree was created for "feature" but then switched todiff --git a/tests/snapshots/integration__integration_tests__switch__switch_already_at_path_mismatch.snap b/tests/snapshots/integration__integration_tests__switch__switch_already_at_path_mismatch.snapnew file mode 100644index 000000000..d23d88367--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_already_at_path_mismatch.snap@@ -0,0 +1,36 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - feature-already+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "150"+ 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+ SOURCE_DATE_EPOCH: "1735776000"+ 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 -----+[2m○[22m Already on worktree for [1mfeature-already[22m @ [1m[PROJECT_ID][22m+[33m▲[39m [33mWorktree path doesn't match branch name; expected [1m_REPO_.feature-already[22m [31m⚑[39m[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_path_mismatch_no_shell.snap b/tests/snapshots/integration__integration_tests__switch__switch_path_mismatch_no_shell.snapnew file mode 100644index 000000000..236a6c34c--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_path_mismatch_no_shell.snap@@ -0,0 +1,36 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - feature-mismatch+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "150"+ 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+ SOURCE_DATE_EPOCH: "1735776000"+ 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 -----+[33m▲[39m [33mWorktree for [1mfeature-mismatch[22m @ [1m[PROJECT_ID][22m, but cannot change directory — shell integration not installed[39m+[33m▲[39m [33mWorktree path doesn't match branch name; expected [1m_REPO_.feature-mismatch[22m [31m⚑[39m[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m