-
-
Notifications
You must be signed in to change notification settings - Fork 408
Update to imara-diff 0.2 in diff slider test
#2288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
gix-diff/tests/diff/blob/slider.rs
Outdated
| use gix_diff::blob::intern::TokenSource; | ||
| use gix_diff::blob::unified_diff::ContextSize; | ||
| use gix_diff::blob::{Algorithm, UnifiedDiff}; | ||
| use gix_diff::blob::v2::{Algorithm, BasicLineDiffPrinter, Diff, InternedInput, UnifiedDiffConfig}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's interesting that v2 is available at all as it shouldn't be available by default.
Let me fix that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, seems like this code should not compile, it's fine on main.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that, I didn't realise that this is a test in gix-diff-tests, which enables the feature. It was a long day yesterday 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I also could have provided that context. :-)
|
I’ve re-added the v1 slider test that I had updated in this PR’s first commit. Now, there’s both the |
Byron
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great to have! I think we should also think about having a minimal default set of slider tests that we keep, at some point, so we have some CI protections for this. But it's a note for the future, when it settles a bit more.
Besides that, I asked Copilot to take a look, but would also love it if you could try it once more as I didn't have a slider setup to actually run the code.
But if you give the green light, I will happily merge this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR updates the diff slider test to support imara-diff 0.2 by adding a new v2 API test alongside the existing v1 test. The changes refactor common logic into helper functions to reduce duplication and support both API versions.
Key changes:
- Renames existing
baseline()test tobaseline_v1()and adds newbaseline_v2()test for the v2 API - Extracts common parsing logic into
parse_dir_entry()helper function - Moves diff assertion logic to
assert_diffs()helper function - Adds
fold_to_unidiff()method to theBaselinetype for cleaner code reuse
| let old_data = std::fs::read(asset_dir.join(format!("{old_blob_id}.blob"))).unwrap(); | ||
| let new_data = std::fs::read(asset_dir.join(format!("{new_blob_id}.blob"))).unwrap(); |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .unwrap() calls violate the project's error handling guidelines. According to the coding guidelines, tests should avoid .unwrap() in favor of .expect() with meaningful context or ?. These file reads should either be propagated with ? or use .expect("meaningful context") to explain why the files are expected to exist.
| continue; | ||
| }; | ||
|
|
||
| let input = InternedInput::new(old_data.to_str().unwrap(), new_data.to_str().unwrap()); |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .unwrap() calls on .to_str() are problematic. The project guidelines prohibit .unwrap() in favor of .expect() with context or proper error handling with ?. Additionally, this assumes the blob data is valid UTF-8, which may not always be true for binary files or files with different encodings. This could cause the test to panic instead of handling non-UTF-8 data gracefully.
| let algorithm = match algorithm { | ||
| gix_diff::blob::Algorithm::Myers => Algorithm::Myers, | ||
| gix_diff::blob::Algorithm::Histogram => Algorithm::Histogram, | ||
| gix_diff::blob::Algorithm::MyersMinimal => Algorithm::MyersMinimal, | ||
| }; |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The algorithm mapping is duplicated between parse_dir_entry (lines 138-142) and this section. Since parse_dir_entry already returns the Algorithm enum from the v1 API, this remapping to v2 Algorithm could be extracted into a helper function to avoid duplication and make the relationship between v1 and v2 algorithms clearer.
| let mut diff = Diff::compute(algorithm, &input); | ||
| diff.postprocess_lines(&input); |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name diff is shadowed after mutation (line 98 creates it, line 99 mutates it). Consider renaming to clarify the mutation, or combine the operations if the intermediate state isn't needed.
| } | ||
|
|
||
| impl Baseline<'_> { | ||
| /// Fold all [`DiffHunk`]s we produce into a unified_diff string |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc comment uses backticks around DiffHunk and refers to "we produce" but doesn't fully explain what this method does or when it should be used. Consider clarifying that this method converts the baseline hunks into a unified diff format string for comparison purposes.
| /// Fold all [`DiffHunk`]s we produce into a unified_diff string | |
| /// Converts all baseline [`DiffHunk`]s into a single unified diff format string. | |
| /// | |
| /// This method is typically used to produce a unified diff representation of the baseline hunks, | |
| /// suitable for comparison with other diff outputs in tests or analysis. |
| unreachable!("BUG: Need file named '<name>.<algorithm>'") | ||
| }; | ||
| let algorithm = match algorithm { | ||
| "myers" => Algorithm::Myers, | ||
| "histogram" => Algorithm::Histogram, | ||
| other => unreachable!("'{other}' is not a supported algorithm"), | ||
| }; | ||
|
|
||
| let parts: Vec<_> = name.split('-').collect(); | ||
| let [old_blob_id, new_blob_id] = parts[..] else { | ||
| unreachable!("BUG: name part of filename must be <old_blob_id>-<new_blob_id>"); |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message format is inconsistent. Line 136 uses "BUG: Need file named", line 141 uses single quotes around the variable without "BUG:", and line 146 uses "BUG: name part of filename must be". Consider using a consistent format for all unreachable error messages, such as starting all with "BUG:" prefix.
Yep, having a set of default tests definitely is on my todo list as well.
I just re-ran the tests with your updates on my machine and did not observe any differences to the previous state. Just for context: in case you were wondering, I intentionally did not de-duplicate the tests right away, in order to facilitate review. |
This is a companion to #2287. It updates the diff slider test to use
imara-diff0.2. In my non-representative sample of ~3000 diffs fromgitoxide, it matches the git baseline in ~95 % of cases.