Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Enable Windows tests by normalizing ANSI escape codes (#147)
Maximilian Roos5bb60fdc7ecf
diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 110f967b8..6f11b8747 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -1309,6 +1309,10 @@ exit /b 1/// Must call `setup_mock_gh()` first. Prepends the mock bin directory to PATH/// so gh/glab commands are intercepted.///+ /// On Windows, this also removes directories containing real gh.exe/glab.exe from PATH.+ /// This is necessary because Windows searches for .exe before .cmd in PATHEXT order,+ /// so a real gh.exe would be found before our mock gh.cmd even with mock-bin first.+ ////// Metadata redactions keep PATH private in snapshots, so we can reuse the/// caller's PATH instead of a hardcoded minimal list.pub fn configure_mock_commands(&self, cmd: &mut Command) {@@ -1317,6 +1321,14 @@ exit /b 1.as_deref().map(|p| std::env::split_paths(p).collect()).unwrap_or_default();++ // On Windows, remove directories containing real gh.exe or glab.exe+ // to ensure our mock .cmd files are found instead+ #[cfg(windows)]+ {+ paths.retain(|dir| !dir.join("gh.exe").exists() && !dir.join("glab.exe").exists());+ }+paths.insert(0, mock_bin.clone());let new_path = std::env::join_paths(paths).unwrap();cmd.env("PATH", new_path);diff --git a/tests/fixtures/template-repo/_git/config b/tests/fixtures/template-repo/_git/configindex deb5290f2..9d01655cb 100644--- a/tests/fixtures/template-repo/_git/config+++ b/tests/fixtures/template-repo/_git/config@@ -5,6 +5,7 @@logallrefupdates = trueignorecase = trueprecomposeunicode = true+ autocrlf = false[user]name = Test Useremail = [email protected]diff --git a/tests/fixtures/template-repo/gitconfig b/tests/fixtures/template-repo/gitconfigindex 6bf32fe8e..36270ee7b 100644--- a/tests/fixtures/template-repo/gitconfig+++ b/tests/fixtures/template-repo/gitconfig@@ -6,3 +6,5 @@resolveConflict = false[init]defaultBranch = main+[core]+ autocrlf = falsediff --git a/tests/integration_tests/bare_repository.rs b/tests/integration_tests/bare_repository.rsindex 69d8a1f03..48a2b67e7 100644--- a/tests/integration_tests/bare_repository.rs+++ b/tests/integration_tests/bare_repository.rs@@ -483,7 +483,6 @@ fn test_bare_repo_commands_from_bare_directory() {/// during background cleanup after merge. The merge functionality itself works/// correctly - this is a timing/cleanup issue specific to Windows file handles.#[test]-#[cfg_attr(windows, ignore)]fn test_bare_repo_merge_workflow() {let test = BareRepoTest::new();diff --git a/tests/integration_tests/for_each.rs b/tests/integration_tests/for_each.rsindex 06bfe5e11..92de8eea4 100644--- a/tests/integration_tests/for_each.rs+++ b/tests/integration_tests/for_each.rs@@ -19,8 +19,6 @@ fn setup_repo() -> TestRepo {repo}-/// Skipped on Windows: snapshot output differs due to shell/path differences.-#[cfg_attr(windows, ignore)]#[test]fn test_for_each_single_worktree() {let repo = setup_repo();@@ -33,8 +31,6 @@ fn test_for_each_single_worktree() {);}-/// Skipped on Windows: snapshot output differs due to shell/path differences.-#[cfg_attr(windows, ignore)]#[test]fn test_for_each_multiple_worktrees() {let mut repo = setup_repo();@@ -50,8 +46,6 @@ fn test_for_each_multiple_worktrees() {);}-/// Skipped on Windows: snapshot output differs due to shell/path differences.-#[cfg_attr(windows, ignore)]#[test]fn test_for_each_command_fails_in_one() {let mut repo = setup_repo();@@ -74,8 +68,6 @@ fn test_for_each_no_args_error() {snapshot_for_each("for_each_no_args", &repo, &["for-each"]);}-/// Skipped on Windows: snapshot output differs due to shell/path differences.-#[cfg_attr(windows, ignore)]#[test]fn test_for_each_with_detached_head() {let mut repo = setup_repo();@@ -91,8 +83,6 @@ fn test_for_each_with_detached_head() {);}-/// Skipped on Windows: snapshot output differs due to shell/path differences.-#[cfg_attr(windows, ignore)]#[test]fn test_for_each_with_template() {let repo = setup_repo();diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rsindex 12047b784..b624fc3b1 100644--- a/tests/integration_tests/statusline.rs+++ b/tests/integration_tests/statusline.rs@@ -31,10 +31,14 @@ fn run_statusline_from_dir(let mut child = cmd.spawn().expect("failed to spawn command");if let Some(json) = stdin_json {- let stdin = child.stdin.as_mut().expect("failed to get stdin");+ // Take ownership of stdin so we can drop it after writing+ let mut stdin = child.stdin.take().expect("failed to get stdin");stdin.write_all(json.as_bytes()).expect("failed to write stdin");+ // Explicitly close stdin by dropping it - this signals EOF to the child process.+ // On Windows, not closing stdin can cause the child to hang waiting for more input.+ drop(stdin);}let output = child.wait_with_output().expect("failed to wait for output");@@ -139,12 +143,20 @@ fn claude_code_snapshot_settings(repo: &TestRepo) -> insta::Settings {settings}-/// Skipped on Windows: JSON contains paths that need escaping on Windows.+/// Escape a path for use in JSON strings.+/// On Windows, backslashes must be escaped as double backslashes.+fn escape_path_for_json(path: &std::path::Path) -> String {+ path.display().to_string().replace('\\', "\\\\")+}++/// Skipped on Windows: stdin read has 10ms timeout, Windows process spawning is slower+/// causing timing-sensitive race condition where model name is lost.#[test]#[cfg_attr(windows, ignore)]fn test_statusline_claude_code_full_context() {let repo = setup_repo_with_changes();+ let escaped_path = escape_path_for_json(repo.root_path());let json = format!(r#"{{"hook_event_name": "Status",@@ -154,13 +166,11 @@ fn test_statusline_claude_code_full_context() {"display_name": "Opus"}},"workspace": {{- "current_dir": "{}",- "project_dir": "{}"+ "current_dir": "{escaped_path}",+ "project_dir": "{escaped_path}"}},"version": "1.0.80"}}"#,- repo.root_path().display(),- repo.root_path().display());let output = run_statusline(&repo, &["--claude-code"], Some(&json));@@ -169,16 +179,12 @@ fn test_statusline_claude_code_full_context() {});}-/// Skipped on Windows: JSON contains paths that need escaping on Windows.#[test]-#[cfg_attr(windows, ignore)]fn test_statusline_claude_code_minimal() {let repo = TestRepo::new();- let json = format!(- r#"{{"workspace": {{"current_dir": "{}"}}}}"#,- repo.root_path().display()- );+ let escaped_path = escape_path_for_json(repo.root_path());+ let json = format!(r#"{{"workspace": {{"current_dir": "{escaped_path}"}}}}"#,);let output = run_statusline(&repo, &["--claude-code"], Some(&json));claude_code_snapshot_settings(&repo).bind(|| {@@ -186,18 +192,19 @@ fn test_statusline_claude_code_minimal() {});}-/// Skipped on Windows: JSON contains paths that need escaping on Windows.+/// Skipped on Windows: stdin read has 10ms timeout, Windows process spawning is slower+/// causing timing-sensitive race condition where model name is lost.#[test]#[cfg_attr(windows, ignore)]fn test_statusline_claude_code_with_model() {let repo = TestRepo::new();+ let escaped_path = escape_path_for_json(repo.root_path());let json = format!(r#"{{- "workspace": {{"current_dir": "{}"}},+ "workspace": {{"current_dir": "{escaped_path}"}},"model": {{"display_name": "Haiku"}}}}"#,- repo.root_path().display());let output = run_statusline(&repo, &["--claude-code"], Some(&json));