test(conftest): make GPG-signing fixture work on Windows#1962
Open
bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
Open
test(conftest): make GPG-signing fixture work on Windows#1962bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Make the GPG-related bump tests work on Windows hosts where Gpg4win and Git for Windows ship separate
gpgbinaries with separate keyrings.Currently, the
tmp_commitizen_project_with_gpgfixture fails on a typical Windows developer machine for two reasons:_get_gpg_keyidparsesgpg --list-secret-keysoutput with a regex that only handles LF line endings. On Windows, gpg emits CRLF, so the regex never matches and the fixture asserts out atassert key_id.%APPDATA%\gnupg), butgit commit -Sinvokes the gpg bundled with Git for Windows (~/.gnupg). That gpg can't find the secret key and signing fails withgpg: skipped "<fingerprint>": No secret key.Changes
_get_gpg_keyidto parse the stablegpg --with-colons --list-secret-keysmachine-readable format. Field 9 of the firstfpr:line under asec:block is the primary key fingerprint per the gpg DETAILS specification. This is line-ending agnostic.tmp_commitizen_project_with_gpg, pingit config gpg.programto the absolute path of the gpg binary used to create the key (resolved viashutil.which("gpg")). This guarantees git uses the same gpg/keyring as the fixture on every platform.fprto 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-colonsparser produces the same fingerprint as the previous regex.Verification
Locally on Windows (Gpg4win 2.5.19 + Git for Windows 2.4.9):
test_bump_minor_increment_signed[*]andtest_bump_minor_increment_signed_config_file[*]error out during fixture setup (4 errors).Checklist
uv run poe lintclean