Skip to content

Fix passthru output when no lines match - #128

Merged
Shengyu Fu (shengyfu) merged 3 commits into
mainfrom
shengyfu-fix-passthru-no-match
Sep 3, 2026
Merged

Shengyu Fu (shengyfu) merged 3 commits into
mainfrom
shengyfu-fix-passthru-no-match

Conversation

@shengyfu

Copy link
Copy Markdown
Member

Summary

  • route effective --passthru searches through every eligible indexed file
  • emit no-hit text files through the existing context-line path in local and server-backed searches
  • preserve exit status 1 when there are no actual matches, including server responses containing only context rows
  • retain binary-file and output-only mode behavior

Testing

  • cargo test --test ripgrep_compat passthru -- --nocapture
  • cargo test --test ripgrep_compat new_flags_agree_across_search_paths -- --nocapture
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace

Closes #126

Copilot AI balanced review requested due to automatic review settings September 1, 2026 03:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Balanced
Findings: 1 High severity · 2 Medium severity

New issues introduced by this change (3)
Severity Finding
Medium severity tgrep-cli/​tests/​ripgrep_compat.rs — This test does not exercise the indexed path: naming a file makes run set bypass_index and call…
Medium severity tgrep-cli/​tests/​ripgrep_compat.rs — Passing this explicit file also triggers bypass_index before server discovery…
High severity tgrep-cli/​src/​serve.rs — MatchAll applies to the server's entire index, because the request does not carry the CLI's…
What changed in this PR

Fixes --passthru so eligible text files are emitted even without matches while preserving exit status and binary behavior.

Changes:

  • Uses full indexed-file enumeration for passthru.
  • Emits no-hit files through context output.
  • Adds local, indexed, binary, and server-oriented tests.
File Description
tgrep-cli/​src/​search.rs Handles no-hit passthru output and exit status.
tgrep-cli/​src/​serve.rs Adds server-side full-file passthru handling.
tgrep-cli/​tests/​ripgrep_compat.rs Adds passthru regression coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tgrep-cli/tests/ripgrep_compat.rs Outdated
Comment thread tgrep-cli/tests/ripgrep_compat.rs Outdated
Comment thread tgrep-cli/src/serve.rs Outdated
Copilot AI review requested due to automatic review settings September 1, 2026 03:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Balanced
Findings: 1 High severity · 2 Medium severity

Pre-existing issues (3)
Severity Finding
High severity tgrep-cli/​src/​serve.rs — MatchAll applies to the server's entire index, because the request does not carry the CLI's… View comment
Medium severity tgrep-cli/​tests/​ripgrep_compat.rs — Passing this explicit file also triggers bypass_index before server discovery… View comment
Medium severity tgrep-cli/​tests/​ripgrep_compat.rs — This test does not exercise the indexed path: naming a file makes run set bypass_index and call… View comment
Suppressed comments (4)

tgrep-cli/tests/ripgrep_compat.rs:2730

  • A file target bypasses server delegation entirely (search.rs:492-528), so the running daemon is never queried and the “Server unreachable” assertion passes vacuously. Target the one-file root directory instead so this exercises the new server context-row response and client exit-status calculation.
            path.to_str().unwrap(),

tgrep-cli/tests/ripgrep_compat.rs:2743

  • Because path resolves to a file, the indexed and server iterations both bypass their advertised paths and run brute-force search (search.rs:492-528). Point the shared target at root so the test actually validates -m 0 through local-index and server request handling.
    let path = root.join("hello.rs");
    let path = path.to_str().unwrap();

tgrep-cli/tests/ripgrep_compat.rs:2596

  • This target is a single file, so search::run sets bypass_index and executes the brute-force path (search.rs:492-528). As a result, this test does not cover the changed local-index candidate selection or the no-match FileOutcome handling it is named for. Use a directory target and assert that all eligible files are emitted while the process still exits 1.
            path.to_str().unwrap(),

tgrep-cli/src/serve.rs:1294

  • Making passthru a MatchAll server query causes the daemon to search its entire index even for a subtree request, materialize every file line into nested vectors, serialize one large JSON response, and only then let the client discard out-of-scope rows (serve.rs:1514-1554, search.rs:692-734). For large repositories this makes memory and network usage scale with the full repository and can exhaust the daemon/client. Bypass server delegation for effective passthru, or add server-side scope plus streaming/bounded responses.
    let plan = if passthru || invert_match || encoding.may_differ_from_index() {
        query::QueryPlan::MatchAll

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: c4fb5038-6356-4740-aab0-2216d80e27bd
Copilot AI review requested due to automatic review settings September 2, 2026 23:50
@shengyfu
Shengyu Fu (shengyfu) force-pushed the shengyfu-fix-passthru-no-match branch from 82673a2 to 9956009 Compare September 2, 2026 23:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Server bypass can omit live additions and emit tombstoned or newly ignored files from a stale on-disk index.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity tgrep-cli/​src/​search.rs — Bypassing the daemon here makes --passthru discover candidates only from the on-disk…
Issues resolved since last review (3)
Severity Finding
High severity tgrep-cli/​src/​serve.rs — MatchAll applies to the server's entire index, because the request does not carry the CLI's… View resolved comment
Medium severity tgrep-cli/​tests/​ripgrep_compat.rs — Passing this explicit file also triggers bypass_index before server discovery… View resolved comment
Medium severity tgrep-cli/​tests/​ripgrep_compat.rs — This test does not exercise the indexed path: naming a file makes run set bypass_index and call… View resolved comment

Comment thread tgrep-cli/src/search.rs
// never reports.
if !opts.no_index
&& !bypass_index
&& !opts.effective_passthru()
@shengyfu
Shengyu Fu (shengyfu) merged commit d0d325b into main Sep 3, 2026
10 checks passed
@shengyfu
Shengyu Fu (shengyfu) deleted the shengyfu-fix-passthru-no-match branch September 3, 2026 00:02
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.

--passthru wont print every line when a match is NOT found

2 participants