Repository navigation
fix(tools): stop dropping grep hits under paths containing "test" - #42
Open
harshitgavita-07 wants to merge 1 commit into
Open
harshitgavita-07 wants to merge 1 commit into
harshitgavita-07 wants to merge 1 commit into
Conversation
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.
[Medium impact] This PR appears safe to merge. SummaryReplaces substring-based filtering in directory searches with checks for directory names and test-file names.
Reviews (1) · Last reviewed commit: "fix(tools): stop dropping grep hits unde..." · Reviewed by Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
FileSystemTools.grepin directory mode finds matches correctly, then post-filters them with:The substring check drops every match whose path contains
testanywhere, including ordinary source directories likesrc/latest/,src/contest/, orsrc/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
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_modulesremains excluded both via--exclude-dirand the component check, so no new vendor noise appears.Tests
New
TestGrepcases intests/test_filesystem_tools.py:src/latest/andsrc/contest/are returned (failed before the fix, pass after)tests/test_app.pyandsrc/app.test.jsstay excluded (passed before, still pass)Full suite: 513 passed (511 existing + 2 new; the static-validator tests from #40 are on their own branch).