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

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
abhijit-s pushed a commit to abhijit-s/fff that referenced this pull request Aug 13, 2026
Brings in upstream fixes on top of our 0.18.0 fork:
- fix(grep) dmtrKovalenko#756/dmtrKovalenko#764: literal/regex fallback now keeps an explicit
  FilePath scope so a top-level regex alternation can't leak matches
  outside the pinned path
- fix dmtrKovalenko#754/dmtrKovalenko#765: missing clap attribute on no_content_indexing
- fix(bun) dmtrKovalenko#766: proper build step for fff-bun
- chore dmtrKovalenko#762: rename stale fff.nvim repo refs to fff

Conflicts resolved preserving fork divergences:
- update_check.rs / install-mcp.sh: kept our DEFAULT_REPO=abhijit-s/fff
  and FFF_UPDATE_REPO override; upstream's fff.nvim->fff rename does not
  apply since we target our own fork for update checks and installs
- README.md: kept our rewritten Homebrew-tap/apt/fffctl install section;
  upstream only tweaked a release URL in a block our fork already removed
- grep_tests.rs: add/add at EOF resolved as a union — kept our three
  cold-start readiness tests and adopted upstream's dmtrKovalenko#756 regex-scope test,
  reflowing the shared trailing braces so both functions close correctly

grep.rs auto-merged; reviewed the dmtrKovalenko#756 fallback change against our
surrounding fork logic and confirmed coherence. Makefile .PHONY targets
and the per-root ignore feature (ignore.rs/main.rs) preserved; workspace
stays at 0.18.0. Build green (fff-mcp/fff-engine/fff-ctl); fff-search +
fff-engine tests 375 passed, 0 failed.
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