Skip to content

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

test: convert absolute-path detached worktree tests to non-snapshot (#1684)

Maximilian Roos23858bc6b7ea
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rs
index 03dea4ea5..2c720bf3d 100644
--- a/tests/integration_tests/remove.rs
+++ b/tests/integration_tests/remove.rs
@@ -1823,24 +1823,31 @@ fn test_remove_detached_by_name_fails(mut repo: TestRepo) {
assert_cmd_snapshot!(make_snapshot_cmd(&repo, "remove", &["(detached)"], None));
}
-/// Verify that detached worktrees can be removed by path (#1661).
+/// Verify that detached worktrees can be removed by absolute path (#1661).
/// This ensures the CLI supports the same operation the picker uses.
#[rstest]
fn test_remove_detached_worktree_by_path(mut repo: TestRepo) {
- repo.add_worktree("feature-detached");
+ let worktree_path = repo.add_worktree("feature-detached");
repo.detach_head_in_worktree("feature-detached");
- let worktree_path = repo
- .worktree_path("feature-detached")
- .to_string_lossy()
- .to_string();
+ assert!(worktree_path.exists());
- assert_cmd_snapshot!(make_snapshot_cmd(
- &repo,
- "remove",
- &[&worktree_path, "--foreground", "--yes"],
- None,
- ));
+ let worktree_str = worktree_path.to_string_lossy().to_string();
+ let output = repo
+ .wt_command()
+ .args(["remove", &worktree_str, "--foreground", "--yes"])
+ .output()
+ .unwrap();
+
+ assert!(
+ output.status.success(),
+ "wt remove should succeed: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ assert!(
+ !worktree_path.exists(),
+ "Worktree directory should be removed"
+ );
}
/// Verify that detached worktrees can be removed by relative path.
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index 498dec618..43328c75a 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -994,21 +994,23 @@ fn test_switch_error_path_occupied_detached(repo: TestRepo) {
snapshot_switch_with_directive_file("switch_error_path_occupied_detached", &repo, &["feature"]);
}
-/// Switch to a detached worktree by path (#1661).
+/// Switch to a detached worktree by absolute path (#1661).
#[rstest]
fn test_switch_detached_worktree_by_path(mut repo: TestRepo) {
- repo.add_worktree("feature-detached");
+ let worktree_path = repo.add_worktree("feature-detached");
repo.detach_head_in_worktree("feature-detached");
- let worktree_path = repo
- .worktree_path("feature-detached")
- .to_string_lossy()
- .to_string();
+ let worktree_str = worktree_path.to_string_lossy().to_string();
+ let output = repo
+ .wt_command()
+ .args(["switch", &worktree_str])
+ .output()
+ .unwrap();
- snapshot_switch_with_directive_file(
- "switch_detached_worktree_by_path",
- &repo,
- &[&worktree_path],
+ assert!(
+ output.status.success(),
+ "wt switch should succeed: {}",
+ String::from_utf8_lossy(&output.stderr)
);
}
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_by_path.snap b/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_by_path.snap
deleted file mode 100644
index 31d9dae47..000000000
--- a/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_by_path.snap
+++ /dev/null
@@ -1,48 +0,0 @@
----
-source: tests/integration_tests/remove.rs
-info:
- program: wt
- args:
- - remove
- - /tmp/.tmph0CPwB/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 -----
-◎ Removing worktree @ _REPO_.feature-detached... (detached HEAD, no branch to delete)
-✓ Removed worktree @ _REPO_.feature-detached (detached HEAD, no branch to delete)
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_detached_worktree_by_path.snap b/tests/snapshots/integration__integration_tests__switch__switch_detached_worktree_by_path.snap
deleted file mode 100644
index cf528dfb6..000000000
--- a/tests/snapshots/integration__integration_tests__switch__switch_detached_worktree_by_path.snap
+++ /dev/null
@@ -1,47 +0,0 @@
----
-source: tests/integration_tests/switch.rs
-info:
- program: wt
- args:
- - switch
- - /private/var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpj2sTWR/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 -----
-▲ Branch-worktree mismatch: repo.feature-detached @ _REPO_.feature-detached, expected @ _REPO_.repo.feature-detached ⚑
-○ Switched to worktree for repo.feature-detached @ _REPO_.feature-detached