Skip to content

📝 CodeRabbit Chat: Implement requested code changes - #78

Open
coderabbitai[bot] wants to merge 2 commits into
mainfrom
coderabbitai/chat/560e881
Open

📝 CodeRabbit Chat: Implement requested code changes#78
coderabbitai[bot] wants to merge 2 commits into
mainfrom
coderabbitai/chat/560e881

Conversation

@coderabbitai

@coderabbitai coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Code changes was requested by @leynos.

The following files were modified:

  • lading/workspace/metadata.py

Summary by Sourcery

Refactor cargo metadata handling by separating command invocation from JSON parsing and wiring these helpers into the main loader.

Enhancements:

  • Extract helper to invoke the cargo metadata command and normalize its output, mapping process errors to domain-specific exceptions.
  • Extract helper to parse and validate the cargo metadata JSON payload, returning a mapping for valid object responses.
  • Simplify load_cargo_metadata to orchestrate command invocation, error handling, and JSON parsing via the new helper functions.

leynos and others added 2 commits June 2, 2026 00:25
Add a runtime `CommandRunner` port and subprocess adapter so production
commands depend on a stable command-execution abstraction.

Move cmd-mox IPC and passthrough handling into `lading.testing`, then
select that adapter once at the CLI boundary when
`LADING_USE_CMD_MOX_STUB` is enabled. Route cargo metadata and publish
preflight execution through the selected runner so production modules no
longer import the dev-only dependency.
@coderabbitai
coderabbitai Bot requested a review from leynos June 5, 2026 20:37
@sourcery-ai

sourcery-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors the cargo metadata loading flow by extracting command invocation and JSON parsing into dedicated helpers, improving error mapping, separation of concerns, and testability while preserving existing behavior.

Sequence diagram for refactored cargo metadata loading flow

sequenceDiagram
    participant Caller
    participant load_cargo_metadata
    participant _invoke_cargo_metadata_command
    participant _parse_cargo_metadata_output

    Caller->>load_cargo_metadata: load_cargo_metadata(workspace_root, runner)
    load_cargo_metadata->>load_cargo_metadata: normalise_workspace_root(workspace_root)
    load_cargo_metadata->>load_cargo_metadata: _active_command_runner(runner)
    load_cargo_metadata->>load_cargo_metadata: log_command_invocation(LOGGER, _CARGO_METADATA_COMMAND, root_path)
    load_cargo_metadata->>_invoke_cargo_metadata_command: _invoke_cargo_metadata_command(command_runner, root_path)
    _invoke_cargo_metadata_command-->>load_cargo_metadata: exit_code, stdout_text, stderr_text

    alt exit_code != 0
        load_cargo_metadata-->>Caller: CargoMetadataInvocationError(exit_code, stdout_text, stderr_text)
    else exit_code == 0
        load_cargo_metadata->>_parse_cargo_metadata_output: _parse_cargo_metadata_output(stdout_text)
        _parse_cargo_metadata_output-->>load_cargo_metadata: payload
        load_cargo_metadata-->>Caller: payload
    end
Loading

File-Level Changes

Change Details Files
Extracted cargo metadata command invocation into a dedicated helper that normalizes spawn-time errors and coerces subprocess output to text.
  • Introduced a new _invoke_cargo_metadata_command(command_runner, root_path) helper that wraps command_runner invocation of the cargo metadata command.
  • Mapped FileNotFoundError for the cargo executable to CargoExecutableNotFoundError and all other spawn errors to CargoMetadataError within the new helper.
  • Ensured the helper always returns a tuple of (exit_code, stdout_text, stderr_text) with stdout and stderr coerced to strings via coerce_text.
lading/workspace/metadata.py
Extracted JSON parsing and validation of cargo metadata output into a dedicated helper to encapsulate format checks and exceptions.
  • Added a new _parse_cargo_metadata_output(stdout_text) helper that JSON-decodes the cargo metadata output and raises CargoMetadataParseError on decode failures.
  • Preserved validation that the decoded payload is a dict, raising CargoMetadataParseError.non_object_payload() otherwise.
lading/workspace/metadata.py
Reworked load_cargo_metadata to delegate to the new helpers, clarifying control flow and error handling while keeping its public behavior intact.
  • Updated load_cargo_metadata to resolve workspace root and command runner as before, then call _invoke_cargo_metadata_command to run cargo metadata.
  • Adjusted error handling so that non-zero exit codes raise CargoMetadataInvocationError using the already coerced stdout/stderr strings from the helper.
  • Delegated JSON parsing to _parse_cargo_metadata_output and returned its result.
lading/workspace/metadata.py

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

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Author

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 626cd356-7acc-435a-82d6-0afc7e7ff68b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


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.

Base automatically changed from issue-62-move-cmd-mox-integration-behind-a-commandrunner-port to main June 8, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant