Skip to content

🧹 [code health] Update Bash replace test to use metavariable#131

Open
bashandbone wants to merge 1 commit intomainfrom
fix-bash-replace-test-metavar-11195642146221711901
Open

🧹 [code health] Update Bash replace test to use metavariable#131
bashandbone wants to merge 1 commit intomainfrom
fix-bash-replace-test-metavar-11195642146221711901

Conversation

@bashandbone
Copy link
Contributor

@bashandbone bashandbone commented Mar 23, 2026

🎯 What:

The code health issue addressed is an actionable TODO in crates/language/src/bash.rs that suggested using a metavariable in the replacement string of test_bash_replace.

💡 Why:

This improves the test by verifying that the pattern matching engine correctly captures the value into the metavariable and substitutes it back into the replacement string, rather than relying on a hardcoded value. This makes the test a better validator of the underlying replacement logic.

✅ Verification:

The change was verified manually by checking the logic:

  • Input: "echo 123"
  • Pattern: "echo $A" (captures $A = 123)
  • Replacer: "log $A"
  • Expected Result: "log 123"
  • Assertion: assert_eq!(ret, "log 123")

Automated tests were attempted but could not be completed due to environment-specific dependency issues (offline mode missing mimalloc and bit-set from the local Cargo cache). However, the logic is straightforward and consistent with other tests in the repository (e.g., in rust.rs).

✨ Result:

The TODO is resolved, the comment is removed, and the test is now more representative of real-world use cases for the pattern matching engine.


PR created automatically by Jules for task 11195642146221711901 started by @bashandbone

Summary by Sourcery

Update the Bash replacement test to validate metavariable substitution rather than a hardcoded replacement string.

Tests:

  • Adjust the Bash replace test to use the captured metavariable in the replacer while asserting the substituted value.

Chores:

  • Remove the resolved TODO comment related to improving the Bash replace test.

Updated `test_bash_replace` in `crates/language/src/bash.rs` to use `$A` in the replacer string instead of a hardcoded value, resolving a TODO and improving test robustness.

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 23, 2026 14:49
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 23, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the Bash replacement test to use a metavariable in the replacement string so the test validates capture-and-substitute behavior instead of relying on a hardcoded replacement value.

Sequence diagram for Bash test_bash_replace metavariable capture and replace

sequenceDiagram
    participant TestRunner
    participant test_bash_replace
    participant test_replace
    participant BashPatternEngine

    TestRunner->>test_bash_replace: run()
    test_bash_replace->>test_replace: test_replace(echo_123, echo_$A, log_$A)
    test_replace->>BashPatternEngine: match("echo 123", pattern: "echo $A")
    BashPatternEngine-->>test_replace: captures A = 123
    test_replace->>BashPatternEngine: substitute(replacer: "log $A", A = 123)
    BashPatternEngine-->>test_replace: "log 123"
    test_replace-->>test_bash_replace: ret = "log 123"
    test_bash_replace->>test_bash_replace: assert_eq(ret, "log 123")
    test_bash_replace-->>TestRunner: test passed
Loading

File-Level Changes

Change Details Files
Update the Bash replacement unit test to exercise metavariable substitution in the replacer string.
  • Change the replacement string in the Bash replace test from a hardcoded literal to one that includes the captured metavariable
  • Keep the expected assertion value the same to confirm correct interpolation of the captured metavariable
  • Remove the obsolete TODO comment that requested this change
crates/language/src/bash.rs

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
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 - I've left some high level feedback:

  • Consider extending this test (or adding a sibling one) to cover a case where the same metavariable appears multiple times in the replacement string (e.g., log $A $A) to better exercise the substitution behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extending this test (or adding a sibling one) to cover a case where the same metavariable appears multiple times in the replacement string (e.g., `log $A $A`) to better exercise the substitution behavior.

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.

Copy link
Contributor

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

Updates the Bash language replacement test to validate metavariable substitution during replacement, aligning it with how other language tests exercise the replace engine.

Changes:

  • Replace the hardcoded replacement string ("log 123") with a metavariable-based replacer ("log $A") in test_bash_replace.
  • Remove the now-resolved TODO comment.

💡 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants