Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
test: add relative path tests for detached worktree remove and switch (#1682)
Maximilian Roos630782847012
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rsindex ffa7cb2c2..03dea4ea5 100644--- a/tests/integration_tests/remove.rs+++ b/tests/integration_tests/remove.rs@@ -1843,6 +1843,23 @@ fn test_remove_detached_worktree_by_path(mut repo: TestRepo) {));}+/// Verify that detached worktrees can be removed by relative path.+/// This tests resolve_worktree_arg's CWD-relative path resolution for Remove context.+#[rstest]+fn test_remove_detached_worktree_by_relative_path(mut repo: TestRepo) {+ repo.add_worktree("feature-detached");+ repo.detach_head_in_worktree("feature-detached");++ // From the main worktree (repo/), the relative path resolves against CWD+ let relative_path = "../repo.feature-detached";+ assert_cmd_snapshot!(make_snapshot_cmd(+ &repo,+ "remove",+ &[relative_path, "--foreground", "--yes"],+ None,+ ));+}+/// Test that resolve_worktree("@") works when the worktree is accessed via a symlink.////// This tests the path normalization fix where:diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex d28a517c4..498dec618 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -1012,6 +1012,23 @@ fn test_switch_detached_worktree_by_path(mut repo: TestRepo) {);}+/// Switch to a detached worktree by relative path.+/// Relative paths with directory separators (e.g., "../repo.feature") are resolved against CWD.+#[rstest]+fn test_switch_detached_worktree_by_relative_path(mut repo: TestRepo) {+ repo.add_worktree("feature-detached");+ repo.detach_head_in_worktree("feature-detached");++ // From the main worktree (repo/), the detached worktree is at ../repo.feature-detached+ let relative_path = "../repo.feature-detached";++ snapshot_switch_with_directive_file(+ "switch_detached_worktree_by_relative_path",+ &repo,+ &[relative_path],+ );+}+////// When the main worktree (repo root) has been switched to a feature branch via/// `git checkout feature`, `wt switch main` should error with a helpful messagediff --git a/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_by_relative_path.snap b/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_by_relative_path.snapnew file mode 100644index 000000000..f373ae136--- /dev/null+++ b/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_by_relative_path.snap@@ -0,0 +1,48 @@+---+source: tests/integration_tests/remove.rs+info:+ program: wt+ args:+ - remove+ - "../repo.feature-detached"+ - "--foreground"+ - "--yes"+ 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+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mRemoving worktree @ [1m_REPO_.feature-detached[22m... (detached HEAD, no branch to delete)[39m+[32m✓[39m [32mRemoved worktree @ [1m_REPO_.feature-detached[22m (detached HEAD, no branch to delete)[39mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_detached_worktree_by_relative_path.snap b/tests/snapshots/integration__integration_tests__switch__switch_detached_worktree_by_relative_path.snapnew file mode 100644index 000000000..83ee289c4--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_detached_worktree_by_relative_path.snap@@ -0,0 +1,47 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "../repo.feature-detached"+ 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+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_DIRECTIVE_FILE: "[DIRECTIVE_FILE]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[33m▲[39m [33mBranch-worktree mismatch: [1mrepo.feature-detached[22m @ [1m_REPO_.feature-detached[22m, expected @ [1m_REPO_.repo.feature-detached[22m [31m⚑[39m[39m+[2m○[22m Switched to worktree for [1mrepo.feature-detached[22m @ [1m_REPO_.feature-detached[22m