Skip to content

e2e setup: don't let an inherited git env re-init the parent repo - #51805

Merged
Jinwoo-H merged 3 commits into
mainfrom
e2e-setup-strip-git-env
Nov 29, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
e2e-setup-strip-git-env

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When e2e tests were started from inside a git command (for example git bisect run), the test setup's git init could re-initialise the developer's own checkout as a bare repo. After that, git stopped working in every worktree of that checkout. Now the e2e runner drops that inherited git environment before anything runs.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​26 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

What Changed

  • tests/playwright.config.ts now first imports the existing git-env scrub that Vitest already uses. The config loads in the Playwright runner and in every worker before global setup, fixtures, or app launches, so every git call and launched app in an e2e run starts without GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_COMMON_DIR and related variables.
  • The shared list now also removes GIT_CONFIG, which otherwise sends the seeder's plain git config user.* writes into whatever file it names (e.g. another repo's config), and the remaining repo-locating variables (GIT_CEILING_DIRECTORIES, GIT_IMPLICIT_WORK_TREE, GIT_GRAFT_FILE, GIT_SHALLOW_FILE, GIT_REPLACE_REF_BASE, GIT_NO_REPLACE_OBJECTS, GIT_SUPER_PREFIX). GIT_CONFIG_GLOBAL/SYSTEM/NOSYSTEM and -c values (GIT_CONFIG_COUNT/PARAMETERS) stay: they can't redirect a write, and the signing/compat setup relies on them.
  • pr-package-test-paths.mjs keeps Windows test routing for the renamed setup file.
  • Renamed vitest-inherited-git-env-setup.ts to inherited-git-env-setup.ts, since Vitest and Playwright now share it (one list of variables). This matches the rename on layout-owner-v2 (fix(layout-owner): a held pane keeps its terminal until Reopen; e2e seeding ignores a hook's git env #51761), so the two branches merge cleanly.
  • Added tests/e2e/global-setup-inherited-git-env.unit.test.ts. It sets GIT_DIR to a linked worktree's git dir in a throwaway repo (the same value git bisect run exports), loads the Playwright config, runs the real seedTestRepository(), and checks that the throwaway repo's shared config still has core.bare=false and no user.name. A second case points GIT_CONFIG at an outside file and checks that seeding leaves it unchanged.

Why

git bisect run, git hooks, git rebase --exec and git submodule foreach export GIT_DIR to the commands they run. When the global setup ran plain git init in a temp folder with GIT_DIR=<repo>/.git/worktrees/<wt>, git re-initialised that repo. Because the path doesn't end in /.git, git guessed it was bare and wrote core.bare = true to the shared .git/config, which broke git in every worktree with "fatal: this operation must be run in a work tree". The git config user.* calls also wrote the E2E Test identity into it.

Clearing the variables once, where the runner loads its config, covers the global setup, worker fallback seeding, fixtures, and the Electron app under test (whose own git calls would otherwise also target the outer repo). That's simpler than passing an env to every git call.

Linked Issue

N/A (internal)

Visual Proof

N/A: test infrastructure only, no UI change.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • Reproduced the original bug in a throwaway repo with a linked worktree: git bisect run of a script that does git init in a temp folder flipped the shared core.bare from false to true.

  • New tests pass; with the config import removed both fail (shared repo flipped to bare; outside config rewritten with E2E Test). With only GIT_CONFIG removed from the list, the second case fails.

  • pnpm check:code-quality:changed and pnpm tc:node pass (macOS).

Performance

None, because this only deletes a few environment variables once when the test runner loads its config.

Risk

Low. Only test runs change. Anyone who relied on an exported GIT_DIR reaching e2e tests now gets the checkout found from the working directory, which is the same repo in normal use. Back out with a plain revert.

Level: Low

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Playwright configuration imports inherited Git environment setup before other imports. The setup removes selected inherited Git environment variables and retains the documented exceptions. The unit-selection setup list and TypeScript include list use the setup path. New tests check repository seeding when GIT_DIR points to a linked worktree and verify that a file named by GIT_CONFIG remains unchanged.

Merge Risk: Minimal · up to e7c28

This change stops inherited Git environment variables from making e2e setup rewrite a developer's checkout configuration. It affects only test tooling, and a regression test covers the scenario. No remaining merge risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the e2e setup no longer lets an inherited git environment make the parent repository re-initialise. The PR scrubs inherited GIT_DIR and related variables in the Playwr…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is detailed and covers most of the required template. It has a clear ELI5, a What Changed section, a Why section, Testing checkboxes with concrete steps (macOS run, reproduction, and a…
Full details: Title check

Explanation

The title names the main change: the e2e setup no longer lets an inherited git environment make the parent repository re-initialise. The PR scrubs inherited GIT_DIR and related variables in the Playwright config, which matches the title's subject and intent. The title is short and specific, and it uses a single sentence.

Full details: Description check

Explanation

The description is detailed and covers most of the required template. It has a clear ELI5, a What Changed section, a Why section, Testing checkboxes with concrete steps (macOS run, reproduction, and a failure check with the config import removed), a Performance line, and a Risk section with a level and backout plan. The Visual Proof section is correctly marked N/A with a reason. Two items are weak. The Linked Issue section says "N/A (internal)", but the template says a linked issue should always exist for outside contributors. The author appears to be a maintainer, so the special case may apply, but the description does not state that. The Testing section also does not name the platforms beyond macOS, and Windows/Linux/SSH impact is not verified. The AI Disclosure section is left as the unfilled template comment, which is acceptable only for internal contributors and is not confirmed here.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: edf226a6-7419-444a-a2be-f726bb2f37f8
Commits

Reviewing files that changed from the base of the PR and between cfd5a63 and e7c2884.

Files selected for processing: 3

  • config/scripts/test-runtime/environment/inherited-git-env-setup.ts
  • config/scripts/workflow/source-routing/pr-package-test-paths.mjs
  • tests/e2e/global-setup-inherited-git-env.unit.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0167c596-771c-4b44-b457-1c63793fd1ea
Commits

Reviewing files that changed from the base of the PR and between 590b2b6 and 004638a.

Files selected for processing: 5

  • config/scripts/ci/unit-selection/dependency-graph/ci-unit-files.mjs
  • config/scripts/test-runtime/environment/inherited-git-env-setup.ts
  • config/tsconfig.node.json
  • tests/e2e/global-setup-inherited-git-env.unit.test.ts
  • tests/playwright.config.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@Jinwoo-H
Jinwoo-H merged commit f6e561e into main Nov 29, 2026
59 checks passed
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.

1 participant