Skip to content

Fix coverage detection#37

Merged
leynos merged 3 commits intomainfrom
codex/fix-runtime-errors-in-detect.py
Jul 26, 2025
Merged

Fix coverage detection#37
leynos merged 3 commits intomainfrom
codex/fix-runtime-errors-in-detect.py

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 26, 2025

Summary

  • handle format parsing manually in detect script
  • add version to pyproject so uv works

Testing

  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_688506433f20832281ebb1fa2f483cdc

Summary by Sourcery

Simplify and harden the coverage detection script by removing the custom ParamType, switching the format option to a plain string, manually parsing and validating it at runtime, and updating the output accordingly, and add a version field to pyproject.toml to enable the uv command

Bug Fixes:

  • Fix unsupported coverage format handling by manually parsing and validating the format string instead of using a custom ParamType
  • Ensure the detected format value is correctly written to GITHUB_OUTPUT

Enhancements:

  • Simplify typer Option for coverage format to use a string default

Build:

  • Add version ‘0.0.0’ to pyproject.toml to support uv tooling

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 26, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 24 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4061a0d and c5efeed.

📒 Files selected for processing (2)
  • .github/actions/generate-coverage/tests/test_detect.py (1 hunks)
  • pyproject.toml (1 hunks)

Summary by CodeRabbit

  • New Features

    • Added a test to verify error handling for unsupported coverage format inputs.
  • Bug Fixes

    • Improved error messaging when an unsupported coverage format is provided.
  • Chores

    • Updated default values and removed explicit type declarations for action inputs in GitHub Actions configuration.
    • Added a version field to the project metadata.
    • Simplified option handling and removed unused imports in the coverage detection script.

Walkthrough

Remove the custom CoverageFmtParam class from the coverage detection script, update the main function to accept a plain string for the format option, and explicitly convert it to the enum with error handling. Simplify the option declaration and clean up unused imports. Add a version field to the [project] section in pyproject.toml. Modify GitHub Action input definitions by removing explicit type declarations and changing boolean defaults to strings. Add a test for invalid coverage format handling that asserts proper error output and exit code.

Changes

File(s) Change Summary
.github/actions/generate-coverage/scripts/detect.py Remove custom ParamType, update option to plain string, add explicit enum conversion and error handling, clean up imports, update function signature.
pyproject.toml Add version = "1.2.2" to [project] section.
.github/actions/generate-coverage/action.yml Remove type declarations from inputs, change boolean default values to string literals for with-default-features and with-ratchet.
.github/actions/ratchet-coverage/action.yml Remove type: string declaration from baseline-file input.
.github/actions/generate-coverage/tests/test_detect.py Add test for invalid coverage format input verifying error message and exit code.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DetectScript
    participant CoverageFmtEnum

    User->>DetectScript: Run detect.py with --fmt option (string)
    DetectScript->>CoverageFmtEnum: Convert string to enum (handle errors)
    alt Valid format
        DetectScript->>DetectScript: Continue processing
        DetectScript->>User: Output coverage result in selected format
    else Invalid format
        DetectScript->>User: Print error message and exit with code 1
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Poem

A version named "1.2.2" arrives,
The script sheds types, now plain strings thrive.
Enums stand ready to catch the wrong,
With errors clear and exits strong.
Actions trimmed, inputs refined,
Tests ensure no faults unwind.
Coverage flows, sleek and alive!
🎉🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-runtime-errors-in-detect.py

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @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.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 26, 2025

Reviewer's Guide

Streamlines coverage format handling by removing the custom parameter type and introducing manual parsing in the detect script, and adds a project version in pyproject.toml to enable ‘uv’ compatibility.

Entity relationship diagram for pyproject.toml version addition

erDiagram
    PROJECT ||--o{ VERSION : has
    PROJECT {
        string name
        string version
    }
Loading

Class diagram for updated coverage format handling in detect.py

classDiagram
    class CoverageFmt {
        <<enum>>
        COBERTURA
        COVERAGEPY
    }
    class Lang {
        <<enum>>
        PYTHON
        RUST
        MIXED
    }
    class detect {
        +get_lang() Lang
        +main(fmt: str, github_output: Path) None
    }
    CoverageFmt <.. detect : uses
    Lang <.. detect : uses
Loading

Class diagram showing removal of CoverageFmtParam

classDiagram
    class CoverageFmtParam {
        -name: str
        +convert(value: str, param: click.Parameter|None, ctx: click.Context|None) CoverageFmt
    }
    %% CoverageFmtParam was removed from the codebase
Loading

File-Level Changes

Change Details Files
Streamline coverage format option handling and parsing
  • Removed the custom CoverageFmtParam class
  • Updated FMT_OPT to use the enum’s string value as default
  • Changed main signature to accept fmt as raw string and github_output as Path
  • Added try/except to convert fmt to CoverageFmt with error handling
  • Adjusted match-case and output write to use the parsed enum
.github/actions/generate-coverage/scripts/detect.py
Add project version for tooling compatibility
  • Inserted a version field under the [project] section
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes - here's some feedback:

  • Add a unit test that runs detect.main with an invalid format to assert it exits with code 1 and prints the “Unsupported format” error.
  • Now that fmt is accepted as a raw string, consider updating the CLI help text to list the supported coverage formats for clearer user guidance.
  • The pyproject version is set to “0.0.0”—if this is your initial release, bump it to a meaningful version or adopt an automated versioning strategy to avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add a unit test that runs `detect.main` with an invalid format to assert it exits with code 1 and prints the “Unsupported format” error.
- Now that `fmt` is accepted as a raw string, consider updating the CLI help text to list the supported coverage formats for clearer user guidance.
- The pyproject version is set to “0.0.0”—if this is your initial release, bump it to a meaningful version or adopt an automated versioning strategy to avoid confusion.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 26, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 26, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 26, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 26, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 05f0182 and 4061a0d.

📒 Files selected for processing (5)
  • .github/actions/generate-coverage/action.yml (1 hunks)
  • .github/actions/generate-coverage/scripts/detect.py (3 hunks)
  • .github/actions/generate-coverage/tests/test_detect.py (1 hunks)
  • .github/actions/ratchet-coverage/action.yml (0 hunks)
  • pyproject.toml (1 hunks)
💤 Files with no reviewable changes (1)
  • .github/actions/ratchet-coverage/action.yml
🧰 Additional context used
📓 Path-based instructions (3)
pyproject.toml

📄 CodeRabbit Inference Engine (.rules/python-00.md)

Use pyproject.toml to configure tools like Ruff, Pyright, and Pytest.

pyproject.toml: Always include a [project] table in pyproject.toml with at least name and version fields as required by PEP 621.
Include description and readme fields in the [project] table of pyproject.toml to improve indexing and packaging tool compatibility.
Specify requires-python in the [project] table of pyproject.toml to constrain supported Python versions.
Declare the license using the license field in the [project] table of pyproject.toml, either as SPDX text or by referencing a file.
List authors in the [project] table of pyproject.toml using a list of tables with name and email.
Include keywords and classifiers in the [project] table of pyproject.toml to improve discoverability in package indexes.
Declare runtime dependencies in the dependencies field of the [project] table in pyproject.toml using PEP 508 syntax.
Use [project.optional-dependencies] in pyproject.toml to group development and documentation dependencies separately from runtime dependencies.
Define CLI entry points using [project.scripts] and GUI entry points using [project.gui-scripts] in pyproject.toml.
Register plugin entry points using [project.entry-points.'group.name'] in pyproject.toml if your project supports plugins.
Declare a [build-system] table in pyproject.toml with requires and build-backend fields to support PEP 517/518 builds and editable installs.
For Astral uv projects, set [tool.uv] package = true in pyproject.toml to ensure your own package is built and installed during uv sync or uv run.
Keep build constraints minimal in pyproject.toml; omit [build-system] if you do not need editable installs, but set tool.uv.package = true if you want your package built.
Use exact or bounded version ranges for dependencies in pyproject.toml (e.g., requests>=2.25, <3.0) to avoid unexpected major version upgrades.
Declare dynamic...

Files:

  • pyproject.toml
.github/actions/*/action.yml

📄 CodeRabbit Inference Engine (AGENTS.md)

.github/actions/*/action.yml: Each action must have an action.yml file containing every input and output, with required ones clearly marked.
Composite actions referencing sibling scripts must use ${{ github.action_path }} for portability.

Files:

  • .github/actions/generate-coverage/action.yml
.github/actions/*/tests/**

📄 CodeRabbit Inference Engine (AGENTS.md)

.github/actions/*/tests/**: Tests for each action must be present in a tests/ directory within the action's directory.
Contract tests must validate that declared inputs and outputs round-trip correctly.

Files:

  • .github/actions/generate-coverage/tests/test_detect.py
🔇 Additional comments (13)
.github/actions/generate-coverage/scripts/detect.py (5)

32-36: Approve the simplified option definition.

The refactoring from a custom ParamType to a plain string option with enum default value improves code clarity whilst maintaining the same functionality.


53-54: Approve the simplified function signature.

Changing from enum parameter to plain string simplifies the interface and allows for explicit validation within the function body.


58-62: Approve the explicit format validation with proper error handling.

The try/except block correctly handles invalid format strings and provides clear error messages. The use of fmt.lower() ensures case-insensitive matching, which improves user experience.


64-64: Approve the match statement update.

Correctly updated to use the validated enum instance fmt_enum instead of the raw string parameter.


76-76: Approve the output formatting.

Correctly uses fmt_enum.value to write the validated format string to the GitHub output file.

pyproject.toml (1)

3-3: Approve the version field addition.

Adding the version field satisfies PEP 621 requirements for the [project] table, which must include at least name and version fields.

.github/actions/generate-coverage/action.yml (3)

10-10: Approve the string default value.

Changing from boolean true to string "true" is correct since GitHub Actions inputs are always treated as strings. This improves consistency and clarity.


21-21: Approve the string default value.

Changing from boolean false to string "false" maintains consistency with GitHub Actions string-based input handling.


3-29: Validate action inputs with contract tests

Tests exist under .github/actions/generate-coverage/tests/:

  • conftest.py
  • test_detect.py
  • test_scripts.py

Run these tests to confirm every defined input in action.yml (including defaults) round-trips correctly through the action’s output.

.github/actions/generate-coverage/tests/test_detect.py (4)

13-17: Approve the custom Exit exception class.

The _FakeExit class correctly mimics typer.Exit behaviour for testing purposes, capturing the exit code for assertions.


19-25: Approve the typer module mock.

The _FAKE_TYPER namespace provides appropriate substitutes for the typer functions used in the detect script. The Option lambda correctly returns the default value, and echo properly handles stderr/stdout routing.


27-33: Approve the dynamic module import approach.

Using importlib.util to dynamically load the detect script is a clean way to test it without packaging concerns. The path resolution using Path(__file__).resolve().parents[1] correctly navigates to the scripts directory.


36-43: Approve the invalid format test coverage.

The test correctly verifies that invalid format strings cause the program to exit with code 1 and output an appropriate error message. This covers the new error handling path introduced in the detect.py refactoring.

Comment thread .github/actions/generate-coverage/tests/test_detect.py
Comment thread pyproject.toml
@leynos leynos merged commit 3a62b84 into main Jul 26, 2025
1 check passed
@leynos leynos deleted the codex/fix-runtime-errors-in-detect.py branch July 26, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant