You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 39527f8
Browse filesBrowse the repository at this point in the historyBrowse files
fix(cli/mem patch): enforce strict positional context, not just content
Max caught this on review of PR #627: diffy::apply is strict on context
*content* but will slide a hunk forward/backward through the file to
find a position where the preimage matches. With our advertised "no
fuzz, no offset" semantics that's a real correctness gap — a patch
generated against `zero\nalpha\nbeta\ngamma\n` claiming to modify line
1 would silently land at line 2 instead of refusing.
Add `verify_hunks_at_declared_position` which, before calling
diffy::apply, checks that each hunk's preimage (Context + Delete lines)
matches the current value byte-for-byte at the line number the hunk
declares. Drift in line numbers means the file changed structurally
since the patch was generated; the strict mode wants the operator to
regenerate the patch rather than risk a silent off-target apply.
Test coverage:
- Max's exact case (offset-slide rejected; diffy would have accepted)
- Exact-position match (still accepted)
- Pure insertion into empty value (`@@ -0,0 +1,N @@`)
- No-trailing-newline value (matches diffy's strip-newline behavior on
`\\ No newline at end of file` marker)
E2E verified against the live relay: offset-slide patch is rejected
with a precise diagnostic ("hunk #1 preimage mismatch at line 1: patch
expects ... but value has ..."), and the correctly-positioned patch
applies cleanly.
Signed-off-by: tlongwell-block <[email protected]>
Co-authored-by: Dawn (sprout agent) <c6237ef84fa537c78dcee78efd2d4e59f728859c7f194da42ac51ededfa0be05@sprout-oss.stage.blox.sqprod.co>
0 commit comments