Skip to content

test(conftest): make GPG-signing fixture work on Windows - #1962

Open
bearomorphism wants to merge 1 commit into
commitizen-tools:masterfrom
bearomorphism:fix/test-gpg-windows
Open

test(conftest): make GPG-signing fixture work on Windows#1962
bearomorphism wants to merge 1 commit into
commitizen-tools:masterfrom
bearomorphism:fix/test-gpg-windows

Conversation

@bearomorphism

Copy link
Copy Markdown
Collaborator

Description

Make the GPG-related bump tests work on Windows hosts where Gpg4win and Git for Windows ship separate gpg binaries with separate keyrings.

Currently, the tmp_commitizen_project_with_gpg fixture fails on a typical Windows developer machine for two reasons:

  1. _get_gpg_keyid parses gpg --list-secret-keys output with a regex that only handles LF line endings. On Windows, gpg emits CRLF, so the regex never matches and the fixture asserts out at assert key_id.
  2. Even when a fingerprint can be extracted, the test key is created by the gpg in PATH (Gpg4win, %APPDATA%\gnupg), but git commit -S invokes the gpg bundled with Git for Windows (~/.gnupg). That gpg can't find the secret key and signing fails with gpg: skipped "<fingerprint>": No secret key.

Changes

  • Rewrite _get_gpg_keyid to parse the stable gpg --with-colons --list-secret-keys machine-readable format. Field 9 of the first fpr: line under a sec: block is the primary key fingerprint per the gpg DETAILS specification. This is line-ending agnostic.
  • In tmp_commitizen_project_with_gpg, pin git config gpg.program to the absolute path of the gpg binary used to create the key (resolved via shutil.which("gpg")). This guarantees git uses the same gpg/keyring as the fixture on every platform.
  • Add fpr to the codespell ignore list (pyproject.toml) so the gpg colon-output prefix used in the parser doesn't trip the spell check.

Behaviour on Linux / macOS is unchanged: shutil.which("gpg") returns the same gpg the subprocess call would have invoked anyway, and the --with-colons parser produces the same fingerprint as the previous regex.

Verification

Locally on Windows (Gpg4win 2.5.19 + Git for Windows 2.4.9):

  • Before: test_bump_minor_increment_signed[*] and test_bump_minor_increment_signed_config_file[*] error out during fixture setup (4 errors).
  • After: full suite passes — 1289 passed, 3 skipped, 2 xfailed.

Checklist

  • uv run poe lint clean
  • Existing test suite green locally on Windows

Two changes to the `tmp_commitizen_project_with_gpg` fixture and its
helper so that the GPG-related bump tests run reliably on Windows
hosts where `Gpg4win` and `Git for Windows` ship separate gpg
binaries and keyrings:
* `_get_gpg_keyid` now parses `gpg --with-colons` output instead
of relying on a regex over the human-friendly layout. The regex
required LF line endings, which gpg does not produce on Windows
(CRLF), so it always returned `None` and the fixture asserted out.
* The fixture pins `git config gpg.program` to the same gpg binary
it used to create the test key (resolved via `shutil.which`).
Otherwise `git commit -S` invokes the gpg shipped with Git for
Windows, which has a different keyring and reports
`gpg: skipped <fingerprint>: No secret key`.
Behaviour on Linux / macOS is unchanged because `shutil.which` and
`--with-colons` work identically there.
The codespell ignore list is extended with `fpr` so the gpg colon
output prefix used in the parser does not trip the spelling check.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecovBot commented May 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.23%. Comparing base (4b93a50) to head (096da69).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@## master #1962 +/- ##
=======================================
Coverage 98.23% 98.23% =======================================
Files 61 61 Lines 2779 2779 =======================================
Hits 2730 2730 Misses 49 49 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bearomorphism
bearomorphism marked this pull request as ready for review May 9, 2026 09:41
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@bearomorphism