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 |
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— 5 tests, each written to failwithout the fix:
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