Skip to content

tests/conftest.py: git() runs git under a default identity given as -c config, never as environment, so the seven tests that commit through it with none of their own no longer die with Author identity unknown where git cannot work one out, and no call site's own -c user.name or exported identity is overridden (#279) - #310

Merged
brettheap merged 4 commits into
mainfrom
fix/tests-git-identity
Oct 12, 2026

Conversation

@brettheap

@brettheap brettheap commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openreposhape-4 (openRepoShape-4)
Claim: #279 (comment)

What

tests/conftest.py's git() now runs git -c "user.name=openRepoShape tests" -c [email protected] <args>. The two values are IDENTITY_NAME and IDENTITY_EMAIL, defined once next to FILE_PROTOCOL; run_script's four setdefaults reuse them (same values, so a pure refactor), so conftest names the default once, for git() and run_script. Nine other test files still spell the same pair for their own commits, and GIT_IDENTITY in tests/test_shape_doctor.py is among them; none is touched.

A second file, tests/test_git_helper_identity.py (10 tests, added after review), holds the default and its precedence on a runner that exports an identity as well as one that does not.

The branch carries four commits: the helper change, then the review's fix round (the test file, and the ranking comment corrected), then a second fix round (a tenth test, the four variables named in the ranking), then a re-wrap of one comment paragraph to 79 columns with no word changes. The squash takes the final subject.

Why

git() gave git no identity, so a test that commits through it with none of its own depends on git guessing one from the passwd entry and a hostname with a domain. Where git cannot, seven tests die with Author identity unknown: stage_unmerged's commit-tree in three tests of tests/test_shape_doctor.py, commit in three of tests/test_pin_validator.py and one of tests/test_scaffold_e2e.py. CI does not hit it because each of its three jobs exports GIT_AUTHOR_* and GIT_COMMITTER_* (.github/workflows/tests.yml, the "git identity for the scaffolded commits" step of the tests, tests-windows and tests-macos jobs), so git never has to guess.

Why config and not environment. GIT_AUTHOR_NAME and GIT_COMMITTER_NAME outrank user.name, so a default in env would silently replace the identity of every call site that gives its own -c user.name=...: as_human's Source Human, and -c user.name=t -c user.email=t@t, the commonest spelling in the suite. (make_source_repo's commit() runs git itself with its own environment and never goes through git(), so it is not one of them.)

Where the default ranks, strongest first: the four GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL where exported in the environment, each for its own role; a later -c on the same command line, which is how a call site's own -c user.name=... beats it; the default; then every identity read from a config file, global, system or repository-local. An exported EMAIL is not in the top group: git reads it only where no user.email is set, so the default's address hides it ([email protected] git -c user.name=DEF -c [email protected] commit records DEF <[email protected]>). So the default fills a gap and overrides no call site and none of the four variables, but it does outrank a developer's own ~/.gitconfig identity: a commit through git() that gives no identity now records openRepoShape tests where it used to record the developer. That is harmless here: no test reads such an author, and nothing in the suite writes user.name into a repository's config. A test that needs its own identity to take effect through git() passes it as -c, or exports the four variables. Probed in a scratch repository (git 2.43.0, empty GIT_CONFIG_GLOBAL, GIT_CONFIG_NOSYSTEM=1, the four variables and EMAIL unset):

the call records
a bare git commit Author identity unknown
the default as -c only openRepoShape tests
the default, then the call's own later -c user.name=t -c user.email=t@t t
the default, then an exported GIT_AUTHOR_* / GIT_COMMITTER_* the exported one
the default, then an exported EMAIL only the default (EMAIL ranks below it)
REJECTED: the default exported in env, the call's own -c user.name=t openRepoShape tests (the call asked for t)

Tests

The seven are the regression tests for "a default exists", and they catch it only on a machine git cannot guess an identity on. CI exports an identity, which outranks the default and any call's own -c, so on CI the default is invisible: nothing else in the suite saw the precedence, and a helper that put the default in the environment, or after a call's own -c, passed every existing test. tests/test_git_helper_identity.py closes that. Each test removes the four identity variables, EMAIL and the config injectors and isolates git's config, so it is identity-less on every runner. It checks that a call with no identity records the default; that a leading -c that gives no identity (core.protectNTFS=false) leaves the default in place; that git("-c", "user.name=t", ...) and as_human beat it; that an exported identity beats both; and that commit-tree, an annotated tag, a merge, a cherry-pick and a rebase pick it up. It touches the helper alone: no autouse guard, no other test isolated.

Five mutants of git(), each run in a scratch copy under an exported identity (openRepoShape CI) and under none, with the same result both ways:

mutant caught by
M1 the pairs dropped the no-identity test, the unrelated--c test, and the commit-tree, tag, merge, cherry-pick and rebase tests (7 failed)
M2 the default moved into env the -c user.name=t test, the as_human test, the cherry-pick and rebase tests (4 failed)
M3 the email pair omitted the same seven as M1
M4 the default placed after the call site's own leading -c the same four as M2
M9 the default skipped when the call already carries any other -c the unrelated--c test alone (1 failed); it survived the first nine tests

The control (the head) passes all ten, and the exported-identity test passes under every mutant, as it must.

Runs, gh shim first on PATH (it logs and exits 97), git-filter-repo 2.47.0, --basetemp under scratch:

  • On the head: tests/test_git_helper_identity.py -q, identity-less: 10 passed; the same with an identity exported: 10 passed.
  • On the second head, a2d6dc1: tests/test_git_helper_identity.py tests/test_shape_doctor.py tests/test_pin_validator.py tests/test_scaffold_e2e.py tests/test_repo_hygiene.py -q, identity exported as usual: 364 passed, 3 skipped (the 3 are the Windows-only PowerShell test). The head adds one test and changes comments and one docstring in tests/conftest.py; the four other files were not run again.
  • The seven, identity-less, on the first head: 7 failed on main's bytes (ede15ce), 7 passed on 5e182dc. tests/test_shape_doctor.py tests/test_pin_validator.py tests/test_scaffold_e2e.py tests/test_family.py tests/test_update_shape.py, identity-less, on 5e182dc: 481 passed, 3 skipped.
  • Through the helper itself, identity-less: git("-c", "user.name=t", "-c", "user.email=t@t", "commit", ...) records t, as_human records Source Human, a call with no identity records openRepoShape tests, and a bare git("commit-tree", ...) succeeds.
  • No --help text changed, so docs/cli.md is unchanged. macOS and Windows have not run the latest head yet. Nothing in it is platform-specific: the two -c pairs go through a list-form subprocess.run, with no shell and no stdin, and the new tests use plain file names.

Landing notes

Closes #279

🤖 Generated with Claude Code

… `-c` config, never as environment, so the seven tests that commit through it with none of their own no longer die with `Author identity unknown` where git cannot work one out, and no call site's own `-c user.name` or exported identity is overridden (#279)

`git()` ran git with no identity, so a test that committed through it and gave
none of its own depended on git guessing one from the passwd entry and a
hostname with a domain. Where git cannot (a container whose hostname has no
domain), seven tests died with `Author identity unknown`: `stage_unmerged`'s
`commit-tree` in three tests of tests/test_shape_doctor.py, `commit` in three
tests of tests/test_pin_validator.py and one of tests/test_scaffold_e2e.py.
CI never met it because each of its three jobs exports the four
`GIT_AUTHOR_*` and `GIT_COMMITTER_*` variables, so git never has to guess.

`git()` now runs `git -c user.name=<default> -c user.email=<default> <args>`.
The default is `IDENTITY_NAME` and `IDENTITY_EMAIL` (`openRepoShape tests`,
`[email protected]`, the spelling the suite already used), defined
once in tests/conftest.py and reused by `run_script`'s four `setdefault`s,
which keep the same values.

The default is CONFIG and not environment because git ranks an exported
`GIT_AUTHOR_NAME` or `GIT_COMMITTER_NAME` above `user.name`. A default put in
an `env` would replace the identity of every call site that gives its own
`-c user.name=...` (the commonest spelling in the suite, `-c user.name=t -c
user.email=t@t`) and of `as_human`'s and `make_source_repo`'s `Source Human`,
which commit as that on purpose. As `-c` ahead of the verb it is the weakest
identity there is: a later `-c` on the command line wins over it, and an
identity the operator or CI exports wins over both. Every call keeps exactly
the identity it had; only a call that had none gains one.

Proved identity-less (the four variables and `EMAIL` unset, an empty
`GIT_CONFIG_GLOBAL`, `GIT_CONFIG_NOSYSTEM=1`, git 2.43.0):

- A bare `git commit` fails with `Author identity unknown`; with the default
  as `-c` it records `openRepoShape tests`; with the call's own later `-c
  user.name=t` it records `t`; with an exported identity it records that one;
  and the rejected design, the default in the environment, records the default
  where the call asked for `t`.
- Through the helper: `make_source_repo`'s three commits are authored by
  `Source Human`, a `git("-c", "user.name=t", ..., "commit")` by `t`,
  `as_human` by `Source Human`, a call with no identity by `openRepoShape
  tests`, and a bare `commit-tree` succeeds.
- The seven tests: 7 failed on main's bytes (ede15ce), 7 passed on these.
- tests/test_shape_doctor.py tests/test_pin_validator.py
  tests/test_scaffold_e2e.py tests/test_family.py tests/test_update_shape.py
  identity-less: 481 passed, 3 skipped (the Windows-only PowerShell test);
  nothing else in them needed an identity.
- The normal run, identity exported, over tests/test_shape_doctor.py
  tests/test_pin_validator.py tests/test_scaffold_e2e.py
  tests/test_repo_hygiene.py: 355 passed, 3 skipped (the same three).

Not here, and left to follow-ups: an autouse guard that isolates git's config
for the whole suite (it overlaps the `gh` guard of #296), and one identity-less
run of the whole suite.

Lane: openreposhape-4 (openRepoShape-4)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 12, 2026

Copy link
Copy Markdown

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 14 hours and 31 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewer's Guide

The test Git helper now supplies a shared default identity via command-line configuration, allowing identity-less commits to work on systems where Git cannot infer an identity while preserving call-site and environment overrides; script-launch identity defaults are refactored to use the same constants.

File-Level Changes

Change Details Files
Provide a stable default Git identity for helper-mediated commits without overriding explicit identities.
  • Define shared default name and reserved email constants.
  • Prepend git invocations with -c user.name and -c user.email configuration.
  • Rely on Git precedence so later call-site -c options and exported identity variables remain authoritative.
  • Document why configuration is used instead of environment variables and the affected identity-less commit paths.
tests/conftest.py
Reuse the shared identity constants for scripts launched by the test harness.
  • Replace duplicated identity literals in the four setdefault calls.
  • Preserve caller-provided identity environment variables.
tests/conftest.py

Assessment against linked issues

Issue Objective Addressed Explanation
#279 Ensure commits made through the shared tests/conftest.py git() helper succeed even when Git cannot infer an author or committer identity. ✅
#279 Preserve identities explicitly supplied by individual call sites or inherited from the environment, rather than overriding them with the helper's default identity. ✅
#279 Provide a regression guard that forces the full test suite to run without relying on developer or CI Git configuration, exposing any future identity-less commits. ❌ The PR does not implement the issue's optional autouse configuration-isolation guard or run the entire suite under such a guard. It only adds a default identity to git() and reports partial identity-less test runs.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

brettheap and others added 3 commits October 12, 2026 01:16
…ntity and its precedence on a runner that exports an identity too, and the comment on the default now says where it ranks, above a config file's `user.name` and below a later `-c` and an exported identity (#279)

The review of 5e182dc found two things wrong with it.

Nothing guarded the helper's default or its precedence. CI exports all four
`GIT_AUTHOR_*` and `GIT_COMMITTER_*` variables in each of its three jobs, and
an exported identity outranks both the default and a call site's own `-c`, so
on CI the default is invisible: a helper that lost it stays green there, and
one that put it in the environment, or after a call site's own `-c`, stays
green everywhere. Identity-less, the seven tests catch the first two of those
mutants and not the last two, and no other test reads an author through the
helper. tests/test_git_helper_identity.py removes the four variables, `EMAIL`
and the config injectors itself and isolates git's config (an empty
`GIT_CONFIG_GLOBAL`, `GIT_CONFIG_NOSYSTEM=1`), so it is identity-less on every
runner. It checks that a call with no identity records the default; that a
call's own `-c user.name=t -c user.email=t@t` and `as_human`'s `Source Human`
beat it; that an exported identity beats both; and that `commit-tree`, an
annotated tag, a merge, a cherry-pick and a rebase pick it up, the last two
as the committer of a commit whose author they keep. It touches the helper
alone: no autouse guard, no other test isolated.

Verified against four mutants of `git()`, each in a scratch copy, under an
exported identity and under none. Dropping the pairs, and omitting the email
pair, fail the no-identity test and the five verb tests; moving the default
into `env`, and placing it after a call site's own leading `-c`, fail the
`-c user.name=t` test, the `as_human` test, the cherry-pick test and the
rebase test. The control passes all nine.

The comment on the default said it was "the weakest identity there is" and
that every call keeps the identity it had. That was wrong against a config
FILE: a `-c` on the command line outranks a global, system or repository-local
`user.name`, so a commit through `git()` that gives no identity now records
`openRepoShape tests` where it used to record the developer. It ranks below an
exported identity and below a later `-c`, above any config file. That is
harmless here, because no test reads such an author and nothing writes
`user.name` into a repository's config, and the comment now says it, and says
that a test needing its own identity passes it as `-c` or exports it. The
same comment named `make_source_repo` as a case the environment design would
have broken; its `commit()` runs git itself with its own environment and never
goes through `git()`, so the contested call sites are `as_human` and the
`-c user.name=` spellings, and the comment says those. And "the suite names its
default once" said too much: this file names it once, for `git()` and
`run_script`, and nine other test files still spell the pair.

Lane: openreposhape-4 (openRepoShape-4)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ough a call that carries an unrelated `-c`, and the ranking comment names the four `GIT_*` variables that outrank the default, an exported `EMAIL` not being one of them (#279)

The re-check of a2d6dc1 left three nits.

A mutant of `git()` survived all nine tests: the default skipped whenever the
call already carries any other `-c`, on the guess that the call gave its own
identity. No call site is affected today, since no identity-needing call with
no identity of its own carries a `-c`, so it was a gap in the test and not a
live bug. `test_an_unrelated_dash_c_leaves_the_default_in_place` closes it: a
`git("-c", "core.protectNTFS=false", "commit", ...)` that gives no identity
records the default. The mutant fails exactly that test and the control
passes all ten, both under an exported identity and under none; the four
mutants of the last round fail as before, the two that drop a pair now also
failing the new test.

The ranking comment on `IDENTITY_CONFIG` said an identity "EXPORTED in the
environment" is strongest. That holds for the four `GIT_AUTHOR_NAME`,
`GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME` and `GIT_COMMITTER_EMAIL`, each for
its own role, and not for `EMAIL`: git reads it only where no `user.email` is
set, so `[email protected] git -c user.name=DEF -c [email protected]
commit` records `DEF <[email protected]>`, and the same call with no default
records `[email protected]`. The comment, the `git()` docstring, the test
file's header and the exported-identity test's docstring now say which
variables outrank the default and that `EMAIL` does not.

The `idless` fixture's docstring said `HOME` is moved because git falls back
to `~/.gitconfig` where `GIT_CONFIG_GLOBAL` is "unset on some builds". The
fixture sets it itself; the reason is that git older than 2.32 ignores
`GIT_CONFIG_GLOBAL`. It says that.

tests/test_git_helper_identity.py: 10 passed identity-less and 10 passed with
an identity exported. tests/conftest.py changes in comments and one docstring
only.

Lane: openreposhape-4 (openRepoShape-4)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…columns, which b15d167 left 80 and 112 wide, with no word changes (#279)

b15d167 re-filled the last paragraph of the comment on `IDENTITY_CONFIG` and
left two of its lines past the 79-column wrap the rest of the comment keeps:
one 80 columns wide, one 112. The tail is re-wrapped to 79 or fewer. Every
word is unchanged and in the same order; `git diff b15d167 -w
--word-diff=porcelain` shows only the line breaks moving, and the word streams
of the whole file, comment markers removed, are identical before and after
(3366 words). Every other line is as it was, including the two long lines
main already had (`def git(...)` and the `org: str = ...` signature).

tests/test_git_helper_identity.py, identity-less: 10 passed.

Lane: openreposhape-4 (openRepoShape-4)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sonarqubecloud

Copy link
Copy Markdown

@brettheap
brettheap merged commit 7591455 into main Oct 12, 2026
5 checks passed
@brettheap
brettheap deleted the fix/tests-git-identity branch October 12, 2026 12:15
brettheap added a commit that referenced this pull request Oct 12, 2026
…, #253 via #264, #302 via #318, #288 via #309, #279 via #310, #306 via #311, #334 via #336, #239 via #269, #243 via #268, #321 via #335) into fix/adopt-record-submodule-placement

Brings in the twelve commits from c7c02fa to a1b3a4b on top of 71b58a1,
merged by sha. No rebase. Among the files this branch changes:
346079d (#216) and e43fa95 (#243) change adopt-project.py; 34ecbc2 (#260)
changes scripts/shape_materialize.py; 87373a6 (#306) changes
shape-doctor.py and tests/test_shape_doctor.py; 7491530 (#288) changes
AGENTS.md and tests/test_repo_hygiene.py.

Two conflicts, each resolved keeping both sides:

- adopt-project.py, the module docstring's `execute` paragraph. #243 ends
  "the root's only submodules are the two leg mounts, each at the commit
  pushed to its leg."; this branch follows "two leg mounts." with "The
  split's `project.yaml` records the leg each source submodule kept in a
  leg was answered into, under `submodules:`, for `shape-doctor.py` to
  check it against." The merge has #243's sentence, then this branch's,
  re-wrapped to the paragraph's width. The module docstring is not in
  `--help` (docs/cli.md holds neither sentence).
- tests/test_repo_hygiene.py, `test_agents_md_is_short_enough_to_be_read`.
  Each side moved the AGENTS.md cap from 464 and wrote a paragraph
  saying why: #288 to 477, for thirteen lines, and this branch to 472,
  for eight. AGENTS.md itself merged cleanly and holds both: 485 lines,
  main's 477 plus this branch's +9 -1. The merge keeps #288's paragraph
  word for word, then this branch's, renumbered "2026-10-12: 477 -> 485"
  because it now follows #288's, and asserts `<= 485`.

`git merge-tree --write-tree` of the two parents gives the same tree in
every file but these two.

Checked:

- adopt-project.py: `_commit_the_split` was changed by both sides, in
  hunks that do not touch. #243 clones the assembly with `--template=`;
  this branch builds `append` with the `submodules:` record. The merged
  function holds both, and each side's text is unchanged. Every other
  definition one side changed is that side's text.
- shape-doctor.py: #306 changes `validator_row` and `run_validator`.
  This branch's placement functions, F1's
  `gitmodules_the_record_answers` among them, are this branch's text.
- No top-level name is bound twice in adopt-project.py,
  scaffold-project.py, scripts/repo_shape.py,
  scripts/shape_materialize.py, shape-doctor.py, validate-manifest.py,
  update-shape.py, scripts/family.py or scripts/bump-leg.py. Each merged
  module's names are the base's plus what either side added.
- AGENTS.md is main's plus exactly this branch's changed lines.
- The branch's diff against main is #189 alone: 12 files, +1694 -157. That
  is +1670 at 27d039b, plus F1's fix and test (+23), plus the one line
  the docstring re-wrap adds.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 12, 2026
… of main's commits merge with no conflict, among them #243's template-less clone of the assembly and #216's literal `git grep` in adopt-project.py, and #260's one-pass `render` in shape_materialize.py

origin/main moved 71b58a1 -> 8cdca5e. It was merged by sha, as the
coordinator asked for e43fa95 or later:
- c7c02fa (#299 via #315), scripts/family.py;
- 346079d (#216 via #228), adopt-project.py: `plan`'s follow-up
  `git grep`;
- 34ecbc2 (#260 via #316), scripts/shape_materialize.py: `render`
  substitutes in one pass;
- 86da808 (#253 via #264), scripts/bump-leg.py;
- 6f4ce47 (#302 via #318), scripts/family.py;
- 7491530 (#288 via #309), AGENTS.md, README, docs and
  scaffold-project.py's --help;
- 7591455 (#279 via #310), tests/conftest.py: `git()` takes its default
  identity as `-c` config;
- 87373a6 (#306 via #311), shape-doctor.py;
- 8a14ac9 (#334 via #336), tests/test_update_shape_landing.py;
- c1b6732 (#239 via #269), update-shape.py;
- e43fa95 (#243 via #268), adopt-project.py: the assembly root is cloned
  with `--template=`, and the verification refuses a mount whose gitlink
  is not the commit pushed to its leg (`adopt-mount-commit`);
- a1b3a4b (#321 via #335), tests/test_git_output_decoding.py;
- 8cdca5e (#295 via #312), the template's scripts/validate-pins.py.

`git merge-tree` and this merge give the same tree, 07e6b49.
adopt-project.py, scripts/shape_materialize.py and
tests/test_adopt_ignored_shape_files.py auto-merge. In the last of these
main's 346079d and this branch's 86a5e30 change different cases.

Checked on the merged tree:
- AST (fin183g/names.py, base 71b58a1): no top-level name is bound twice
  in adopt-project.py, scaffold-project.py, scripts/repo_shape.py or
  scripts/shape_materialize.py, and none is loaded but bound nowhere.
  Main changed the signature of no function this branch calls.
- Every sentence 86a5e30 changed is still there: in `_through`, in
  `_link_parts`, in `_verify`'s `_resolve` (which e43fa95's
  `adopt-mount-commit` leaves as it was), and in the three test files.
- `_commit_the_split` now clones the assembly with `--template=`. The
  next commit, F3, reads what that clone holds in its own `.git`, which
  is why F3 comes after this merge.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment