From 3432e0615cfea1df1bdf91e1e1d676d81faece0e Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Wed, 3 Jun 2026 19:07:20 -0700 Subject: [PATCH] test: pin git init to 'main' in test setup (fix Linux-CI branch-group failures) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Git defaults the initial branch to 'master' unless init.defaultBranch is set — true on Linux CI runners but typically overridden to 'main' on developer macOS machines. That host gap made git-worktree tests assuming 'main' (the shared-branch-group reliability suite in engine shard 2/2) pass locally but fail only in CI with 'fatal: path ... does not exist in main'. Set init.defaultBranch=main for every test process via GIT_CONFIG_* env vars in the shared core test setup (inherited by all child git invocations, without mutating the developer's global config). Appends rather than clobbers any pre-existing GIT_CONFIG_COUNT. Co-Authored-By: Claude Opus 4.8 (1M context) --- packages/core/src/__test-utils__/vitest-setup.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/core/src/__test-utils__/vitest-setup.ts b/packages/core/src/__test-utils__/vitest-setup.ts index 8d2f57695a..de895b95f8 100644 --- a/packages/core/src/__test-utils__/vitest-setup.ts +++ b/packages/core/src/__test-utils__/vitest-setup.ts @@ -69,6 +69,20 @@ const BLOCKED_TEST_CLI_PATTERN = const originalCwd = process.cwd.bind(process); +// Pin `git init` to the `main` branch for every test process. Git defaults the +// initial branch to `master` unless `init.defaultBranch` is set — true on Linux +// CI runners but usually overridden to `main` on developer macOS machines. That +// host gap silently broke git-worktree tests that assume `main` (e.g. the +// shared-branch-group reliability suite) in CI only. These GIT_CONFIG_* env +// vars apply the setting to all child git invocations without mutating the +// developer's global config. Appended (not clobbered) if a count already exists. +(() => { + const existing = Number.parseInt(process.env.GIT_CONFIG_COUNT ?? "0", 10) || 0; + process.env[`GIT_CONFIG_KEY_${existing}`] = "init.defaultBranch"; + process.env[`GIT_CONFIG_VALUE_${existing}`] = "main"; + process.env.GIT_CONFIG_COUNT = String(existing + 1); +})(); + function ensureValidCwd(): string { try { return originalCwd();