Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion tests/engine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -648,6 +648,18 @@


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."""
Expand All @@ -656,12 +668,46 @@
)
validator = SignoffValidator(rule)
context = ValidationContext(
stdin_text="feat: add feature\n\nSigned-off-by: John Doe <john@example.com>"

Check failure on line 671 in tests/engine_test.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "feat: add feature\n\nSigned-off-by: John Doe <john@example.com>" 3 times.

See more on https://sonarcloud.io/project/issues?id=commit-check_commit-check&issues=AZ9FoGcZzCySbqz3vFry&open=AZ9FoGcZzCySbqz3vFry&pullRequest=463
)

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\nSigned-off-by: dependabot[bot] <support@github.com>"
)
)

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 <john@example.com>"
)

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."""
Expand Down
Loading