Fix and improve test: message_length_limit#1900
Fix and improve test: message_length_limit#1900ttw225 wants to merge 7 commits intocommitizen-tools:masterfrom
Conversation
CLI > config > default (0) for not limit
CLI > config > default (0) for not limit
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1900 +/- ##
=======================================
Coverage 97.99% 97.99%
=======================================
Files 60 60
Lines 2689 2691 +2
=======================================
+ Hits 2635 2637 +2
Misses 54 54 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Pull request overview
Fixes precedence handling for message_length_limit so a present-but-None CLI argument no longer suppresses config fallback (CLI > config > default), and adds regression tests to cover both cz commit and cz check.
Changes:
- Resolve
message_length_limitonce during command initialization, treatingNoneas “unset” so config is applied. - Update
CommitArgs/CheckArgstyping to allowNoneformessage_length_limit. - Add/expand unit and CLI integration tests covering config fallback, CLI override (including
-l 0), and boundary behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
commitizen/commands/commit.py |
Fixes message length limit resolution when CLI flag is unset (None) and uses resolved value during validation. |
commitizen/commands/check.py |
Applies the same resolution logic for cz check and passes the resolved limit into validation. |
tests/commands/test_commit_command.py |
Adds unit tests for CLI vs config precedence, boundary conditions, and explicit disable via -l 0. |
tests/commands/test_check_command.py |
Adds unit coverage for config fallback when CLI provides None and adjusts override/boundary assertions. |
tests/test_cli_config_integration.py |
Adds integration tests verifying pyproject-configured limits are enforced and that CLI overrides work. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
This PR fixes how message_length_limit is resolved when the CLI flag is unset. Previously, the CLI argument could be present as None, causing arguments.get("message_length_limit", ...) to return None and skip the config fallback—so the configured limit (e.g. in pyproject.toml) was effectively ignored.
Now the precedence is correctly enforced as CLI > config > default (0 = no limit) for both cz commit and cz check, and additional unit + integration tests are added to prevent regressions.
test_commit_command.py,test_check_command.pytests/test_cli_config_integration.pyChecklist
Was generative AI tooling used to co-author this PR?
Generated-with: [Cursor] following the guidelines
Code Changes
uv run poe alllocally to ensure this change passes linter check and testsExpected Behavior
When
message_length_limitis configured,cz commit / cz checkshould enforce it unless explicitly overridden via-l/--message-length-limit(including-l 0to disable the limit).Steps to Test This Pull Request
Steps to reproduce the behavior:
pyproject.tomlcontaining:cz check --message "feat: this is definitely too long"cz check -l 0 --message "feat: this is definitely too long"Additional Context
#1899