Skip to content

fix(diff): refresh adoption of upstream #3268 — Myers alignment, FileComparison, listing budgets - #153

Merged
kylehgc merged 2 commits into
developfrom
adopt/3268-refresh
Sep 1, 2026
Merged

kylehgc merged 2 commits into
developfrom
adopt/3268-refresh

Conversation

@kylehgc

@kylehgc kylehgc commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Closes #152. Adoption refresh of upstream rtk-ai#3268 (Ilia Alshanetsky), replacing the early snapshot the fork carried (ce07aff, 54cb3a1, fork test c7d29b0) with the PR's current head ecef036.

Commits

Commit Author Kind
cherry-pick of ecef036 Ilia Alshanetsky Adoption, authorship preserved. Conflict resolution against the fork's diff_cmd.rs folded into the cherry-pick (no code of the fork's own added).

| 7753ec7 | kylehgc | Amendment: one-line clippy int_plus_one fix in the PR's test-only replay_classic helper (start1 >= cursor + 1 → start1 > cursor). The fork's gate runs clippy 1.97 with -D warnings; kept separate so the contributor's commit stays intact. |

Repro, real binaries (before = installed develop build, after = this branch)

CRLF-only difference and a single insertion render identically on both sides (differs, text matches (line endings: 0 CRLF vs 2 CRLF), exit 1; 0a1 / > NEW, exit 1). The behavioural change is the over-budget case — two 6000-line files with no line in common:

# before: LCS cell cap exceeded → wholesale replacement, 12002 lines of classic diff
1,6000c1,6000
< alpha 0
< alpha 1
...
# after: refuses to list, says why, 2 lines
big_a.txt → big_b.txt
   6000 lines differ, too many to list; use `rtk proxy diff` for the full text

What changed vs. the fork's snapshot

Resolution (22 conflict blocks, all in diff_cmd.rs)

Every block resolved to the PR's side, with two exceptions, both to keep the fork's region parser (condense_unified_diff, fork PR #128 / upstream rtk-ai#3788) intact:

  1. Imports: the PR's use anyhow::Result; became use anyhow::{Context, Result}; — condense_stdin uses .context().
  2. Test helpers: the PR's render_file_diff / changes_of helpers kept, plus the fork's test-local strict/passthrough condense_unified_diff wrapper appended after them.

git diff develop -- src/cmds/git/diff_cmd.rs shows no change to any region-parser symbol. Two fork tests dropped as stale (test_compute_diff_over_cell_cap_emits_wholesale_replacement, test_compute_diff_wholesale_replacement_still_pairs_by_similarity — both assert the removed LCS cap). Two PR tests absent by design (test_condense_unified_diff_large_no_false_overflow_indicator, _no_false_overflow): they are upstream's old condense tests, already replaced by the region parser's own.

Safety gate

External code was read in full before any cargo invocation: only src/cmds/git/diff_cmd.rs and src/core/guard.rs touched; no Cargo.toml, build.rs, or dependency changes. No process spawning, network, env access, or unsafe; the only filesystem access is the pre-existing fs::read_to_string of the two compared files; new imports are intra-crate only. Test bodies allocate up to ~1.1 MB strings and run bounded randomized loops (capped by MAX_TRACE_CELLS / POSITIONAL_BYTE_CAP), CPU-heavy but finite.

Quality gate

x64 host toolchain: cargo fmt --all clean · cargo clippy --all-targets 0 warnings (after the amendment; the bare cherry-pick tripped int_plus_one) · cargo test --all 3122 unit tests passed, 0 failed, 8 ignored; all integration suites green. Independent reviewer pass over fidelity to both the PR and the fork's region parser: guard.rs byte-identical to the PR; every line differing from pr-3268 in diff_cmd.rs is region-parser content already on develop, the Context import, or the test-helper wrapper; region parser body byte-identical to develop; no external callers of the changed private symbols (main.rs calls only the unchanged run / run_stdin). Only cosmetic note: one blank line before #[cfg(test)] follows the PR's shape now.

Upstream status

rtk-ai#3268 is still open with CHANGES_REQUESTED (KuSh, 2026-09-01). This is an Adoption: self-healing upstream, no upstream PR obligation. If the next review round changes the shape again, this refresh repeats.

🤖 Generated with Claude Code

iliaal and others added 2 commits September 1, 2026 17:39
`rtk diff <f1> <f2>` decided identity from `str::lines()`, which strips a
trailing `\r` and treats the final newline as optional. A CRLF-vs-LF pair
printed "[ok] Files are identical" and exited 0, so a verification gate built
on `diff` silently passed. Identity is now decided on the bytes, and when the
bytes differ while the text matches, the render names the cause instead of
listing visually identical strings.

`compute_diff` compared line N to line N, so one inserted line desynchronized
the whole tail: 200 lines with one insertion rendered 403 lines of output, and
the `never_worse` guard threw that away and dumped both files. It now trims the
common prefix and suffix and aligns the middle with Myers' greedy algorithm,
bounded by a banded trace of 1,000,000 cells rather than by the edit distance.
A lopsided pair keeps a window a few diagonals wide however large `d` grows, so
one line against five thousand aligns instead of being refused.

Every reported change carries a line number in each file. The classic renderer
needs both: `NaM` anchors an append in file1 and ranges it in file2, `NdM` does
the reverse, and after one insertion neither frame can be derived from the
other. A dissimilar in-place rewrite stays one `Replaced` rather than becoming a
`Removed` plus an `Added`, so the classic path groups it as a single change hunk
without inferring the pairing from equal line numbers.

All three listing paths are bounded by count and by bytes, and the aligned path
spends its count budget before the script exists: `myers_ops` knows the edit
distance when it reaches the end, so one line against 40,000 refuses without
cloning a script it would throw away. Past the budget, equal lengths pair by
position and say so, and unequal ones report a measured floor plus line bounds
in each file.

Rebased onto develop, which merged rtk-ai#3048 in the meantime. An empty change list
is no longer the "identical" signal: `FileComparison` distinguishes byte
identity from an invisible difference and from a refused listing, so an
over-cap comparison cannot route through the identical branch and exit 0.
…test

Fork-authored amendment on top of acbe88c (cherry-picked from upstream
rtk-ai#3268, Ilia Alshanetsky). Kept separate so the contributor's commit stays
intact and attributable.

The fork's gate runs clippy 1.97 with -D warnings; `start1 >= cursor + 1`
in the test-only `replay_classic` helper trips `int_plus_one`. `start1 >
cursor` is the same predicate on usize. Not sent upstream: whether their
CI pins a clippy that flags it is their call.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kylehgc
kylehgc merged commit 534cd4d into develop Sep 1, 2026
3 checks passed
@kylehgc
kylehgc deleted the adopt/3268-refresh branch September 1, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refresh adoption of upstream #3268: rtk diff identity check + alignment (iliaal)

2 participants