Files
kylehgc ee614e4c63 fix(diff): region parser for condense_unified_diff -- budget-owned hunks, raw fallback
Parse the stream into (prologue)(file-header)(hunk)* regions before
classifying: hunk extent comes from the @@ line budget (one old-budget per
parent, so @@@ combined headers parse too), content is classified only
inside hunks, and any structural disagreement (invalid body prefix, budget
over/under-run, budget owed at EOF, malformed @@) falls back to raw
passthrough. Detector precedence is a documented total order on
condense_unified_diff_strict.

Fixes, each with its reproducer from
claudedocs/diff-classifier-review-2026-08-29.md as a test:
- SQL/Lua '-- comment' removals (--- on the wire) no longer dropped
- added '++ text' lines no longer parsed as file headers
- format-patch mbox prose and the '-- ' signature no longer counted
- +++ /dev/null deletions named by their --- side
- binary / rename-only / mode-only sections reported instead of vanishing
- --color input stripped (was: silently empty output), non-UTF-8 stdin
  read lossily (was: hard error, no fallback)
- CRLF content bytes survive verbatim (split('\n'), not lines())
- b/ prefix stripped exactly once; timestamps tab-split from header names
- the '... +N more' trailer removed: it claimed truncation that never
  happened (all lines were printed above it)

Fixture corpus: 13 real-producer captures (git 2.54, GNU diff) in
tests/fixtures/diff -- multi-file, -U0, -W, rename/delete/binary,
log -p, show --cc, format-patch single/series/cover, diff -u/-ru/-rN,
CRLF. Property tests: every marked body line survives to the output,
counters equal rendered lines, the fallback fires on zero corpus fixtures.
2026-08-30 22:29:17 +00:00

21 lines
522 B
Plaintext

diff -rNu a/f1.txt b/f1.txt
--- a/f1.txt 2026-08-29 22:45:15.660427700 -0400
+++ b/f1.txt 2026-08-29 22:45:15.660427700 -0400
@@ -1,3 +1,4 @@
alpha
-beta
+BETA
gamma
+delta
diff -rNu a/newfile.txt b/newfile.txt
--- a/newfile.txt 1969-12-31 19:00:00.000000000 -0500
+++ b/newfile.txt 2026-08-29 22:45:15.660427700 -0400
@@ -0,0 +1 @@
+only in b
diff -rNu a/sub/deep.txt b/sub/deep.txt
--- a/sub/deep.txt 2026-08-29 22:45:15.660427700 -0400
+++ b/sub/deep.txt 2026-08-29 22:45:15.660427700 -0400
@@ -1 +1,2 @@
same
+more