Skip to content

fix(tools): stop dropping grep hits under paths containing "test" - #42

Open
harshitgavita-07 wants to merge 1 commit into
openhackai:mainfrom
harshitgavita-07:fix-grep-test-substring-filter
Open

harshitgavita-07 wants to merge 1 commit into
openhackai:mainfrom
harshitgavita-07:fix-grep-test-substring-filter

Conversation

@harshitgavita-07

Copy link
Copy Markdown

Problem

FileSystemTools.grep in directory mode finds matches correctly, then post-filters them with:

if "node_modules" in rel or "test" in rel.lower():
    continue

The substring check drops every match whose path contains test anywhere, including ordinary source directories like src/latest/, src/contest/, or src/attest/. For a security scanner this silently removes real source files from search results, so findings in those files are never surfaced to the hunter agents.

Reproduction

src/latest/handler.py   # contains: eval(user_input)
src/contest/util.py     # contains: eval(user_input)

fs_tools.grep("eval") returns no matches for either file.

Fix

Replace the substring check with component-aware detection (_is_test_or_vendor_path): a path is skipped only when a directory component is a test/vendor directory by name (tests, __tests__, spec, fixtures, node_modules, ...) or the basename follows a test-file convention (test_*, *_test.*, *.test.*, *.spec.*, conftest.*). node_modules remains excluded both via --exclude-dir and the component check, so no new vendor noise appears.

Tests

New TestGrep cases in tests/test_filesystem_tools.py:

  • hits under src/latest/ and src/contest/ are returned (failed before the fix, pass after)
  • control: tests/test_app.py and src/app.test.js stay excluded (passed before, still pass)

Full suite: 513 passed (511 existing + 2 new; the static-validator tests from #40 are on their own branch).

FileSystemTools.grep's directory mode post-filtered results with
'test' in rel.lower(), silently discarding every match whose path
contained that substring anywhere - including source directories like
src/latest/, src/contest/ or src/attest/. A security scanner skipping
arbitrary source files means missed findings.

Replace the substring check with component-aware detection
(_is_test_or_vendor_path): whole-directory test names (tests, __tests__,
spec, fixtures, ...) and test-file naming conventions (test_*, *_test.*,
*.test.*, *.spec.*, conftest.*) are still skipped, everything else is
searched. node_modules stays excluded both via --exclude-dir and the
component check.

Adds TestGrep cases: src/latest/ and src/contest/ hits are returned,
while tests/test_app.py and src/app.test.js stay excluded.
@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

Replaces substring-based filtering in directory searches with checks for directory names and test-file names.

  • Directory searches keep source matches from paths containing “test” inside another word.

Reviews (1) · Last reviewed commit: "fix(tools): stop dropping grep hits unde..." · Reviewed by Greptile

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