Repository navigation
fix(pr_agent/algo/git_patch_processing.py): skipping lines that are not unified hunk headers - #2755
Conversation
…ot unified hunk headers
… that starts with @@ but is not a hunk header
PR Summary by QodoGuard unified hunk parsing: skip non-matching '@@' lines and keep valid hunks
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1.
|
…ped hunk before a valid one
|
Code review by qodo was updated up to the latest commit 14dc0ca |
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Thanks for guarding both call sites, and for regression tests that bite: four of the six go red against main; the two green ones are your no-regression guards. I have corrected the description to match the diff (it said 5 tests each failing without the fix, and its file list omitted the new test file).
For the record: gvago's #2330 guarded the same two call sites in April and is closed as superseded, with credit carried in this merge commit; #2798 covered one of them this morning and follows. One behavior note: an unparseable patch now returns the header-only tuple rather than ("", ""), so /ask_line fires its model call where today it skips. That matches the existing range-miss contract, so it is not blocking; I will file a follow-up on the caller's gate.
Closes #2756.
Description
extract_hunk_headers(match)is called whenever a line starts with@@, without checking thatRE_HUNK_HEADERactually matched.Root cause
A
@@-prefixed line that is not a standard unified hunk header — a combined/merge diff@@@ … @@@, for instance — makesRE_HUNK_HEADER.matchreturnNone, which is then passedstraight to
extract_hunk_headers.Scoping, stated honestly: I could not demonstrate a provider that surfaces such a patch, so
this is a latent robustness gap rather than a reachable crash. The
plain-diffprovider acceptsarbitrary user-supplied diffs and is the most plausible route.
The fix
Both sites check
RE_HUNK_HEADER.match(line)first. An unrecognised@@line is logged and skipped, and inextract_hunk_lines_from_patchits body is skipped too, so the valid hunks in the same patch still parse.Behaviour change
@@line raises, or silently discards the whole patchFiles changed
Testing
New regression coverage in
tests/unittest/test_hunk_header_parse_guard.py— 6 tests: four failwithout the fix, two pin the no-regression cases:
Proven to be a genuine regression test: with every changed
pr_agent/file reverted to itsorigin/mainversion and the new test file left in place, the suite fails. It only passeswith the fix applied.
Full pipeline, reproduced locally exactly as
.github/workflows/build-and-test.yamlruns it:on
python:3.12.13-slim— no failures.Also checked:
pytest tests/unittest— no new failures vsmainruff— no new findings vsmain;isort— clean on every file touchedRisk / compatibility
Well-formed patches take an identical path — the match result was already computed at both sites.
tests/unittest/test_diff_pipeline_core.py::test_malformed_patch_returns_empty_tupleasserted theold
("", "")return, and its own comment described it as a consequence of the crash beingswallowed. It is updated to assert the new contract — no hunk content is produced — and renamed
accordingly.
Checklist
Maintainer edit (IsmaelMartinez): corrected the file list and test-count claims to match the diff; see review below.