Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Enable Windows CI status tests via MOCK_SCRIPT_DIR (#407)
Maximilian Roosa7bb80365e75
diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 1e9e72807..c9bcffb98 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -1567,18 +1567,35 @@ esacstd::fs::write(&pr_json_file, pr_json).unwrap();std::fs::write(&run_json_file, run_json).unwrap();- // Use dirname "$0" to find JSON files relative to script.- // This works on both Unix and Windows because:- // - On Unix: $0 is the script path as invoked- // - On Windows: mock-stub.exe converts the path to MSYS2 format before invoking bash- write_mock_script(- &mock_bin,- "gh",- r#"#!/bin/sh+ // Convert mock_bin path to a format bash can read.+ // On Windows, convert D:\foo\bar to /d/foo/bar (MSYS2 style).+ // On Unix, just use the path as-is.+ let script_dir = {+ let path_str = mock_bin.to_string_lossy();+ #[cfg(windows)]+ {+ let chars: Vec<char> = path_str.chars().collect();+ if chars.len() >= 2 && chars[1] == ':' {+ // D:\foo\bar -> /d/foo/bar+ let drive = chars[0].to_ascii_lowercase();+ format!("/{}{}", drive, path_str[2..].replace('\\', "/"))+ } else {+ path_str.replace('\\', "/")+ }+ }+ #[cfg(not(windows))]+ {+ path_str.to_string()+ }+ };++ // Embed SCRIPT_DIR directly to avoid path resolution issues on Windows.+ // Debug mode: set MOCK_GH_DEBUG=1 to see path resolution info.+ let script = format!(+ r#"#!/bin/bash# Mock gh command that returns configured JSON data# JSON files are in the same directory as this script--SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"+SCRIPT_DIR="{script_dir}"case "$1" in--version)@@ -1603,8 +1620,9 @@ case "$1" inexit 1;;esac-"#,+"#);+ write_mock_script(&mock_bin, "gh", &script);// Create mock glab script (fails immediately - no GitLab support in this mock)write_mock_script(diff --git a/tests/helpers/mock-stub/src/main.rs b/tests/helpers/mock-stub/src/main.rsindex 0c2502412..3fdbcc2f8 100644--- a/tests/helpers/mock-stub/src/main.rs+++ b/tests/helpers/mock-stub/src/main.rs@@ -11,7 +11,7 @@use std::env;use std::io::{self, Write};-use std::path::Path;+use std::path::{Path, PathBuf};use std::process::{Command, Stdio, exit};/// Convert Windows path to MSYS2/Git Bash style path.@@ -33,12 +33,32 @@ fn to_msys_path(path: &Path) -> String {}}+/// Find Git Bash on Windows (avoid WSL bash wrapper at `C:\Windows\System32\bash.exe`).+#[cfg(windows)]+fn find_bash() -> PathBuf {+ // GitHub Actions and most Windows installations have Git here+ let git_bash = PathBuf::from(r"C:\Program Files\Git\bin\bash.exe");+ if git_bash.exists() {+ git_bash+ } else {+ PathBuf::from("bash")+ }+}++#[cfg(not(windows))]+fn find_bash() -> PathBuf {+ PathBuf::from("bash")+}+fn main() {let exe_path = env::current_exe().expect("failed to get executable path");// Strip .exe extension to get companion script path// e.g., /tmp/bin/gh.exe -> /tmp/bin/ghlet script_path = exe_path.with_extension("");+ let script_dir = script_path+ .parent()+ .expect("mock-stub: script path has no parent directory");// Distinguish setup errors from environment errorsif !script_path.exists() {@@ -52,31 +72,45 @@ fn main() {// Convert to MSYS2-style path for bash on Windowslet script_path_str = to_msys_path(&script_path);+ let script_dir_str = to_msys_path(script_dir);// Forward all arguments to bash with the scriptlet args: Vec<String> = env::args().skip(1).collect();+ // Find Git Bash on Windows (avoid WSL bash wrapper)+ let bash_path = find_bash();+// Debug: Show what we're about to execute (only when MOCK_DEBUG is set)if env::var("MOCK_DEBUG").is_ok() {eprintln!("mock-stub: exe_path={}", exe_path.display());eprintln!("mock-stub: script_path={}", script_path.display());eprintln!("mock-stub: script_path_str={}", script_path_str);+ eprintln!("mock-stub: script_dir={}", script_dir.display());+ eprintln!("mock-stub: script_dir_str={}", script_dir_str);+ eprintln!("mock-stub: bash_path={}", bash_path.display());eprintln!("mock-stub: args={:?}", args);}// Use .output() to capture stdout/stderr, then forward them.// This is more reliable than relying on handle inheritance on Windows,// which can fail silently when pipes are involved.- let output = Command::new("bash")+ //+ // Pass MOCK_SCRIPT_DIR so scripts can reliably find sibling files.+ // This avoids $0/dirname/pwd issues in Git Bash on Windows CI.+ let output = Command::new(&bash_path).arg(&script_path_str).args(&args)+ .env("MOCK_SCRIPT_DIR", &script_dir_str).stdin(Stdio::inherit()).stdout(Stdio::piped()).stderr(Stdio::piped()).output().unwrap_or_else(|e| {- eprintln!("mock-stub: failed to execute bash: {e}");- eprintln!("Is Git Bash installed and in PATH?");+ eprintln!(+ "mock-stub: failed to execute bash at {}: {e}",+ bash_path.display()+ );+ eprintln!("Is Git Bash installed?");exit(1);});diff --git a/tests/integration_tests/ci_status.rs b/tests/integration_tests/ci_status.rsindex 6f2711c0b..79f860aef 100644--- a/tests/integration_tests/ci_status.rs+++ b/tests/integration_tests/ci_status.rs@@ -5,15 +5,9 @@//!//! ## Windows support//!-//! These tests are currently skipped on Windows because the mock gh command-//! infrastructure doesn't work reliably with the bash->JSON file reading-//! pipeline. The mock-stub.exe successfully invokes bash, but the SCRIPT_DIR-//! path resolution and JSON file reading fails in CI.-//!-//! See: https://github.com/max-sixty/worktrunk/issues/401-//!-//! Tests that only need simple mock behavior (e.g., `wt config show` which-//! just checks if gh --version succeeds) work fine on Windows.+//! On Windows, mock-stub.exe sets MOCK_SCRIPT_DIR so the mock gh script can+//! reliably locate its JSON data files. Use MOCK_DEBUG=1 to troubleshoot+//! path issues.use crate::common::{TestRepo, make_snapshot_cmd, repo, setup_snapshot_settings};use insta_cmd::assert_cmd_snapshot;@@ -26,7 +20,6 @@ fn get_branch_sha(repo: &TestRepo, branch: &str) -> String {/// Test CI status detection with GitHub PR showing passed checks#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_github_pr_passed(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -68,7 +61,6 @@ fn test_list_full_with_github_pr_passed(mut repo: TestRepo) {/// Test CI status detection with GitHub PR showing failed checks#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_github_pr_failed(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -110,7 +102,6 @@ fn test_list_full_with_github_pr_failed(mut repo: TestRepo) {/// Test CI status detection with GitHub PR showing running checks#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_github_pr_running(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -152,7 +143,6 @@ fn test_list_full_with_github_pr_running(mut repo: TestRepo) {/// Test CI status detection with GitHub PR showing conflicts#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_github_pr_conflicts(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -194,7 +184,6 @@ fn test_list_full_with_github_pr_conflicts(mut repo: TestRepo) {/// Test CI status detection with StatusContext (external CI like pre-commit.ci)#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_status_context_pending(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -236,7 +225,6 @@ fn test_list_full_with_status_context_pending(mut repo: TestRepo) {/// Test CI status detection with StatusContext failure (external CI)#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_status_context_failure(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -278,7 +266,6 @@ fn test_list_full_with_status_context_failure(mut repo: TestRepo) {/// Test CI status detection with no PR but workflow run#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_github_workflow_run(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -316,7 +303,6 @@ fn test_list_full_with_github_workflow_run(mut repo: TestRepo) {/// Test CI status detection with workflow run in progress#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_github_workflow_running(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -354,7 +340,6 @@ fn test_list_full_with_github_workflow_running(mut repo: TestRepo) {/// Test CI status with stale PR (local HEAD differs from PR HEAD)#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_stale_pr(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -397,7 +382,6 @@ fn test_list_full_with_stale_pr(mut repo: TestRepo) {/// Test CI status detection with mixed CheckRun and StatusContext results#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_mixed_check_types(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -441,7 +425,6 @@ fn test_list_full_with_mixed_check_types(mut repo: TestRepo) {/// Test CI status detection when PR has no checks configured#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_with_no_ci_checks(mut repo: TestRepo) {// Add GitHub remoterepo.run_git(&[@@ -481,7 +464,6 @@ fn test_list_full_with_no_ci_checks(mut repo: TestRepo) {/// Test filtering PRs by repository owner#[rstest]-#[cfg_attr(windows, ignore = "mock gh JSON reading fails on Windows CI")]fn test_list_full_filters_by_repo_owner(mut repo: TestRepo) {// Add GitHub remote with specific ownerrepo.run_git(&[