Skip to content

Fix macOS and Windows CI: prevent parallel test temp-dir collisions in unique_temp_repo_dir#24

Merged
mwallner merged 9 commits into
developfrom
copilot/fix-build-macos-failure
Jun 6, 2026
Merged

Fix macOS and Windows CI: prevent parallel test temp-dir collisions in unique_temp_repo_dir#24
mwallner merged 9 commits into
developfrom
copilot/fix-build-macos-failure

Conversation

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

The "Build (macOS)" CI job was failing because parallel unit tests could collide on the same temporary directory path, causing git init --bare to fail with File exists when copying templates into an already-initialized repo.

Root cause

unique_temp_repo_dir() used SystemTime::now().as_nanos() + pid — but all test threads share the same PID, and macOS system clock resolution can be coarser than 1 ns, so two concurrent calls could produce identical paths. add_origin_remote_with_feature() calls this twice per test; with branch_exists_anywhere_finds_remote_only_branch and branch_exists_anywhere_returns_false_for_truly_missing_branch running in parallel, one would win the git init --bare and the other would error.

Changes (tests/test_helpers.rs)

  • Atomic counter replaces SystemTime + PID — an AtomicU64 incremented per call guarantees uniqueness regardless of timing or concurrency.

  • Canonicalize temp dir base (non-Windows only) to resolve the macOS /var/private/var symlink before constructing the path, preventing Homebrew git from encountering unexpected path aliasing during template copying. The canonicalize step is skipped on Windows because Path::canonicalize() there converts paths to the \\?\C:\... extended-length UNC format, which git rejects as an invalid hostname when used as a local remote URL and cannot resolve as a worktree path.

// Before
let ts = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_nanos();
std::env::temp_dir().join(format!("mergetopus-test-{ts}-{}", std::process::id()))

// After
static UNIQUE_ID: AtomicU64 = AtomicU64::new(0);
let id = UNIQUE_ID.fetch_add(1, Ordering::Relaxed);
#[cfg(not(windows))]
let base = std::env::temp_dir().canonicalize().unwrap_or_else(|_| std::env::temp_dir());
#[cfg(windows)]
let base = std::env::temp_dir();
base.join(format!("mergetopus-test-{}-{}", std::process::id(), id))

mwallner and others added 7 commits April 11, 2026 22:03
Harden resolve flow and improve TUI branch selection
added large integration tests and updated readme
readme for humans, by humans
re-relase 0.5 after package moderation
icon cdn, remove obsolete scripts
I've been on a 10-hour train-ride with lots of ☕ and 🤖
Copilot AI changed the title [WIP] Fix failing GitHub Actions job Build (macOS) Fix macOS CI: prevent parallel test temp-dir collisions in unique_temp_repo_dir Jun 5, 2026
Copilot AI requested a review from mwallner June 5, 2026 14:17
@mwallner mwallner changed the base branch from main to develop June 5, 2026 14:19
@mwallner mwallner marked this pull request as ready for review June 5, 2026 14:19
@mwallner

mwallner commented Jun 5, 2026

Copy link
Copy Markdown
Owner

@copilot now the Windows tests are failing. All Actions must pass successfully.

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@copilot now the Windows tests are failing. All Actions must pass successfully.

Fixed in 58de74d. On Windows, std::path::Path::canonicalize() converts temp paths to the \\?\C:\... extended-length UNC format, which git rejects as an invalid hostname when used as a local remote URL, and cannot resolve as a worktree path. The fix wraps the canonicalize() call in #[cfg(not(windows))] so it only applies on macOS (where it's needed to resolve /var/private/var) and is skipped on Windows.

Copilot AI changed the title Fix macOS CI: prevent parallel test temp-dir collisions in unique_temp_repo_dir Fix macOS and Windows CI: prevent parallel test temp-dir collisions in unique_temp_repo_dir Jun 5, 2026
@mwallner mwallner merged commit 286c164 into develop Jun 6, 2026
3 checks passed
@mwallner mwallner deleted the copilot/fix-build-macos-failure branch June 6, 2026 21:00
mwallner added a commit that referenced this pull request Jun 6, 2026
Merge pull request #24 from mwallner/copilot/fix-build-macos-failure

Fix macOS and Windows CI: prevent parallel test temp-dir collisions in unique_temp_repo_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants