fix: make compare_lines a valid total order (#105)#106
Merged
Conversation
The previous comparator could return Ordering::Less for both compare_lines(a, b) and compare_lines(b, a) when two lines shared a prefix ending just before "**". That violated antisymmetry, so Vec::sort_by produced different orderings on different platforms, breaking "CODEOWNERS out of date" validation. Compare path components left-to-right with "**" treated as a sentinel that sorts before any non-"**" component, falling back to full-line lexical compare as a deterministic tiebreaker. The shared comparator is reused by codeowners_file_parser, so both generation and parse agree.
- Rename the antisymmetry sweep so the name matches what it asserts. - Add a transitivity sweep over the same special-character set; this is the property that was actually missing from coverage of the Ord contract. - Add a length-asymmetry case (shorter path vs longer extension) and an equal-path tiebreaker case, exercising the (None, Some) / (Some, None) and full-line fallback arms.
perryqh
reviewed
May 18, 2026
| assert_eq!(compare_lines(&enabled, &other), compare_lines(&disabled, &other)); | ||
| assert_eq!(compare_lines(&other, &enabled), compare_lines(&other, &disabled)); | ||
| } | ||
|
|
perryqh
approved these changes
May 18, 2026
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
codeowners-rsgenerates nondeterministicCODEOWNERSordering due to invalid comparator incompare_lines#105:compare_linesinsrc/ownership/file_generator.rswas not antisymmetric, soVec::sort_byproduced different CODEOWNERS orderings on macOS vs Linux for the same input.**(e.g./foo/**/*bar*and/foo/**/baz/**/*), the old comparator returnedLessin both directions, leaving sort output platform/build dependent.**is treated as a sentinel that sorts before any non-**component, with full-line lexical compare as a deterministic tiebreaker. The shared comparator is reused bycodeowners_file_parser, so generated and parsed orderings agree.Test plan
cargo test— full suite passes (existing sort tests unchanged)cargo clippy --all-targets --all-features— cleancargo fmt --all -- --check— clean#prefix on disabled entries does not perturb path ordering