Commit graph

1 commit

Author SHA1 Message Date
Abhay Singh
5e0f1a219f
fix(transforms): guard the lossless diff fold to diff-shaped content only (#2140)
## Description

`ContentRouter._lossless_first` tries several lossless folds and keeps
the smallest result. Most folds self-verify reversibility, but the
`diff` fold is subtractive: it removes `index <hex>..<hex>` lines
without an inverse check. That can silently delete matching lines from
non-diff text, logs, or search output.

## Fix

- Skip the `diff` fold unless the detected strategy is
`CompressionStrategy.DIFF` or the content is structurally diff-shaped.
- Keep genuine diffs folding their `index` bookkeeping.
- Add regression coverage for a non-diff `index ...` line and a real
diff.
- Merge current `main` to refresh mergeability and stale lint results.

## Testing

```text
uvx ruff@0.15.17 check headroom/transforms/content_router.py tests/test_lossless_diff_fold_guard.py headroom/memory/factory.py
All checks passed!

uvx ruff@0.15.17 format --check headroom/transforms/content_router.py tests/test_lossless_diff_fold_guard.py headroom/memory/factory.py
3 files already formatted

git diff --check headroomlabs/main...HEAD
# no output

uv run --extra dev python -m pytest tests/test_lossless_diff_fold_guard.py -q
2 passed
```

## Review Readiness

- [x] Ready for review
- [x] Regression tests added
- [x] CHANGELOG updated

Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
2026-07-13 23:39:33 -04:00