Skip to content

Fix and improve test: message_length_limit#1900

Open
ttw225 wants to merge 7 commits intocommitizen-tools:masterfrom
ttw225:fix-and-test/message_length_limit
Open

Fix and improve test: message_length_limit#1900
ttw225 wants to merge 7 commits intocommitizen-tools:masterfrom
ttw225:fix-and-test/message_length_limit

Conversation

@ttw225
Copy link
Contributor

@ttw225 ttw225 commented Mar 18, 2026

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.

-        self.max_msg_length = arguments.get(
-            "message_length_limit", config.settings.get("message_length_limit", 0)
+
+        message_length_limit = arguments.get("message_length_limit")
+        self.message_length_limit: int = (
+            message_length_limit
+            if message_length_limit is not None
+            else config.settings["message_length_limit"]
         )

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.

  • unit tests: test_commit_command.py, test_check_command.py
  • integration tests: tests/test_cli_config_integration.py

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes (please specify the tool below)

Generated-with: [Cursor] following the guidelines

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes

Expected Behavior

When message_length_limit is configured, cz commit / cz check should enforce it unless explicitly overridden via -l/--message-length-limit (including -l 0 to disable the limit).

Steps to Test This Pull Request

Steps to reproduce the behavior:

  1. Create a temp repo with a pyproject.toml containing:
[tool.commitizen]
name = "cz_conventional_commits"
message_length_limit = 10
  1. Confirm config is enforced (should fail):
    cz check --message "feat: this is definitely too long"
  2. Confirm CLI overrides config (should succeed):
    cz check -l 0 --message "feat: this is definitely too long"

Additional Context

#1899

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.99%. Comparing base (33223b4) to head (f5c4b48).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant