fix(diff): check modified count in identical-files guard#792
Open
gghez wants to merge 1 commit intortk-ai:developfrom
Open
fix(diff): check modified count in identical-files guard#792gghez wants to merge 1 commit intortk-ai:developfrom
gghez wants to merge 1 commit intortk-ai:developfrom
Conversation
The "Files are identical" check only tested added and removed counters, ignoring modified lines. When two lines shared enough characters to be classified as a modification (similarity > 0.5), they incremented modified but not added/removed, so the guard passed and the diff reported no changes. Also replace the Jaccard set-based similarity function with a positional prefix+suffix metric that better reflects actual line differences — the old approach used unique character sets, which over-estimated similarity for lines sharing common characters in different positions. Fixes rtk-ai#781 Signed-off-by: gghez <gghez@users.noreply.github.com>
Collaborator
📊 Automated PR Analysis
SummaryFixes a bug where Review Checklist
Linked issues: #781 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rtk diffincorrectly reports "Files are identical" when lines differ by only a few characters. Two root causes:The identical-files guard at line 24 only checked
added == 0 && removed == 0, ignoring themodifiedcounter. Lines classified as modifications (similarity > 0.5) incrementedmodifiedbut notadded/removed, so the guard passed and the diff silently swallowed actual differences.The
similarity()function used Jaccard similarity on unique character sets, which over-estimated similarity for lines sharing common characters regardless of position. Replaced it with a positional prefix+suffix ratio that better reflects actual line differences.Changes
&& diff.modified == 0to the identical-files guard inrun()similarity()implementation: Jaccard set-based -> positional prefix+suffix metrictest_similarity_partial_overlapfor the new metricTest plan
cargo test --all)diffreports "Files are identical" when lines differ by only a few characters #781cargo checkcompiles without warningsFixes #781