From 4feabe48cdb7e676cae92b48d9e7f08cc4eeb67d Mon Sep 17 00:00:00 2001 From: Ruben Sanosh Date: Thu, 30 Jul 2026 16:16:21 -0600 Subject: [PATCH 1/2] test: add coverage for BodyValidator leading blank line edge cases --- tests/engine_test.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/engine_test.py b/tests/engine_test.py index dd1eff97..a6bd95bc 100644 --- a/tests/engine_test.py +++ b/tests/engine_test.py @@ -967,6 +967,50 @@ def test_validate_without_body(self): with patch("commit_check.util._print_failure"): result = validator.validate(context) assert result == ValidationResult.FAIL + + @pytest.mark.benchmark + def test_validate_with_leading_blank_lines_and_body(self): + """Test body validation with leading blank lines before body content. + + _get_commit_message() strips input before BodyValidator sees it, so + leading blank lines are removed and this collapses to a single line + with no separate subject/body it should FAIL. + """ + rule = ValidationRule(check="require_body") + validator = BodyValidator(rule) + context = ValidationContext(stdin_text="\n\nbody content") + + with patch("commit_check.util._print_failure"): + result = validator.validate(context) + assert result == ValidationResult.FAIL + + @pytest.mark.benchmark + def test_validate_with_leading_blank_lines_no_body(self): + """Test body validation with only leading blank lines and no content. + + After stripping, this becomes an empty message, which is treated as + having no commit message at all — it should PASS. + """ + rule = ValidationRule(check="require_body") + validator = BodyValidator(rule) + context = ValidationContext(stdin_text="\n\n") + + result = validator.validate(context) + assert result == ValidationResult.PASS + + @pytest.mark.benchmark + def test_validate_with_whitespace_only_message(self): + """Test body validation with a whitespace-only message. + + After stripping, this becomes an empty message, same as the + leading-blank-lines-only case — it should PASS. + """ + rule = ValidationRule(check="require_body") + validator = BodyValidator(rule) + context = ValidationContext(stdin_text=" \n ") + + result = validator.validate(context) + assert result == ValidationResult.PASS class TestMergeBaseValidator: From cd4a01861d2002be67fe44de58359848513e0775 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 22:22:33 +0000 Subject: [PATCH 2/2] ci: auto fixes from pre-commit.com hooks --- tests/engine_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/engine_test.py b/tests/engine_test.py index a6bd95bc..65a239a9 100644 --- a/tests/engine_test.py +++ b/tests/engine_test.py @@ -967,7 +967,7 @@ def test_validate_without_body(self): with patch("commit_check.util._print_failure"): result = validator.validate(context) assert result == ValidationResult.FAIL - + @pytest.mark.benchmark def test_validate_with_leading_blank_lines_and_body(self): """Test body validation with leading blank lines before body content.