fix(file-ops): keep spaced filenames in files_only search results - #40707
fix(file-ops): keep spaced filenames in files_only search results#40707TabooHarmony wants to merge 1 commit into
Conversation
|
Thanks for isolating the regression. The premise is confirmed on current main: Problems
Suggested changes
This is an automated hermes-sweeper review. |
match output by line shape. The bare-path shape regex (^[^\s:][^\s]*$) forbids whitespace, so a files_only line like "My Document.md" is misclassified as a diagnostic and silently stripped from results. No error is raised. Content and count modes are unaffected: their path:line and path:count shapes satisfy the regex via the :N anchor. In files_only mode, classify by tracking rg's multi-line "regex parse error:" block instead of the whitespace-hostile shape regex. A parse error aborts the search, so no real matches are interleaved with its continuation lines; a line is stripped only while inside an active parse-error block. Every other files_only line is treated as a real path and preserved verbatim — including names containing spaces, or names that happen to start with "error:". The hard-error path (rg:/grep: prefix and the parse-error block) is still classified as diagnostics, so genuine failures are surfaced unchanged. Adds regression tests for spaced-path preservation, continued hard-error detection, and the two awkward-but-valid filename cases (leading "error:", leading whitespace) in files_only mode.
bb21f4c to
e45cc63
Compare
|
Addressed the review feedback and rebased onto current main. Added a parameterized end-to-end regression test using the existing The new test fails against current main for both grep and ripgrep, and passes with this fix. Relevant file-operation and search tests pass locally, aside from the existing unreadable-file cases that cannot reproduce under root because root can read |
What does this PR do?
Fixes a regression from #39858 where
search_filesinfiles_onlymode silently drops any matching file whose name contains a space.#39858 added
_split_tool_diagnosticsto separate rg/grep error text from match output by line shape (since_execmerges stderr into stdout). The bare-path shape regex (^[^\s:][^\s]*$) forbids whitespace, so a files-only output line likeMy Document.mdorsub/Meeting Notes.txtfails the regex, carries norg:/grep:prefix, and gets folded into the "diagnostics" bucket — stripped from the result. No error is raised, so the loss is silent.Content and count modes are unaffected: their
path:line:content/path:countshapes satisfy the regex via the:Nanchor. Only files_only, with its bare unanchored path lines, is hit.The fix makes
_split_tool_diagnosticsmode-aware. Infiles_onlymode it tracks rg's multi-lineregex parse error:block and strips a line only while inside an active block. A regex parse error aborts the search, so no real matches are interleaved with its continuation lines — every other files_only line is treated as a real path and preserved verbatim, including names with spaces and (as a bonus) names that happen to start witherror:or with leading whitespace. The hard-error path (rg:/grep:prefixed lines and the parse-error block) is still classified as diagnostics, so genuine failures are surfaced unchanged.Related Issue
No separate issue — the regression and its repro are self-contained below.
Type of Change
Changes Made
tools/file_operations.py:_split_tool_diagnosticstakes anoutput_modeargument (default"content", backward compatible). In files_only mode it classifies by parse-error-block tracking instead of the whitespace-hostile content shape regex._search_with_rg/_search_with_greppassoutput_mode.tests/tools/test_search_error_guard.py:test_files_only_preserves_spaced_paths— spaced names survive.test_files_only_still_drops_regex_parse_error— hard error still classified as diagnostics in files_only mode.test_files_only_keeps_path_named_like_error_summary— a file namederror: notes.mdis preserved.test_files_only_keeps_indented_path_outside_error_block— a path with leading whitespace is preserved outside a parse-error block.How to Test
Reproduce the drop on
main:Before: only
normal.pyandsub/clean.txt(two spaced names dropped, no error). After: all four files returned. Reproduces on both_search_with_rgand_search_with_grep.Run the tests:
Checklist
Code
fix(file-ops):)Documentation & Housekeeping