Repository navigation
fix: print search stats after matches - #146
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new indexed ordering test should use an isolated --index-path (consistent with the existing indexed tests) to avoid writing .tgrep into the searched tree and reduce brittleness.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes --stats output ordering so that human-readable stats are emitted after buffered match output when stdout/stderr are combined (aligning behavior with ripgrep), and adds regression tests to prevent the ordering from regressing.
Changes:
- Flush stdout match output before printing human-readable
--statslines in brute-force, local-index, and server search paths. - Defer local-index “Query plan” stats until after matches are written.
- Add regression tests validating match output precedes stats when stdout and stderr are merged.
File summaries
| File | Description |
|---|---|
| tgrep-cli/src/search.rs | Flushes buffered match output before emitting --stats lines; defers query-plan stats until after matches. |
| tgrep-cli/tests/ripgrep_compat.rs | Adds brute-force and indexed regression tests that validate match output precedes stats on a combined stream. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <[email protected]> Signed-off-by: Shengyu Fu <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The new combined-stream tests keep write handles open while reading the merged output file, which can make the tests less robust (especially across platforms/filesystems).
Review details
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
tgrep-cli/tests/ripgrep_compat.rs:187
- The test reads
merged_pathwhile the parent process still holds write handles (stdout/merged) open. On some platforms this can cause sharing/flush issues and makes the test less robust. Drop the write handles before reading the file contents.
This issue also appears on line 222 of the same file.
tgrep-cli/tests/ripgrep_compat.rs:224
- As above, drop the merged-output write handles before reading the file so the test is robust across platforms and filesystems.
assert!(status.success());
let output = fs::read_to_string(merged_path).unwrap();
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
Addressed the review feedback in commit 71a5e84:
Copilot review |
There was a problem hiding this comment.
🟢 Approval recommended
The change is low-risk, directly addresses the reported ordering problem, and includes targeted regression coverage.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
tgrep-cli/src/search.rs:1327
- The
--statsmessage for a single-file brute-force search says "(1 files)", which is grammatically incorrect and user-visible in--statsoutput.
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
Addressed the final review note in commit Revalidated with |
There was a problem hiding this comment.
🔵 Needs a closer look
The new pre-stats writer.flush()? calls can propagate BrokenPipe and prevent --stats from being printed to stderr in common pipeline scenarios where stdout is closed early.
Review details
Suppressed comments (4)
Previously missed (1) — in code that hasn't changed since the last review.
tgrep-cli/src/search.rs:1088
writer.flush()?here is only needed to preserve stdout/stderr ordering, but it can returnBrokenPipewhen stdout is closed early (e.g.,tgrep ... | head). Using?will abort before writing the--statssummary to stderr, which is surprising since stderr is still writable. Consider ignoringBrokenPipefor this pre-stats flush and only erroring on other flush failures.
This issue also appears in the following locations of the same file:
- line 1204
- line 1324
- line 1369
tgrep-cli/src/search.rs:1204
- This pre-stats
writer.flush()?is intended for output ordering, but?will propagateBrokenPipeand prevent the--statslines from being printed to stderr when stdout is closed early by a downstream consumer. Consider ignoringBrokenPipefor this flush (only for ordering) so stats can still be emitted.
writer.flush()?;
tgrep-cli/src/search.rs:1324
writer.flush()?before printing stats can returnBrokenPipewhen stdout is closed early (common in pipelines). Using?here will skip the stats line entirely even though it is written to stderr. Consider ignoringBrokenPipefor this ordering flush so--statsremains observable.
writer.flush()?;
tgrep-cli/src/search.rs:1369
- Same concern as the other stats flush sites: propagating
BrokenPipehere can prevent--statsfrom being printed to stderr when stdout is closed early. If the goal is just ordering, consider ignoringBrokenPipefor this flush.
writer.flush()?;
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
Addressed the latest review feedback in commit
Copilot review |
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, behavior is covered by targeted regression tests, and the updated output ordering matches the stated requirements without introducing conflicting behavior in the reviewed paths.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
Closes #145
Summary
--statsmessages.Previously, stdout buffering caused
--statsto appear before matches when stdout and stderr were combined, so the summary was easy to miss during large searches.Validation
cargo test --workspacepasses.cargo fmt --all -- --checkpasses.cargo clippy --workspace --all-targets -- -D warningspasses.