Skip to content

Add cucumber-rs support to generate-coverage#48

Merged
leynos merged 3 commits intomainfrom
codex/add-support-for-cucumber-rs-tests-in-generate-coverage
Jul 29, 2025
Merged

Add cucumber-rs support to generate-coverage#48
leynos merged 3 commits intomainfrom
codex/add-support-for-cucumber-rs-tests-in-generate-coverage

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 29, 2025

Summary

  • extend generate-coverage action to optionally run cucumber-rs scenarios
  • install cargo-cucumber when requested
  • merge cucumber coverage with standard output
  • document new inputs and example usage
  • test new cucumber options in run_rust.py

Testing

  • make lint
  • make test

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

Summary by Sourcery

Enable cucumber-rs coverage in the generate-coverage action and merge its results with standard Rust coverage

New Features:

  • Add flags to trigger cucumber-rs scenarios under coverage and pass feature paths and extra args
  • Run a second cargo llvm-cov invocation for cucumber tests and merge its output with the main report
  • Install cargo-cucumber when cucumber-rs coverage is enabled

Build:

  • Add a CI step to install cargo-cucumber if cucumber-rs coverage is requested

Documentation:

  • Document new cucumber-rs inputs in action.yml and README with an example usage

Tests:

  • Add a test to verify cucumber-rs coverage is executed and merged in run_rust.py

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 29, 2025

Reviewer's Guide

This PR enhances the generate-coverage action with optional cucumber-rs support by adding inputs, installing cargo-cucumber, extending the Rust coverage script to run and merge cucumber scenarios, and updating tests and documentation accordingly.

Class diagram for run_rust.py main function changes

classDiagram
    class main {
        +lang: str
        +fmt: str
        +github_output: Path
        +cucumber_rs_features: str
        +cucumber_rs_args: str
        +with_cucumber_rs: bool
        +get_cargo_coverage_cmd()
        +get_line_coverage_percent_from_lcov()
    }
    class cargo_cucumber {
        <<external>>
    }
    main --|> cargo_cucumber : uses when with_cucumber_rs
    main : +merge_cucumber_coverage()
    main : +handle_cucumber_args()
    main : +merge-cobertura (external)
    main : +uvx (external)
Loading

File-Level Changes

Change Details Files
Implement optional cucumber-rs coverage run and merge logic
  • Add CLI options for with-cucumber-rs, cucumber-rs-features, and cucumber-rs-args
  • Invoke a second cargo llvm-cov pass for cucumber tests when enabled
  • Merge cucumber coverage with the primary output (via uvx for cobertura or concatenation)
.github/actions/generate-coverage/scripts/run_rust.py
Add test validating cucumber-rs coverage flow
  • Create test_run_rust_with_cucumber to stub two cargo calls
  • Verify constructed arguments include features and extra args
  • Assert merged coverage output path and exit code
.github/actions/generate-coverage/tests/test_scripts.py
Introduce cucumber-rs inputs and install step
  • Define inputs with-cucumber-rs, cucumber-rs-features, and cucumber-rs-args
  • Add a step to install cargo-cucumber when cucumber support is enabled
  • Propagate new inputs as environment variables to run_rust.py
.github/actions/generate-coverage/action.yml
Document cucumber-rs options and example usage
  • Add table entries for with-cucumber-rs, cucumber-rs-features, cucumber-rs-args
  • Provide a usage snippet demonstrating cucumber setup
.github/actions/generate-coverage/README.md

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 29, 2025

Summary by CodeRabbit

  • New Features

    • Added support for running cucumber-rs scenarios under coverage for Rust projects, allowing integration of cucumber-based tests into coverage reports.
    • Introduced new configuration options for enabling cucumber-rs coverage and specifying feature files and additional arguments.
  • Documentation

    • Updated documentation to describe new cucumber-rs integration options and provided example usage.
  • Tests

    • Added tests to verify cucumber-rs coverage integration and merging behaviour for different coverage formats.

Walkthrough

Extend the GitHub action generate-coverage to support running Rust Cucumber.rs scenarios under coverage. Update documentation and action inputs, modify the Rust coverage script to handle Cucumber.rs runs and merging, and add a targeted test for this new path.

Changes

Cohort / File(s) Change Summary
Documentation Update
.github/actions/generate-coverage/README.md
Document new inputs: with-cucumber-rs, cucumber-rs-features, cucumber-rs-args. Add example usage for enabling Cucumber.rs coverage.
Action Input & Flow
.github/actions/generate-coverage/action.yml
Add three new inputs for Cucumber.rs support. Conditionally install cargo-cucumber. Pass new environment variables to the Rust coverage script.
Rust Coverage Script
.github/actions/generate-coverage/scripts/run_rust.py
Add options and logic to run Cucumber.rs scenarios under coverage. Merge or concatenate coverage outputs as appropriate. Handle errors and outputs for this new path.
Test for Cucumber.rs Path
.github/actions/generate-coverage/tests/test_scripts.py
Add test_run_rust_with_cucumber, test_run_rust_with_cucumber_cobertura, and test_run_rust_with_cucumber_cobertura_merge_failure to verify execution and argument handling for Cucumber.rs coverage. Assert correct command calls, output validation, and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant GitHubAction as GitHub Action
    participant run_rust_py as run_rust.py
    participant cargo as cargo
    participant uvx as uvx (merge tool)
    participant Output as Output File

    GitHubAction->>run_rust_py: Invoke with inputs (including Cucumber.rs options)
    run_rust_py->>cargo: Run cargo llvm-cov (standard tests)
    cargo-->>run_rust_py: Standard coverage output
    alt with_cucumber_rs enabled
        run_rust_py->>cargo: Run cargo llvm-cov (cucumber tests with features/args)
        cargo-->>run_rust_py: Cucumber coverage output
        alt format is cobertura
            run_rust_py->>uvx: Merge standard + cucumber coverage XML
            uvx-->>run_rust_py: Merged coverage XML
            run_rust_py->>Output: Write merged output
        else other formats
            run_rust_py->>Output: Concatenate outputs
        end
    else
        run_rust_py->>Output: Write standard coverage output
    end
    run_rust_py-->>GitHubAction: Exit with result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Poem

In the land of Rust and green,
Cucumber steps now can be seen.
Coverage grows, reports unite,
With features, tags, and tests in flight.
🍀 Merge the XML, concatenate the rest—
This action now puts all to the test!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5a6b6ad and 83b1a88.

📒 Files selected for processing (1)
  • .github/actions/generate-coverage/scripts/run_rust.py (5 hunks)
🔇 Additional comments (5)
.github/actions/generate-coverage/scripts/run_rust.py (5)

11-11: Import added correctly.

The shlex import is properly placed and addresses the previous review comment about correctly parsing shell arguments.


35-37: New options properly configured.

The cucumber-rs options follow the established pattern with appropriate defaults and environment variable mappings.


103-114: Well-structured helper function.

Good extraction of common cargo execution logic with proper error handling and stdout/stderr management.


116-138: Robust lcov merging implementation.

The function correctly validates lcov format, handles newlines properly, and includes comprehensive error handling for file operations.


198-200: Clean integration of cucumber-rs support.

The main function properly integrates the new cucumber-rs functionality with appropriate conditional execution and maintains backward compatibility.

Also applies to: 209-219

✨ 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/add-support-for-cucumber-rs-tests-in-generate-coverage

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

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 and found some issues that need to be addressed.

  • Add assertions to the cucumber test that verify the merged coverage file contains the expected combined content and that the temporary cucumber file is cleaned up to cover the full merge+cleanup behavior.
  • Manually concatenating lcov files can lead to malformed records; consider using an lcov-aware merge tool or adding header/footer validation to ensure the combined file remains valid.
  • There’s a lot of duplicated logic in run_rust.py for running cargo llvm-cov and handling errors—extracting a helper function would DRY up command construction and improve maintainability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add assertions to the cucumber test that verify the merged coverage file contains the expected combined content and that the temporary cucumber file is cleaned up to cover the full merge+cleanup behavior.
- Manually concatenating lcov files can lead to malformed records; consider using an lcov-aware merge tool or adding header/footer validation to ensure the combined file remains valid.
- There’s a lot of duplicated logic in run_rust.py for running cargo llvm-cov and handling errors—extracting a helper function would DRY up command construction and improve maintainability.

## Individual Comments

### Comment 1
<location> `.github/actions/generate-coverage/tests/test_scripts.py:162` </location>
<code_context>
+def test_run_rust_with_cucumber(tmp_path: Path, shell_stubs: StubManager) -> None:
</code_context>

<issue_to_address>
Missing test for Cobertura format and merge-cobertura logic.

Please add a test that covers the Cobertura format, including the 'merge-cobertura' logic and its error handling, to ensure full coverage of the new code.
</issue_to_address>

### Comment 2
<location> `.github/actions/generate-coverage/scripts/run_rust.py:134` </location>
<code_context>
     typer.echo(stdout)
+
+    cucumber_file: Path | None = None
+    if with_cucumber_rs and cucumber_rs_features:
+        cucumber_file = out.with_name(f"{out.stem}.cucumber{out.suffix}")
+        c_args = get_cargo_coverage_cmd(
</code_context>

<issue_to_address>
Consider extracting the cucumber.rs coverage logic into a separate function to simplify the main function.

```suggestion
# extract the cucumber.rs coverage logic into its own function
def run_cucumber_rs_coverage(
    out: Path,
    fmt: str,
    features: str,
    with_default: bool,
    cucumber_rs_features: str,
    cucumber_rs_args: str,
) -> None:
    cucumber_file = out.with_name(f"{out.stem}.cucumber{out.suffix}")
    cmd = get_cargo_coverage_cmd(fmt, cucumber_file, features, with_default=with_default)
    cmd += ["--", "--test", "cucumber", "--", "cucumber", "--features", cucumber_rs_features]
    if cucumber_rs_args:
        cmd += cucumber_rs_args.split()

    try:
        retcode, stdout, stderr = cargo[cmd].run(retcode=None)
    except ProcessExecutionError as exc:
        retcode, stdout, stderr = exc.retcode, exc.stdout, exc.stderr

    if retcode != 0:
        typer.echo(f"cargo llvm-cov failed with code {retcode}: {stderr}", err=True)
        raise typer.Exit(code=retcode or 1)
    typer.echo(stdout)

    if fmt == "cobertura":
        from plumbum.cmd import uvx
        try:
            merged = uvx["merge-cobertura", str(out), str(cucumber_file)]()
        except ProcessExecutionError as exc:
            typer.echo(f"merge-cobertura failed with code {exc.retcode}: {exc.stderr}", err=True)
            raise typer.Exit(code=exc.retcode or 1) from exc
        out.write_text(merged)
    else:
        out.write_text(out.read_text() + cucumber_file.read_text())

    cucumber_file.unlink()


# in main(), replace the big nested block with a single call
 if with_cucumber_rs and cucumber_rs_features:
-    cucumber_file = out.with_name(f"{out.stem}.cucumber{out.suffix}")
-    # ... 20 lines of nested logic ...
-    cucumber_file.unlink()
+    run_cucumber_rs_coverage(
+        out,
+        fmt,
+        features,
+        with_default,
+        cucumber_rs_features,
+        cucumber_rs_args,
+    )
```
</issue_to_address>

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.

Comment thread .github/actions/generate-coverage/tests/test_scripts.py
Comment thread .github/actions/generate-coverage/scripts/run_rust.py
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b2f82fd and 3fa21af.

📒 Files selected for processing (4)
  • .github/actions/generate-coverage/README.md (2 hunks)
  • .github/actions/generate-coverage/action.yml (3 hunks)
  • .github/actions/generate-coverage/scripts/run_rust.py (3 hunks)
  • .github/actions/generate-coverage/tests/test_scripts.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
.github/actions/*/README.md

📄 CodeRabbit Inference Engine (AGENTS.md)

.github/actions/*/README.md: Each action must have a README.md containing a one-liner summary, table of inputs, table of outputs, usage example with uses: ./.github/actions/<name>@<major>, and a release history link to CHANGELOG.
Add a DEPRECATED: banner to README and repository description when deprecating an action.

Files:

  • .github/actions/generate-coverage/README.md
.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_scripts.py
.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
🧬 Code Graph Analysis (1)
.github/actions/generate-coverage/tests/test_scripts.py (2)
.github/actions/generate-coverage/tests/conftest.py (1)
  • shell_stubs (29-40)
shellstub.py (4)
  • StubManager (39-153)
  • register (49-84)
  • env (98-103)
  • calls_of (86-95)
🔇 Additional comments (9)
.github/actions/generate-coverage/README.md (2)

43-45: Documentation correctly describes the new cucumber-rs inputs.

The input descriptions are clear and consistent with the existing documentation style.


103-112: Usage example demonstrates the cucumber-rs feature effectively.

The example shows proper configuration of all three cucumber-rs inputs with realistic values.

.github/actions/generate-coverage/tests/test_scripts.py (1)

162-211: Test comprehensively validates cucumber-rs functionality.

The test properly verifies that:

  • Two cargo commands are executed when cucumber-rs is enabled
  • The second command includes the expected cucumber-specific arguments
  • Environment variables are correctly processed
  • Output files are handled appropriately
.github/actions/generate-coverage/action.yml (3)

30-39: Input definitions follow consistent structure.

The new cucumber-rs inputs are properly defined with appropriate descriptions and defaults.


97-100: Conditional installation logic is correct.

The step properly checks both the cucumber-rs flag and language detection before installing cargo-cucumber.


110-112: Environment variables correctly map inputs to script.

The new environment variables properly pass the cucumber-rs configuration to the run_rust.py script.

.github/actions/generate-coverage/scripts/run_rust.py (3)

34-36: Typer options correctly defined for cucumber-rs inputs.

The new options follow the established pattern and properly map to environment variables.


112-114: Function parameters properly integrate cucumber-rs options.

The new parameters are correctly added to the main function signature.


164-178: Coverage merging logic handles different formats appropriately.

The implementation correctly:

  • Uses merge-cobertura tool for cobertura format
  • Falls back to concatenation for other formats
  • Removes temporary files after merging

Comment thread .github/actions/generate-coverage/scripts/run_rust.py Outdated
@leynos leynos merged commit 16783ca into main Jul 29, 2025
2 checks passed
@leynos leynos deleted the codex/add-support-for-cucumber-rs-tests-in-generate-coverage branch July 29, 2025 23:40
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