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
Copy Markdown
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
Copy Markdown

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 7 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_limit once during command initialization, treating None as “unset” so config is applied.
  • Update CommitArgs / CheckArgs typing to allow None for message_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.

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.

2 participants