A fixture that clones a bare repository is assumed to be deterministic
Test EffectivenessInvariantsExample-Based TestsDifferential Testing
https://medlab.sublayer.space/c/git-default-fixture/
now fails loudly The test job runs with init.defaultBranch set to a branch name no developer uses, so a fixture that reads the machine's git default fails at the push; and the fixture that caused this names main explicitly.
What broke
Wortling is a station service that turns language material a learner captures into spaced-repetition cards. A change to it arrives as a pull request, and a pull request runs the project's test suite: one job that checks out the branch, checks the base, installs dependencies, lints, and runs the tests.
A change adding a build gate carried seven new tests for the gate. Each of them starts from a fixture that builds a small git repository: it makes a seed repository, commits a file, pushes it to a bare repository standing in for the forge, and clones that bare repository into a working copy the test then operates on.
The bare repository was created without saying which branch its head should point at. Git fills that in from a machine setting, init.defaultBranch, and the fixture assumed the value it found on the machine it was written on.
How it showed
The pull request's test job failed with four of the seven new tests red and the rest of the suite green:
FAILED tests/test_build_gate.py::test_a_main_commit_passes Command '['git', 'rev-parse', 'HEAD']' returned non-zero exit status 128. FAILED tests/test_build_gate.py::test_an_unmerged_branch_head_is_refused Command '['git', 'commit', '--quiet', '-am', 'never pushed to the forge']' returned non-zero exit status 1. FAILED tests/test_build_gate.py::test_an_earlier_main_commit_passes_and_says_how_far_behind Command '['git', 'rev-parse', 'HEAD']' returned non-zero exit status 128. FAILED tests/test_build_gate.py::test_a_branch_diverged_from_main_is_refused AssertionError: assert 'commits this build lacks: 1' in 'build: ... main commits this build lacks: 2'
4 failed, 172 passed
None of the four failures reached the gate the tests were written for. Three died on git plumbing: a clone with no commit checked out has no head to ask for, and a commit with nothing staged returns 1. The fourth ran the gate and counted two commits where the fixture's arithmetic expected one, because the clone had started from the wrong place.
The mechanism is one setting, and it is different on the two machines:
developer's git (2.50.1) git init --bare -> HEAD: refs/heads/main runner's git (2.55.0) git init --bare -> HEAD: refs/heads/master runner system config init.defaultBranch: not set
The runner column is measured in the image the job runs in, turbot-ci:20261010-2, whose git the run's own log prints as 2.55.0. A first reading of this table took the version from the runner process instead of the job container and said 2.54.0; both are the same defect one level down, a version read from the machine in hand rather than the machine that ran the job.
Cloning a bare repository whose head points at a branch it does not contain checks out nothing, so on the runner the working copy had no files and no head.
The reproduction is exact: the same four tests fail, and the other three pass, when the suite is run on the author's machine with init.defaultBranch set to master. Every test in the file passes without that setting.
What was watching
The tests were the sensor and they did fire: the suite is what caught this, on the first push. Measured from the commit that introduced the fixture (09:41:31) to the run's creation (09:45:18) is three minutes forty-seven seconds, and from the head the run built (09:43:51) it is one minute twenty-seven seconds.
What was absent is a second environment. Every run of these tests, before the push, used the author's machine and the author's git, so the fixture's dependence on a machine setting was invisible: on that machine it was not a dependence, it was the only behaviour there was. A test suite run in one environment cannot see a difference between its own assumptions and the world.
The failure messages pointed at git rather than at the assumption. rev-parse HEAD returning 128 from a directory that plainly exists reads as a plumbing bug; the fixture's git init --bare line, three functions above, is the cause, and nothing in the output named it.
The detecting sensor was a person reading the red run and recognising the developer-versus-runner shape from earlier incidents on this station.
Where it sits
This is a test-effectiveness case on an invariants failure.
The family is test-effectiveness because the fixture was a test of a test helper and it measured the machine. It is invariants because the property a fixture needs is "the same on every machine", and nothing stated it.
Example-based tests were present and blind: the example was written against one environment and its determinism was never a claim anyone had to make. Differential testing was absent, and it is the sensor this needs: the same tests, run in two environments that differ in one setting, would have disagreed immediately.
This is the third organ of one family on this station. Earlier cases record a runner that lacked the tools a developer had installed, and a runner that carried tools a developer did not. The family is "the machine the test was written on is assumed to be the machine that runs it"; this time the difference was a git setting, and the earlier controls did not look at it.
What we did
The fixture now names the branch explicitly when it creates the bare repository, so the working copy always checks out main and the tests measure the gate instead of the machine.
The class got a separate change, because the fix above helps this fixture and not the next one: the test job now runs with init.defaultBranch set to trunk, a value no developer uses. A fixture that reads the machine's default now disagrees with the job whichever way it leans, at the push, where the author can see it.
What now fails loudly
Two things, and both were watched.
The fixture's pin makes the seven gate tests pass with init.defaultBranch set to trunk, where they failed before it: measured, 7 passed against 4 failed on the same setting.
The job's setting is the class control. Measured three ways: the project's suite on the default branch passes with it, 169 tests; the gate tests as they were at the failing commit fail four of seven with it, the same four as the run; and the gate tests with the fixture pinned pass seven of seven.
What is still only a habit: nothing stops the next fixture from reading some other machine setting. The job pins one git setting, and a suite can read a clock, a locale, a user name or a kernel.
One limit worth stating: the fix and this control are pull requests. Until they merge, the default branch still runs with whatever git default the machine provides, which is the configuration this case is about.