From 823c06c19173155a4f690424c3370b12d6052f25 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 9 Jul 2026 06:33:19 +0000 Subject: [PATCH 1/2] test: cover default signoff regex for bot and regular names The existing SignoffValidator tests pass an inline regex, so the default pattern in rules_catalog was never exercised. Build the rule via RuleBuilder and assert the shipped default: - accepts a bracketed bot name (Signed-off-by: dependabot[bot] <...>) - accepts a regular Name signoff - rejects a message with no signoff trailer --- tests/engine_test.py | 49 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/tests/engine_test.py b/tests/engine_test.py index 7cea27dd..43c8fccc 100644 --- a/tests/engine_test.py +++ b/tests/engine_test.py @@ -23,7 +23,7 @@ ForcePushValidator, AiAttributionValidator, ) -from commit_check.rule_builder import ValidationRule +from commit_check.rule_builder import ValidationRule, RuleBuilder # String constants used across tests (defined once to avoid duplication) GIT_CONFIG_VALUE = "commit_check.engine.get_git_config_value" @@ -648,6 +648,18 @@ def test_subject_length_validator_min_too_short(self): class TestSignoffValidator: + @staticmethod + def _default_signoff_rule(): + """Build the require_signed_off_by rule from the default catalog regex. + + Unlike the tests that pass an inline regex, this exercises the actual + default pattern shipped in rules_catalog, so a regression in that + pattern is caught here. + """ + builder = RuleBuilder({"commit": {"require_signed_off_by": True}}) + rules = builder.build_all_rules() + return next(r for r in rules if r.check == "require_signed_off_by") + @pytest.mark.benchmark def test_signoff_validator_valid(self): """Test SignoffValidator with valid signoff.""" @@ -662,6 +674,41 @@ def test_signoff_validator_valid(self): result = validator.validate(context) assert result == ValidationResult.PASS + @pytest.mark.benchmark + def test_default_signoff_accepts_bot_name(self): + """Default regex accepts a bracketed bot name such as dependabot[bot].""" + validator = SignoffValidator(self._default_signoff_rule()) + context = ValidationContext( + stdin_text=( + "chore: bump dep\n\n" + "Signed-off-by: dependabot[bot] " + ) + ) + + result = validator.validate(context) + assert result == ValidationResult.PASS + + @pytest.mark.benchmark + def test_default_signoff_accepts_regular_name(self): + """Default regex accepts a regular name and email signoff.""" + validator = SignoffValidator(self._default_signoff_rule()) + context = ValidationContext( + stdin_text="feat: add feature\n\nSigned-off-by: John Doe " + ) + + result = validator.validate(context) + assert result == ValidationResult.PASS + + @pytest.mark.benchmark + def test_default_signoff_rejects_missing_signoff(self): + """Default regex rejects a message without any signoff trailer.""" + validator = SignoffValidator(self._default_signoff_rule()) + context = ValidationContext(stdin_text="feat: add feature") + + with patch("commit_check.util._print_failure"): + result = validator.validate(context) + assert result == ValidationResult.FAIL + @pytest.mark.benchmark def test_signoff_validator_missing_signoff(self): """Test SignoffValidator with missing signoff.""" From 14401cd70b1a06bdcdd99263e0524c91efab70a8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Jul 2026 06:45:38 +0000 Subject: [PATCH 2/2] ci: auto fixes from pre-commit.com hooks --- tests/engine_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/engine_test.py b/tests/engine_test.py index 43c8fccc..885a39f9 100644 --- a/tests/engine_test.py +++ b/tests/engine_test.py @@ -680,8 +680,7 @@ def test_default_signoff_accepts_bot_name(self): validator = SignoffValidator(self._default_signoff_rule()) context = ValidationContext( stdin_text=( - "chore: bump dep\n\n" - "Signed-off-by: dependabot[bot] " + "chore: bump dep\n\nSigned-off-by: dependabot[bot] " ) )