fix: sort provider version lists newest first

Preserve Minecraft release and snapshot chronology, compare loader versions numerically with provider-specific prerelease/build handling, and order Modrinth and CurseForge versions by publication date, including cached lists.

Add regression coverage and live API ordering checks.

Fixes #45
This commit is contained in:
objz committed 2026-10-06 09:15:22 +02:00
1 parent 874c38d7f8
commit 25a4b90f1f
23 files changed
+664 -95

No files matched your search

+10 -3
View File
@@ -466,9 +466,10 @@ pub struct ProviderRegistry {
pub(crate) fn newest_version(versions: &[VersionInfo]) -> Option<&VersionInfo> {
let first = versions.first()?;
Some(versions.iter().fold(first, |newest, version| {
match (published_at(version), published_at(newest)) {
(Some(candidate), Some(current)) if candidate > current => version,
_ => newest,
if published_at(version) > published_at(newest) {
version
} else {
newest
}
}))
}
@@ -487,6 +488,12 @@ fn published_at(version: &VersionInfo) -> Option<chrono::DateTime<chrono::FixedO
chrono::DateTime::parse_from_rfc3339(&version.date_published).ok()
}
/// Keep provider order for equal or missing dates. Mod version names are
/// arbitrary labels, not necessarily comparable version numbers.
pub(crate) fn sort_versions_newest_first(versions: &mut [VersionInfo]) {
versions.sort_by_cached_key(|version| std::cmp::Reverse(published_at(version)));
}
pub(crate) fn has_newer_compatible_version(
versions: &[VersionInfo],
installed_version_id: &str,