Skip to content

[llm-auto-fix] fixed code search where filePattern includes multiple values #159

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

genkernel
Copy link
Contributor

@genkernel genkernel commented Jun 15, 2025

Search code with a single filePattern extension works: *.js.
However when LLM specifies multiple (e.g.: *.ts|*.js|*.py|*.java|*.go) search breaks.

This is LLM-auto-fix that fixed that.

Summary by CodeRabbit

  • Bug Fixes
    • Improved support for specifying multiple file patterns in code search, allowing more flexible and accurate search results.
  • Tests
    • Added tests to verify handling of multiple, whitespace-padded, and empty file pattern inputs in code search.

Copy link
Contributor

coderabbitai bot commented Jun 15, 2025

"""

Walkthrough

The update changes how multiple file patterns are handled in the searchCode function. Instead of passing a single string to ripgrep's -g option, the string is split by the pipe (|) character, and each pattern is supplied as a separate -g argument. Minor formatting adjustments were also made. Additionally, a new asynchronous test was added to verify handling of multiple, whitespace-padded, and empty file pattern tokens.

Changes

File(s) Change Summary
src/tools/search.ts Modified to split filePattern by `
test/test-search-code-edge-cases.js Added async test testFilePatternWithMultipleValues to verify multiple and complex filePattern inputs, including trimming and ignoring empty tokens.

Poem

In the warren of code, patterns abound,
Now each one is found, not tangled or bound!
Split by a pipe, they hop in a row,
Ripgrep now searches wherever you go.
With a twitch of the nose and a flick of the ear,
The search is much clearer—let’s all give a cheer! 🐇✨
"""


📜 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 dfb8f5a and f3721d0.

📒 Files selected for processing (1)
  • test/test-search-code-edge-cases.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/test-search-code-edge-cases.js
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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 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 (1)
src/tools/search.ts (1)

120-123: Remove stray blank lines added inside the catch block.

The three empty lines add noise without value and break the otherwise consistent style in this file. Deleting them improves readability and keeps the diff minimal.

-
-
-
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4338ebb and 5e63e2c.

📒 Files selected for processing (1)
  • src/tools/search.ts (3 hunks)

@wonderwhy-er
Copy link
Owner

Hmm, good catch, need some kind of test for it
Will take a look at some point

@genkernel
Copy link
Contributor Author

Hmm, good catch, need some kind of test for it Will take a look at some point

I told Goose (agent) to call a tool with various filePatterns & verified it works. But surely I cant tell it to write a proper test too!

Will update.

@wonderwhy-er
Copy link
Owner

Hmm, good catch, need some kind of test for it Will take a look at some point

I told Goose (agent) to call a tool with various filePatterns & verified it works. But surely I cant tell it to write a proper test too!

Will update.

heh, yeah I do that too, ask Claude to test tools itself :D
but its better to have some kind of test

There is folder with tests, just ask AI to check it out around edit/search tools

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)
test/test-search-code-edge-cases.js (2)

370-377: Create test fixtures concurrently for better I/O throughput

The six fs.writeFile calls are awaited sequentially, slowing the suite (~40-50 ms on fast SSD, more on CI).
Bundling them in Promise.all keeps code short and shaves time.

-  await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file1.ts'), 'export const myTsVar = "patternTs";');
-  await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file2.js'), 'const myJsVar = "patternJs";');
-  await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file3.py'), 'my_py_var = "patternPy"');
-  await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file4.java'), 'String myJavaVar = "patternJava";');
-  await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file5.go'), 'var myGoVar = "patternGo"');
-  await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file6.txt'), 'This is a text file.');
+  await Promise.all([
+    fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file1.ts'),  'export const myTsVar  = "patternTs";'),
+    fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file2.js'),  'const myJsVar        = "patternJs";'),
+    fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file3.py'),  'my_py_var            = "patternPy"'),
+    fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file4.java'),'String myJavaVar     = "patternJava";'),
+    fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file5.go'),  'var myGoVar          = "patternGo"'),
+    fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file6.txt'), 'This is a text file.')
+  ]);

Minor, but keeps the ever-growing test file snappy.


414-420: Add a positive assertion for the “no-match” scenario

The last check only verifies that certain filenames are absent.
If the search unexpectedly returns matches in other files, the test still passes.
Strengthen it by asserting the “no matches” message (or empty result).

-  assert(!text.includes('file1.ts'), 'Should not find any matches with only empty patterns');
-  assert(!text.includes('file2.js'), 'Should not find any matches with only empty patterns');
+  assert(!text.includes('file1.ts'), 'Should not find any matches with only empty patterns');
+  assert(!text.includes('file2.js'), 'Should not find any matches with only empty patterns');
+  assert(
+    text.includes('No matches') || text.trim() === '',
+    'Expected explicit “no matches” feedback when filePattern resolves to nothing'
+  );

Tightens the expectation and protects against silent false positives.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5e63e2c and dfb8f5a.

📒 Files selected for processing (2)
  • src/tools/search.ts (3 hunks)
  • test/test-search-code-edge-cases.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tools/search.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/test-search-code-edge-cases.js (4)
test/run-all-tests.js (2)
  • colors (16-25)
  • result (140-140)
test/test-search-code.js (23)
  • colors (22-28)
  • result (136-139)
  • result (160-164)
  • result (179-183)
  • result (200-204)
  • result (221-225)
  • result (263-267)
  • result (287-291)
  • result (310-314)
  • result (333-336)
  • result (355-358)
  • result (409-412)
  • text (145-145)
  • text (166-166)
  • text (185-185)
  • text (206-206)
  • text (231-231)
  • text (269-269)
  • text (293-293)
  • text (319-319)
  • text (342-342)
  • text (362-362)
  • text (414-414)
test/test.js (1)
  • fs (41-41)
src/handlers/edit-search-handlers.ts (1)
  • handleSearchCode (25-90)

@genkernel
Copy link
Contributor Author

Added a test that verifies filePattern with various combinations:

'|||'
'|*.ts||*.py|'
' *.ts | *.js '
'*.ts|*.js|*.py'

@genkernel
Copy link
Contributor Author

Cha-ching: ready for review.

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