Skip to content

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

Test: fix user_pre_remove test to be cross-platform (#171)

Maximilian Roos12877262998f
diff --git a/tests/integration_tests/user_hooks.rs b/tests/integration_tests/user_hooks.rs
index 1907104cd..1cc3a6931 100644
--- a/tests/integration_tests/user_hooks.rs
+++ b/tests/integration_tests/user_hooks.rs
@@ -436,19 +436,18 @@ fn snapshot_remove(test_name: &str, repo: &TestRepo, args: &[&str], cwd: Option<
});
}
-/// Skipped on Windows: Uses /tmp path and file locking prevents worktree removal.
#[rstest]
-#[cfg_attr(windows, ignore)]
fn test_user_pre_remove_hook_executes(mut repo: TestRepo) {
// Create a worktree to remove
let _feature_wt = repo.add_worktree("feature");
// Write user config with pre-remove hook
+ // Hook writes to parent dir (temp dir) since the worktree itself gets removed
repo.write_test_config(
r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[pre-remove]
-cleanup = "echo 'USER_PRE_REMOVE_RAN' > /tmp/user_preremove_marker.txt"
+cleanup = "echo 'USER_PRE_REMOVE_RAN' > ../user_preremove_marker.txt"
"#,
);
@@ -459,11 +458,13 @@ cleanup = "echo 'USER_PRE_REMOVE_RAN' > /tmp/user_preremove_marker.txt"
Some(repo.root_path()),
);
- // Verify user hook ran (writes to /tmp since worktree is being removed)
- let marker_file = std::path::Path::new("/tmp/user_preremove_marker.txt");
+ // Verify user hook ran (writes to parent dir since worktree is being removed)
+ let marker_file = repo
+ .root_path()
+ .parent()
+ .unwrap()
+ .join("user_preremove_marker.txt");
assert!(marker_file.exists(), "User pre-remove hook should have run");
- // Clean up
- let _ = fs::remove_file(marker_file);
}
#[rstest]
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_executes.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_executes.snap
index b1a30307d..53f9b1e96 100644
--- a/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_executes.snap
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_pre_remove_executes.snap
@@ -7,6 +7,7 @@ info:
- feature
- "--force-delete"
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -14,10 +15,14 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
@@ -25,5 +30,5 @@ exit_code: 0
----- stderr -----
🔄 Running user pre-remove cleanup:
-  echo 'USER_PRE_REMOVE_RAN' > /tmp/user_preremove_marker.txt
+  echo 'USER_PRE_REMOVE_RAN' > ../user_preremove_marker.txt
🔄 Removing feature worktree & branch in background (--force-delete)