Skip to content

Test git client with real repositories - #14348

Merged
BagToad merged 1 commit into
trunkfrom
williammartin-git-real-repo-test-harness
Oct 30, 2026
Merged

BagToad merged 1 commit into
trunkfrom
williammartin-git-real-repo-test-harness

Conversation

@williammartin

@williammartin williammartin commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Description

Relates to #14349

The git.Client tests build much of Git's output themselves, so they mostly describe the fake process rather than repository behaviour. Their subprocess helpers also discard the environment needed by Go's coverage instrumentation.

This PR adds a temporary-repository harness and converts the branch, configuration, working-tree, remote-resolution and ignore scenarios to real Git. It also isolates inherited repository and configuration settings so test writes stay in test-owned files.

How did you test this change?

Not tested manually. This changes test infrastructure rather than user-facing command behaviour.

Key points

  • IsolateConfig clears inherited repository, index, object, template and configuration routing, then restores the original environment during cleanup.
  • The containment scenarios check that separate repositories and configuration files remain unchanged.
  • Repository tests stay serial because configuration isolation changes the process environment.
  • The remaining subprocess helpers inherit the coverage environment. Later layers remove those mock protocols.

Notes for reviewers

Start with IsolateConfig and its containment scenarios, then read newTestRepo and the converted scenarios.

This is the bottom of the existing stack. #14349 builds the graph and worktree scenarios on this harness.

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @williammartin will read and reply directly. Name the account.
  • An agent will draft replies and @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

Copilot AI balanced review requested due to automatic review settings September 4, 2026 14:57
@williammartin
williammartin requested a review from a team as a code owner September 4, 2026 14:57
@williammartin
williammartin marked this pull request as draft September 4, 2026 14:57

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The push-revision test compares the actual Git error against itself instead of the expected fixture.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity git/​client_test.go — 🛑 Requirement: Inspect the expected error, not the actual error This branch currently extracts…
What changed in this PR

Refactors Git client tests to exercise real temporary repositories while retaining targeted command fakes.

Changes:

  • Adds an isolated temporary-repository test harness.
  • Converts branch, config, remote, ignore, and working-tree tests.
  • Preserves coverage environment variables in helper subprocesses.
File Description
git/​client_test.go Refactors Git client tests and subprocess helpers.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread git/client_test.go Resolved
Comment thread git/client_test.go
return func(ctx context.Context, exe string, args ...string) *exec.Cmd {
cmd := exec.CommandContext(context.Background(), os.Args[0], "-test.run=TestCommandMocking", "--")
cmd.Env = []string{
cmd.Env = append(os.Environ(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This helps preserve Go’s coverage environment in the subprocess mocks. However, it will be removed again in a later PR: #14355

Copilot AI 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.

🟡 Changes recommended

The repository test harness still inherits the operator’s default Git ignore file, allowing personal ignore rules to break tests unless core.excludesFile points to a test-owned empty file.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread git/client_test.go Resolved

Copilot AI 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.

🔵 Needs a closer look

Unbounded repository discovery and unisolated default global attributes leave the tests dependent on ambient Git state, causing environment-dependent failures.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Bound Git discovery to isolate non-repository test

git/​client_test.go:2227

🛑 Requirement: Bound repository discovery in the non-repository test

If TMPDIR points inside a checkout, the temporary directory is still within that worktree. Git discovers the parent repository, especially since IsolateConfig clears GIT_CEILING_DIRECTORIES, so checking an unignored path returns no error and the subsequent require.Error fails. Set a discovery ceiling at the temporary directory's parent so this scenario reliably exercises the fatal non-repository path without reading an ambient repository.

Medium severity Isolate Git global attributes from caller configuration

git/​test.go:51

🛑 Requirement: Isolate the default global attributes file too

Setting GIT_CONFIG_GLOBAL does not disable Git's default $XDG_CONFIG_HOME/git/attributes (or ~/.config/git/attributes). For example, an inherited '*.txt working-tree-encoding=UTF-16' rule makes the new working-tree scenario fail at git add tracked.txt because its fixture lacks a UTF-16 BOM. Point core.attributesFile at the test-owned empty file too, so these real-Git tests do not depend on the caller's global attributes.

1 resolved since last review

Review effort: Balanced

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because an unpublished finding flags test error assertions that conflict with the testing guide.

No open issues 🎉

Review effort: Balanced

Replace synthetic Git output with temporary repository scenarios. Isolate ambient Git configuration, attributes, ignore rules, and repository routing while preserving subprocess coverage instrumentation.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 9e5f7d2e-d1db-4b6e-b470-8fa64d63286a
@williammartin
williammartin force-pushed the williammartin-git-real-repo-test-harness branch from 62fc540 to bc612ed Compare October 29, 2026 20:30
@williammartin
williammartin marked this pull request as ready for review October 29, 2026 20:44
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.

3 participants