Skip to content

fix(pytest,grep): harden quiet summary and grep match parsing - #1273

Closed
siubing05 wants to merge 2 commits into
rtk-ai:developfrom
siubing05:fix/rewrite-regressions
Closed

siubing05 wants to merge 2 commits into
rtk-ai:developfrom
siubing05:fix/rewrite-regressions

Conversation

@siubing05

@siubing05 siubing05 commented Apr 13, 2026 •

Copy link
Copy Markdown

Summary

  • harden pytest quiet-mode summary detection and summary parsing
  • surface quiet-mode error/xfailed/xpassed/deselected outcomes correctly
  • harden grep match parsing for single-file output, Windows paths, and content containing colons
  • keep filenames in rg/grep output with -H and fix the output label typo

Why

While integrating RTK auto-rewrite into Hermes Agent, two parser edge cases showed up:

  • pytest -q can end with summaries like 25 passed in 3.92s, 1 error in 0.20s, or 2 deselected in 0.02s; the old logic mainly relied on the === ... === style summary and could fall back to Pytest: No tests collected
  • single-file grep output can omit the filename, and Windows paths / colon-rich content make naive split(':') parsing unsafe

Changes

pytest

  • add SummaryCounts parsing for passed / failed / errors / skipped / xfailed / xpassed / deselected
  • detect quiet summaries and no tests ran lines via is_summary_line()
  • preserve failure/error detail rendering in the compact RTK summary

grep

  • add parse_match_line() to safely parse file:line:text and fallback line:text
  • force filenames with -H for both rg and grep
  • add regression coverage for Windows paths and content containing colons

Validation

  • cargo test
  • cargo fmt --all --check
  • cargo clippy --all-targets

@CLAassistant

CLAassistant commented Apr 13, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal labels Apr 13, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes two parsing bugs: pytest quiet-mode output (e.g. '25 passed in 3.92s') was not recognized as a summary line, causing incorrect 'No tests collected' results, and ripgrep single-file searches emitting 'LINE:text' without a filename were being misparsed. Adds the -H flag to rg/grep for consistent filename output and introduces a robust parse_match_line() helper.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

@F0rty-Tw0

F0rty-Tw0 commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Hey @siubing05, heads up that I just opened #1554 which covers the same single-file grep parser fix as the grep portion of this PR. Yours has been open longer; I didn't notice it before starting, apologies for the duplicate effort.

For reviewers' context, the two approaches differ on Windows path handling:

  • This PR uses splitn(3, ':') with a 2-format fallback (handles line:content if -H is ever absent). On Windows abs paths like C:\foo\file.rs:42:content the splitn picks file="C" and the line-number parse fails, so the line gets dropped.
  • fix(grep): parse single-file output containing colons #1554 uses a greedy regex ^(.+):(\d+):(.*)$ that picks the LAST :digits: boundary, handling drive letters correctly.

Both fix the Linux/macOS reproducer in #1436. Whichever shape maintainers prefer, happy to defer or fold a Windows-path test fixture into this one if that's the path forward. Also no objection if you'd rather merge yours and I close #1554, your work was first.

@siubing05
siubing05 changed the base branch from master to develop May 1, 2026 06:13
@siubing05 siubing05 changed the title fix(pytest,grep): handle quiet pytest summaries and single-file grep rewrite fix(pytest,grep): harden quiet summary and grep match parsing May 1, 2026
siubing05 added 2 commits May 1, 2026 14:51
…rewrite

Found while integrating RTK auto-rewrite into Hermes Agent's terminal plugin.

pytest: quiet output (pytest -q) ends with lines like '25 passed in
3.92s' rather than '=== 5 passed ==='. The old parser only matched
the ===...=== format, so summary was never captured and the fallback
returned 'Pytest: No tests collected'.

grep: rg can emit 'LINE:text' (no filename) for single-file searches.
The old parser assumed 'file:line:text' unconditionally and corrupted
the result (e.g. '271' treated as filename instead of line number).

Fixes:
- is_summary_line() now handles quiet-mode and 'no tests ran' patterns.
- rg/grep invoked with -H to always include filename even for
  single-file searches.
- parse_match_line() helper parses both 'file:line:text' and
  'line:text' formats robustly.

Regression tests added for both paths.
@siubing05

Copy link
Copy Markdown
Author

Thanks for the heads-up — no worries on the overlap.

I’ve since updated this PR to cover the Windows-path issue you pointed out as well. The grep parser now handles drive-letter paths robustly, and I added regression coverage for that case in addition to the original single-file parsing fix.

This PR still also includes the pytest quiet-summary fix, so at this point it covers:

  • quiet pytest summary parsing
  • single-file grep output parsing
  • Windows absolute path parsing in grep matches

Latest head is 502d037 if maintainers want to review the updated version.

If maintainers prefer to keep everything in one place, I’m happy for this PR to stand as the combined fix.

@siubing05 siubing05 closed this May 9, 2026
@siubing05
siubing05 deleted the fix/rewrite-regressions branch May 9, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants