Skip to content

test(git): one git seam, one fake, one contract suite - #2799

Merged
dan-petty merged 11 commits into
mainfrom
test/2146-one-git-seam-and-fake
Oct 30, 2026
Merged

dan-petty merged 11 commits into
mainfrom
test/2146-one-git-seam-and-fake

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Tests of src/ start git more than any other program. This change gives git one seam, the process runner, and one fake for it.

  • The three users of GitPython (git/operations.py, commands/repos.py, ai/research/edges.py) now run git through the process runner. No module of src/ imports GitPython, and it leaves the dependencies.
  • GitFake and the git_fake fixture answer each git command from a transcript in tests/fixtures/git/. A record is found by the arguments, the directory, the standard input and the environment. A command with no record fails the test and names the command. A test with the fixture cannot start a real git.
  • The real git records the transcripts again (tests/support/git_recording.py) with no user or system configuration file. The git row of devops ci fails when a transcript differs. A contract suite replays every transcript over the code with ProcessFake and with GitFake.
  • commit_snapshot gives the same commit id as before. It takes each path as a file name and reads no attributes file of the user. pull_tracking raises the reason of git when git config --get fails.
  • The three test files of the issue and four others use the fake and start no git. docs/TESTING.md describes the seam, the fake and the row.

Closes #2146

Plans #2146: the process runner is the one seam for git, a git fake
answers from recorded transcripts, and a devops ci row records them again.
…2146)

GitFake answers a git command from a transcript that the real git
recorded. The contract suite replays each transcript over the process fake
and over GitFake and starts no program. The worktree, source-state and
revision tests use the fake.
The three GitPython users now run git commands through the runner, so the
git fake sees every start. GitPython leaves the dependencies and the
knowledge base. commit_snapshot gives the same commit id with plumbing.
Callers may set GIT_AUTHOR_DATE and GIT_COMMITTER_DATE.
The git row of devops ci records every scenario with the real git outside
pytest and fails when a committed transcript differs. It takes 3.5 s and
runs in the static job.
…teral (#2146)

GitFake finds a record by the arguments, the directory, the standard input
and the environment, so a commit with another message, author or date has no
record. The recorder keeps the environment and runs git with no user or
system configuration file. The host name and the system directories count as
host data.

commit_snapshot takes each path as a file name and reads no attributes file of
the user. pull_tracking raises the reason of git when git config --get fails
with a status other than 1. The golden-set test and a new test file start the
real git. The clone tests assert on known_hosts and patch no private name. The
git fake refuses a shell string and bytes as the process guard does.
@dan-petty dan-petty added the type/test Type test: a new or changed test label Oct 30, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Review findings for the ship stage, and what was done.

Fixed (tests first, then the cause):

  • GitFake ignored the standard input and the environment (major). The record key now holds both. The recorder keeps the environment of a call. New tests: a commit with another message, author, committer e-mail or date has no record. The process-fake replay compares them too. The finding named call.input; the field is call.stdin.
  • The golden-set test lost its check of the file content (part of the same finding). The fake cannot see file content, so that test and a new tests/test_git_commit_snapshot.py start the real git again, with the len(commits) == 1 check back (rev-list --count).
  • Patches of the private _ensure_known_host (major). The new known_hosts fixture points HOME at tmp_path, and the tests assert on the written file. Three sites in tests/test_git_operations.py and three in tests/test_ssh_host_keys.py changed. The remaining patch calls in tests/test_ssh_host_keys.py (Path.mkdir and logger.warning) are old and stdlib or logger edges; I left them.
  • The recorder was not hermetic (major). It sets GIT_CONFIG_NOSYSTEM and GIT_CONFIG_GLOBAL for the child. Test: tests/test_git_recording.py (a user file with pull.ff and core.autocrlf is not read).
  • commit_snapshot staged globs and read the attributes file of the user (major). It now runs --literal-pathspecs and -c core.attributesFile=/dev/null. Tests with the real git: a [ab].py path stages only that file, and a user attributes file with * text leaves the commit id the same. The pinned id 63b6e3c0... is unchanged. Limit: an attributes file inside the snapshot directory itself is still read by git; it is content of the caller.
  • _tracking_remote swallowed a failed git config --get (minor). Only status 1 means "unset". Any other status raises GitOperationError. Test with status 128.
  • The git fake did not refuse a shell string or bytes (minor). It now shares started_words with the root conftest (tests/support/started_programs.py). Tests for both forms. The unused _started_program left the conftest.
  • host_data_in missed the host name and system directories (minor). It now checks the host name (full and short) and /srv /opt /etc /run /usr /media /private /Volumes, with a boundary so refs/heads/etc/x is no host path.
  • The archived tasks.md kept a pending step (minor). The line is gone. The follow-up issue numbers moved to the proposal. A section for these fixes was added.

Not fixed: none.

Checks:

  • Full uv run devops ci: all 20 checks pass. The test check (pytest and coverage) took 222 s (3m 42s). The whole run took 3m 52s. The new git row took 26 s inside that run.
  • uv run devops ci fail-to-pass --base origin/main could not replay: the base has GitPython, and the replay fails to import tests.support.fakes.git ("No module named 'git'"). The tool says to merge a change to the test harness in a pull request that is not a fix. This is a test(git) pull request, so it is not a fix pull request and the check does not apply.
  • Targeted tests ran green before and after the rebase on origin/main 0232e3e.
  • devops ci --only git shows the 19 transcripts match git 2.55.0.

Filed: a scope label for git is missing in .github/labels.yml (devops pr create warned). Intake issue was opened.

The tests read the real user name. A runner user named runner matched the
text of two tests.
@dan-petty
dan-petty marked this pull request as ready for review October 30, 2026 20:33
@dan-petty
dan-petty merged commit 72a1f58 into main Oct 30, 2026
19 checks passed
@dan-petty
dan-petty deleted the test/2146-one-git-seam-and-fake branch October 30, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/test Type test: a new or changed test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(git): one git seam answers tests from recorded git transcripts, with a contract suite that replays them

1 participant