Skip to content

Prevent MagicMock from leaking into global gitconfig in tests#83

Merged
max-tet merged 2 commits into
mainfrom
fix/mock-leaks-gitconfig
May 26, 2026
Merged

Prevent MagicMock from leaking into global gitconfig in tests#83
max-tet merged 2 commits into
mainfrom
fix/mock-leaks-gitconfig

Conversation

@max-tet
Copy link
Copy Markdown
Collaborator

@max-tet max-tet commented May 26, 2026

Summary

  • orchestrator.main() ran git config --global user.name/.email with settings.effective_git_name / settings.git_email. Tests patched get_settings with a bare MagicMock, leaving those as auto-attributes — truthy → guard passed → subprocess stringified the mock and wrote MagicMock/mock.effective_git_name/<id> into the developer's real ~/.gitconfig, polluting commit authorship across all repos.
  • Extracted git identity setup into _configure_global_git_identity so tests can patch a single symbol.
  • Added isinstance(str) guard so a non-string identity fails loudly instead of mutating global config.
  • Fixed existing tests: set string identities in _mock_settings helper and patch _configure_global_git_identity in all main() tests.

Test plan

  • pytest tests/test_orchestrator.py — 28 passed
  • Full suite — 293 passed
  • Verified ~/.gitconfig unchanged after full suite run

max-tet added 2 commits May 26, 2026 14:47
orchestrator.main() called `git config --global user.name/.email` with
values pulled off the `settings` object. Tests that patched `get_settings`
with a MagicMock left `effective_git_name` and `git_email` as auto-generated
MagicMock attributes — truthy, so the guard passed — and subprocess
stringified them ("MagicMock/mock.effective_git_name/<id>") into the
developer's real ~/.gitconfig, polluting subsequent commit authorship.

- Extract git identity setup into `_configure_global_git_identity` so tests
  patch a single symbol.
- Add isinstance(str) guard so a non-string identity fails loudly instead
  of corrupting global config.
- Fix existing tests: set string identities on the mock settings helper
  and patch `_configure_global_git_identity` in all `main()` tests.
Five TestMain tests duplicated the same ~10-line patch stack. Collapse
into a single `_patched_main` helper that uses ExitStack to apply all
common patches and yields the mocks dict for per-test assertions.
@max-tet max-tet merged commit 871dc2d into main May 26, 2026
3 checks passed
@max-tet max-tet deleted the fix/mock-leaks-gitconfig branch May 26, 2026 13:09
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.

1 participant