Skip to content

fix(test): tests run from git bisect or a hook no longer change the calling repository - #38802

Closed
Entrpi wants to merge 2 commits into
pingdotgg:mainfrom
Entrpi:fix/git-fixtures-inherited-env
Closed

Entrpi wants to merge 2 commits into
pingdotgg:mainfrom
Entrpi:fix/git-fixtures-inherited-env

Conversation

@Entrpi

@Entrpi Entrpi commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Problem

Running tests from git bisect run or a git hook can change the repository that started them. Git exports GIT_DIR and related variables to the command it runs. The test fixtures inherit them, so a fixture's git init, git config and git commit act on the calling repository instead of the fixture's own. We hit this during a bisect: the config that all our worktrees share gained core.bare = true and the fixtures' test [user] identity, and we had to remove both by hand.

The server already clears these variables for its own git commands (#35119, #35764). The test fixtures and harnesses don't.

Change

  • Move the server's rule (unsetInheritedRepositoryEnv and its six GIT_* repository variables) from VcsProcess.ts to @t3tools/shared/gitEnvironment, unchanged. The server imports it from there, so product behavior doesn't change.
  • Add @t3tools/shared/testing/gitEnv, which removes those variables from process.env. The common test setup (testing/providerEnv.ts) loads it, so it runs before any fixture in every vitest project, including fixtures added later.
  • Load the same module in the scenario, mobile behavior, mobile showcase and live verification harnesses, which run outside vitest.
  • Add both modules to CI's shared-setup detection, and add a test script to @t3tools/provider-testing so CI runs the new test. The package had no tests before.

Scope

A bug fix in test setup, with no product behavior change. No issue: the new test shows the bug, and the fix moves one existing function and loads it in test setup.

Verification

  • New packages/provider-testing/src/replayWorkspace.test.ts: it makes a throwaway repository and runs the replay workspace fixture in a subprocess with all six variables pointing at it.
    • On main it fails: the fixture writes T3 Code Test <t3code-test@example.com> into the throwaway repository's config.
    • With this change it passes, and that repository's config and refs are unchanged.
  • vp run check:changed origin/main passes: format, lint, knip, typecheck, and 423 tests in the 7 test files beside the changes. On macOS this needed TMPDIR=/private/tmp, because of a /var versus /private/var path difference that fails the same way on main.

Written with gpt-6.2-sol (Codex) in T3 Code. PR text by Opus 5.5 (Claude Code) in T3 Code.

Git hooks and bisect can export repository selectors that redirect
fixture Git commands into the caller's repository. Fixture setup can
then overwrite local config and refs.

Share the server's existing selector rule with common test setup and
the upstream fixture harnesses. Use a throwaway repository to verify
that replay workspace setup leaves its config and refs intact, and
register the regression with CI.

User story: I can run tests from a Git hook or bisect without changing the repository that launched them.
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Git repository selector cleanup helper moved into shared code. Package exports, test environment setup, server Git consumers, and provider replay now use the shared helper. CI change detection no longer treats the removed testing helper path as an all-jobs trigger.

Changes: Git environment isolation

Layer / File(s) Summary
Shared filtering and test setup
packages/shared/src/gitEnvironment.ts, packages/shared/src/testing/*, packages/shared/package.json, apps/server/scripts/verify-background-live.ts, scripts/mobile-behavior/environment.ts, scripts/mobile-showcase-environment.ts, scripts/scenarios/shell.ts, scripts/check-changed.test.ts, .github/scripts/ci-changes.cjs
The shared helper identifies inherited Git repository selectors. The testing module uses it to remove those variables, and tests and test entry points reference the updated modules. Package exports and change detection lists are updated.
Server adoption and replay coverage
apps/server/src/project/RepositoryIdentityResolver.ts, apps/server/src/project/worktreeContainer.ts, apps/server/src/vcs/GitVcsDriverCore.ts, apps/server/src/vcs/VcsProcess.ts, packages/provider-testing/src/replayWorkspace.ts
Server Git consumers and provider replay use the helper from shared code. The local implementation in VcsProcess.ts is removed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: navidnadali, juliusmarminge, t3dotgg

Merge Risk: Minimal · up to 1757f

This change makes tests launched from git bisect or a Git hook ignore the inherited repository selector variables, so they no longer modify the calling repository. Server behavior is unchanged because the filtering logic only moved to a shared module. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: test runs started by git bisect or a git hook no longer modify the calling repository. The changeset moves the GIT_* repository selector unsetting into shared code and…
Description check Passed The description follows the template. It has Problem, Change, Scope, and Verification sections. It explains the bug, lists the changes, justifies the lack of an issue, and reports specific test result…
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.
Full details: Title check

Explanation

The title names the main change: test runs started by git bisect or a git hook no longer modify the calling repository. The changeset moves the GIT_* repository selector unsetting into shared code and loads it in test setup, which matches the fix. It uses conventional commit form and is specific.

Full details: Description check

Explanation

The description follows the template. It has Problem, Change, Scope, and Verification sections. It explains the bug, lists the changes, justifies the lack of an issue, and reports specific test results with the macOS TMPDIR workaround. It does not include the template's agent-model line, but it does name the model and harness at the end. It does not link an issue, which the Scope section justifies. The description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0e5574d and 1757f6f.

Files selected for processing: 7

  • .github/scripts/ci-changes.cjs
  • packages/provider-testing/src/replayWorkspace.ts
  • packages/shared/package.json
  • packages/shared/src/testing/gitEnv.test.ts
  • packages/shared/src/testing/gitEnv.ts
  • packages/shared/src/testing/gitRepositoryEnv.ts
  • scripts/check-changed.test.ts
Files with no reviewable changes: 1

  • packages/shared/src/testing/gitRepositoryEnv.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.

pingdotgg#38804 landed the test-run cleanup with a second copy of the repository
selector filter under shared/testing. Resolve onto main's setup files and
keep one filter in @t3tools/shared/gitEnvironment that the server, the test
setup and the replay fixture all import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). and removed size:M 30-99 changed lines (additions + deletions). labels Nov 19, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

The automated pipeline ran the reported steps in the real app without this change, and the problem did not appear. So it cannot show that this change fixes anything.

What was run on 410109da5d, the commit before this change:

On both commits: create an isolated global Git config; initialize a disposable repository with one Sentinel commit; add a linked worktree on feature; stage change.txt; install a pre-commit hook that runs vp test run src/orchestration-v2/testkit/OrchestratorReplayRestartBackgroundNote.integration.test.ts from apps/server; commit Developer change. Record inherited GIT_DIR and GIT_INDEX_FILE, compare local config and refs, hash the index immediately before and after the hook command, and run git status in the caller's main checkout. Both commits completed successfully: config unchanged, main unchanged, feature pointing to Developer change, index unchanged during the hook, and git status exit 0.

How: Manual Linux CLI reproduction in separate checkouts, using real linked-worktree pre-commit hooks and fresh synthetic caller repositories. Captures render recorded CLI output; videos preserve stdout timing at 1x. No live application data was used. Artifacts uploaded through ghdrop; checkouts and scratch data removed.

Closing this pull request. If you can share the exact steps, what you see, and the version and platform you are on, it can be reopened.

@juliusmarminge juliusmarminge added takeover:blocked Takeover blocked; reason in the PR body and removed takeover:in-progress A takeover lead is working on this PR labels Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). takeover:blocked Takeover blocked; reason in the PR body vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants