Skip to content

fix(grep): keep FilePath scope in regex/literal fallback (#756) - #764

Merged
dmtrKovalenko merged 2 commits into
mainfrom
triage-bot/issue-756
Aug 12, 2026
Merged

fix(grep): keep FilePath scope in regex/literal fallback (#756)#764
dmtrKovalenko merged 2 commits into
mainfrom
triage-bot/issue-756

Conversation

@gustav-fff

Copy link
Copy Markdown
Collaborator

Closes #756

Root cause

Two layers. The AI-mode parser splits on whitespace, so regex fragments ^/\* and |^\s*/\* (both contain /+*) are misparsed as Glob constraints, leaving only ---------- as grep text. Those bogus globs match nothing, so the constrained search is empty and the literal/regex fallback at crates/fff-core/src/grep/grep.rs:232 rebuilt the query with constraints: Vec::new(), discarding the user's FilePath("scope/target.css") scope. In regex mode the raw query is then re-run whole and the top-level | branch ^\s*/\* ---------- matches /* ---------- in every file.

Fix

crates/fff-core/src/grep/grep.rs: the fallback now preserves FilePath constraints (only the swallowed operator/glob tokens are dropped), so a pinned path can't be escaped. Regression test added in grep_tests.rs.

Steps to reproduce

On pre-fix origin/main:

mkdir /tmp/fff-756 && cd /tmp/fff-756
npm init -y && npm install @ff-labs/fff-node@0.10.3

Save repro.mjs from the issue, then:

node repro.mjs ./out.log

Expected: actualPaths limited to ["scope/target.css"], filteredFileCount/totalFilesSearched = 1.
Actual (pre-fix):

{"actualPaths":["outside.css","scope/target.css"],"totalMatched":2,"filteredFileCount":2,"totalFilesSearched":2}

How verified

Added e2e regression test reproducing the exact query through the core pipeline (AiGrepConfig + regex mode):

cargo test -p fff-search grep
# test result: ok. 6 passed; 0 failed  (incl. regex_fallback_keeps_file_path_scope_issue_756)
cargo test -p fff-search --test grep_integration
# test result: ok. 68 passed; 0 failed
cargo clippy -p fff-search   # clean

Pre-fix the new test yields ["outside.css","scope/target.css"]; post-fix ["scope/target.css"].

Automated triage via Gustav. Honk-Honk 🪿

The literal/regex fallback rebuilt the query with empty constraints,
dropping an explicit inline FilePath scope. In regex mode a top-level
alternation then leaked matches into files outside the pinned path.
Preserve FilePath constraints in the fallback query.

Closes #756
@dmtrKovalenko
dmtrKovalenko merged commit 2107f03 into main Aug 12, 2026
52 checks passed
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.

[Bug]: AI-mode regex fallback can discard path constraints

2 participants