Skip to content

fix: Ensure all checks pass without overwriting previous failures #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

B-McDonnell
Copy link
Contributor

@B-McDonnell B-McDonnell commented Feb 2, 2025

See #212 for rationale

I also added some testing to demonstrate the problem and verify the solution in main_test.py

Before fix:

platform linux -- Python 3.8.20, pytest-8.3.4, pluggy-1.5.0
rootdir: commit-check
configfile: pyproject.toml
plugins: mock-3.14.0
collected 91 items

tests/author_test.py ..........
tests/branch_test.py .........
tests/commit_test.py ...........
tests/error_test.py ....x
tests/main_test.py ................F..F..FF....F.  
tests/util_test.py ..........................       

After fix:

platform linux -- Python 3.8.20, pytest-8.3.4, pluggy-1.5.0
rootdir: commit-check
configfile: pyproject.toml
plugins: mock-3.14.0
collected 90 items

tests/author_test.py ..........
tests/branch_test.py .........
tests/commit_test.py ...........
tests/error_test.py ....x
tests/main_test.py .............................
tests/util_test.py ..........................

Closes #212

Summary by CodeRabbit

  • Refactor
    • Enhanced the commit validation process by improving the way results are aggregated for more consistent outcomes.
  • Tests
    • Introduced a new test method to validate the main function with multiple command-line arguments and expected results.
    • Expanded existing tests to improve coverage of the command-line interface behavior.

Copy link
Contributor

coderabbitai bot commented Feb 2, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request modifies the commit-check logic by replacing the single return variable with a list that aggregates results from multiple checks. The main function in commit_check/main.py now collects each check’s result into check_results and determines the final outcome based on whether all values equal PASS. Additionally, the dry-run behavior is refined. In the test suite (tests/main_test.py), a new parameterized test method has been added to verify the behavior of multiple checks under various conditions.

Changes

File(s) Changes
commit_check/main.py Replaced the single retval with a check_results list to aggregate results from individual checks; updated control flow to return PASS only if all entries are PASS, otherwise returns FAIL; added import for FAIL and modified dry-run handling.
tests/main_test.py Added a new parameterized test method test_main_multiple_checks within the TestMain class to validate the behavior of the main function with multiple command-line arguments and varied check results via mocking.

Assessment against linked issues

Objective Addressed Explanation
Correctly aggregate multiple check results to avoid overriding failures (#212)

Possibly related PRs

  • fix: Ensure all checks pass without overwriting previous failures #213: The changes in the main PR are directly related to those in the retrieved PR, as both modify the logic of the main function in commit_check/main.py to handle check results using a list instead of a single variable, ensuring consistent behavior in result aggregation.
  • feat: add merge_base to check the branch is rebased #192: The changes in the main PR, specifically the modifications to the main function in commit_check/main.py to handle the results of various checks, are related to the addition of the merge_base check in the retrieved PR, as both involve updates to the control flow and logic of checks performed by the application.

Suggested labels

enhancement, minor

Poem

I'm a bunny in the code, hopping all around,
Checking every commit, ensuring logic's sound.
Each check gets its turn, results in a neat parade,
With carrots of clarity in each update made.
I nibble bugs away and bounce with pure delight—
A hoppy little coder in the daylight!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a1b0c2 and f71c648.

📒 Files selected for processing (1)
  • tests/main_test.py (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
commit_check/main.py (1)

122-125: Consider early return optimization for dry-run.

Moving the dry-run check before running any checks would be more efficient as it could avoid unnecessary processing.

def main() -> int:
    parser = get_parser()
    args = parser.parse_args()
+   if args.dry_run:
+       return PASS
    check_results: list[int] = []
    # ... rest of the function
-   if args.dry_run:
-       return PASS
    return PASS if all(val == PASS for val in check_results) else FAIL
tests/main_test.py (1)

167-169: Consider refactoring author check implementation.

The comment about the messy implementation suggests a need for separate check_author_name and check_author_email functions.

Would you like me to propose a refactored implementation that separates these concerns?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91ee12b and cc9737e.

📒 Files selected for processing (2)
  • commit_check/main.py (2 hunks)
  • tests/main_test.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
tests/main_test.py

122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


123-123: Undefined name FAIL

(F821)


123-123: Undefined name PASS

(F821)


123-123: Undefined name PASS

(F821)


123-123: Undefined name PASS

(F821)


123-123: Undefined name PASS

(F821)


123-123: Undefined name PASS

(F821)


123-123: Undefined name FAIL

(F821)


124-124: Undefined name FAIL

(F821)


124-124: Undefined name PASS

(F821)


124-124: Undefined name PASS

(F821)


124-124: Undefined name PASS

(F821)


124-124: Undefined name PASS

(F821)


124-124: Undefined name PASS

(F821)


124-124: Undefined name FAIL

(F821)


125-125: Undefined name PASS

(F821)


125-125: Undefined name PASS

(F821)


125-125: Undefined name PASS

(F821)


125-125: Undefined name PASS

(F821)


125-125: Undefined name FAIL

(F821)


125-125: Undefined name PASS

(F821)


125-125: Undefined name FAIL

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


127-127: Undefined name FAIL

(F821)


127-127: Undefined name PASS

(F821)


127-127: Undefined name PASS

(F821)


127-127: Undefined name PASS

(F821)


127-127: Undefined name PASS

(F821)


127-127: Undefined name PASS

(F821)


127-127: Undefined name FAIL

(F821)


128-128: Undefined name PASS

(F821)


128-128: Undefined name PASS

(F821)


128-128: Undefined name FAIL

(F821)


128-128: Undefined name PASS

(F821)


128-128: Undefined name PASS

(F821)


128-128: Undefined name PASS

(F821)


128-128: Undefined name FAIL

(F821)


129-129: Undefined name PASS

(F821)


129-129: Undefined name PASS

(F821)


129-129: Undefined name PASS

(F821)


129-129: Undefined name FAIL

(F821)


129-129: Undefined name PASS

(F821)


129-129: Undefined name PASS

(F821)


129-129: Undefined name FAIL

(F821)


130-130: Undefined name PASS

(F821)


130-130: Undefined name PASS

(F821)


130-130: Undefined name FAIL

(F821)


130-130: Undefined name FAIL

(F821)


130-130: Undefined name PASS

(F821)


130-130: Undefined name PASS

(F821)


130-130: Undefined name FAIL

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


133-133: Undefined name FAIL

(F821)


133-133: Undefined name PASS

(F821)


133-133: Undefined name PASS

(F821)


133-133: Undefined name PASS

(F821)


133-133: Undefined name PASS

(F821)


133-133: Undefined name PASS

(F821)


133-133: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name PASS

(F821)

🔇 Additional comments (3)
commit_check/main.py (2)

102-102: LGTM! Good use of type hints.

The type hint for check_results clearly indicates it's a list of integers, which aligns with the PASS/FAIL return values.


110-120: LGTM! Improved result aggregation.

The changes effectively collect results from all checks without overwriting previous failures. This fixes the core issue where subsequent checks could mask earlier failures.

tests/main_test.py (1)

119-136: LGTM! Comprehensive test coverage.

The parametrized test cases effectively verify the new result aggregation logic with various combinations of check results.

🧰 Tools
🪛 Ruff (0.8.2)

122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


122-122: Undefined name PASS

(F821)


123-123: Undefined name FAIL

(F821)


123-123: Undefined name PASS

(F821)


123-123: Undefined name PASS

(F821)


123-123: Undefined name PASS

(F821)


123-123: Undefined name PASS

(F821)


123-123: Undefined name PASS

(F821)


123-123: Undefined name FAIL

(F821)


124-124: Undefined name FAIL

(F821)


124-124: Undefined name PASS

(F821)


124-124: Undefined name PASS

(F821)


124-124: Undefined name PASS

(F821)


124-124: Undefined name PASS

(F821)


124-124: Undefined name PASS

(F821)


124-124: Undefined name FAIL

(F821)


125-125: Undefined name PASS

(F821)


125-125: Undefined name PASS

(F821)


125-125: Undefined name PASS

(F821)


125-125: Undefined name PASS

(F821)


125-125: Undefined name FAIL

(F821)


125-125: Undefined name PASS

(F821)


125-125: Undefined name FAIL

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


126-126: Undefined name PASS

(F821)


127-127: Undefined name FAIL

(F821)


127-127: Undefined name PASS

(F821)


127-127: Undefined name PASS

(F821)


127-127: Undefined name PASS

(F821)


127-127: Undefined name PASS

(F821)


127-127: Undefined name PASS

(F821)


127-127: Undefined name FAIL

(F821)


128-128: Undefined name PASS

(F821)


128-128: Undefined name PASS

(F821)


128-128: Undefined name FAIL

(F821)


128-128: Undefined name PASS

(F821)


128-128: Undefined name PASS

(F821)


128-128: Undefined name PASS

(F821)


128-128: Undefined name FAIL

(F821)


129-129: Undefined name PASS

(F821)


129-129: Undefined name PASS

(F821)


129-129: Undefined name PASS

(F821)


129-129: Undefined name FAIL

(F821)


129-129: Undefined name PASS

(F821)


129-129: Undefined name PASS

(F821)


129-129: Undefined name FAIL

(F821)


130-130: Undefined name PASS

(F821)


130-130: Undefined name PASS

(F821)


130-130: Undefined name FAIL

(F821)


130-130: Undefined name FAIL

(F821)


130-130: Undefined name PASS

(F821)


130-130: Undefined name PASS

(F821)


130-130: Undefined name FAIL

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


131-131: Undefined name PASS

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


132-132: Undefined name FAIL

(F821)


133-133: Undefined name FAIL

(F821)


133-133: Undefined name PASS

(F821)


133-133: Undefined name PASS

(F821)


133-133: Undefined name PASS

(F821)


133-133: Undefined name PASS

(F821)


133-133: Undefined name PASS

(F821)


133-133: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name FAIL

(F821)


134-134: Undefined name PASS

(F821)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
tests/main_test.py (1)

176-177: ⚠️ Potential issue

Remove duplicate mock.

The mock for check_author is duplicated. This was previously flagged in a review.

Apply this diff to fix the issue:

 mocker.patch("commit_check.author.check_author", side_effect=author_side_effect)
-mocker.patch("commit_check.author.check_author", side_effect=author_side_effect)
🧹 Nitpick comments (1)
tests/main_test.py (1)

167-176: Consider refactoring author checks for better encapsulation.

The comment correctly identifies that the current implementation exposes unnecessary implementation details. Consider splitting the author check into two separate public methods.

Here's a suggested approach:

# In commit_check/author.py
def check_author_name(config) -> int:
    return check_author(config, "author_name")

def check_author_email(config) -> int:
    return check_author(config, "author_email")

# Make check_author private by renaming to _check_author

This would simplify testing and provide a cleaner API.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc9737e and 5a1b0c2.

📒 Files selected for processing (1)
  • tests/main_test.py (2 hunks)
🔇 Additional comments (2)
tests/main_test.py (2)

4-4: LGTM! Import statement added as suggested.

The missing imports for PASS and FAIL constants have been added as recommended in the previous review.


119-180: Well-structured test cases with comprehensive coverage!

The new test method test_main_multiple_checks effectively validates:

  • Individual check failures
  • Multiple check combinations
  • All pass/fail scenarios
  • Dry run behavior

The parametrized test cases provide good coverage of the main function's behavior.

All code paths are covered here, checked by the assert
Copy link

sonarqubecloud bot commented Feb 2, 2025

@codecov-commenter
Copy link

codecov-commenter commented Feb 3, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (91ee12b) to head (f71c648).
Report is 1 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #213   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          290       290           
=========================================
  Hits           290       290           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@shenxianpeng shenxianpeng left a comment

Choose a reason for hiding this comment

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

Excellent! thank you.

@shenxianpeng shenxianpeng merged commit d9a8729 into commit-check:main Feb 3, 2025
24 of 25 checks passed
@shenxianpeng shenxianpeng added the bug Something isn't working label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failures are ignored if subsequent checks pass in single run
3 participants