Skip to content

fix(cli): make search result ordering a strict weak ordering - #2126

Open
chennaji9 wants to merge 1 commit into
OpenAtom-Linyaps:masterfrom
chennaji9:fix/search-sort-weak-ordering
Open

chennaji9 wants to merge 1 commit into
OpenAtom-Linyaps:masterfrom
chennaji9:fix/search-sort-weak-ordering

Conversation

@chennaji9

Copy link
Copy Markdown

What does this PR do?

The search-result sort comparator is duplicated in CLIPrinter::printSearchResult and JSONPrinter::printSearchResult, and it violates strict weak ordering:

auto lhsVer = package::Version::parse(lhs.version.c_str());
if (!lhsVer) {
    return false;
}
auto rhsVer = package::Version::parse(rhs.version.c_str());
if (!rhsVer) {
    return false;
}
return *lhsVer > *rhsVer;

For records with equal id/channel/module: if either version fails to parse, the comparator returns false both ways — but two parsable versions still order against each other. Equivalence becomes non-transitive (e.g. 2.0.0, "", 1.0.0), violating std::sort's precondition: undefined behavior (out-of-bounds reads / crashes depending on the sort path).

Note: Version::parse falls through to FallbackVersion, which accepts almost any non-empty dotted string — the unparsable set is effectively {""} and dot-only strings (".", ".."), which repo metadata can still carry.

Order parsable versions first, descending, exactly as before; sort unparsable ones last, deterministically by raw version string. Apply the same fix to both printers so text and JSON output stay consistent.

Validation

  • New unit test CLIPrinter.PrintSearchResultSortsInvalidVersionsLast feeds mixed parsable (3.0.0, 2.0.0, 1.0.0) and unparsable ("...", "") versions with identical id/channel/module through BOTH printers and asserts the emitted order (3.0.0 < 2.0.0 < 1.0.0 < invalid group) via output offsets.
  • All 20 CLIPrinter tests pass with the change (ctest -R 'CLIPrinter|JsonPrinter' → 20/20 Passed, including the pre-existing PrintSearchResultSorts and PrintSearchResultEmpty).
  • ll-tests builds cleanly.

🤖 Generated with Claude Code

@deepin-ci-robot

Copy link
Copy Markdown
Collaborator

Hi @chennaji9. Thanks for your PR.

I'm waiting for a OpenAtom-Linyaps member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
libs/linglong/src/linglong/cli/cli_printer.cpp 75.00% 0 Missing and 1 partial ⚠️
libs/linglong/src/linglong/cli/json_printer.cpp 75.00% 0 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
libs/linglong/src/linglong/cli/cli_printer.cpp 45.92% <75.00%> (+1.89%) ⬆️
libs/linglong/src/linglong/cli/json_printer.cpp 54.65% <75.00%> (+7.03%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The duplicated sort comparators in CLIPrinter::printSearchResult and
JSONPrinter::printSearchResult returned false whenever either version
failed to parse, making record equivalence non-transitive when mixed
with parsable versions and violating std::sort's precondition
(undefined behavior).

Order parsable versions first descending as before and unparsable ones
last by raw string, in both printers; add a unit test covering mixed
parsable/unparsable versions through both printers.

Signed-off-by: 陈那几 <2078634206@qq.com>
@chennaji9
chennaji9 force-pushed the fix/search-sort-weak-ordering branch from e3940e3 to cc2e1b8 Compare October 13, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants