fixed: review findings - robustness, dead code, missing tests

several smaller fixes from the code review:
 - add os_version to RuleContext + OsCondition for mojang rules that
   constrain natives selection by host version (rare, but in the spec).
 - factor mojang_os_name/arch/version into a shared launch_profile::system
   module instead of duplicating between net/mojang.rs and launch/mod.rs.
 - get_json and get_bytes now retry transient failures (5xx, connect,
   body decode) via a shared get_with_retry envelope; previously only
   download_file had retry logic.
 - migrate_legacy_meta_if_needed falls back to the stale cached profile
   with a warn log on network failure instead of erroring out (offline
   launches now work).
 - tightened legacy-loader detection by requiring the unique-to-rmcl
   gameArguments field; clearer error when loader_version is absent.
 - forge legacy versionInfo write uses compact serialization (no
   pretty-print key reorder).
 - deleted dead fetch_version_meta and save_profile_json.
 - documented quick-play templates omission in templates::lookup.
 - added end-to-end test that loads a vanilla profile from disk, loads a
   loader profile with inheritsFrom, resolves, renders, and snapshots.
This commit is contained in:
objz committed 2026-05-25 18:24:06 +02:00
1 parent 19887643bc
commit 412e6ff91a
12 files changed
+395 -74

No files matched your search

+58 -24
View File
@@ -60,9 +60,16 @@ async fn migrate_legacy_meta_if_needed(
);
let client = crate::net::HttpClient::new();
let manifest = crate::net::mojang::fetch_version_manifest(&client)
.await
.map_err(|e| LaunchError::Parse(format!("Failed to fetch version manifest: {e}")))?;
let manifest = match crate::net::mojang::fetch_version_manifest(&client).await {
Ok(m) => m,
Err(e) => {
tracing::warn!(
"Could not reach Mojang manifest ({e}); proceeding with the cached legacy profile. \
Modern features like Forge's --add-opens flags may be missing until the next online launch."
);
return Ok(None);
}
};
let entry = manifest
.versions
@@ -74,9 +81,15 @@ async fn migrate_legacy_meta_if_needed(
))
})?;
let (_meta, raw) = crate::net::mojang::fetch_version_meta_with_raw(&client, entry)
.await
.map_err(|e| LaunchError::Parse(format!("Failed to re-fetch version meta: {e}")))?;
let (_meta, raw) = match crate::net::mojang::fetch_version_meta_with_raw(&client, entry).await {
Ok(ok) => ok,
Err(e) => {
tracing::warn!(
"Could not refetch version metadata from Mojang ({e}); proceeding with the cached legacy profile."
);
return Ok(None);
}
};
tokio::fs::write(meta_path, &raw).await?;
@@ -123,21 +136,34 @@ async fn migrate_legacy_loader_profile_if_needed(
return Ok(None);
}
// tightened predicate per the spec: only treat a profile as "legacy
// stripped" when our old `gameArguments` field is present. that field
// is unique to rmcl <= 0.3.0's custom shape; no upstream profile
// emits it. without this gate, an upstream profile that happens to
// omit inheritsFrom/arguments/minecraftArguments would be mistakenly
// re-extracted from the installer JSON.
let is_legacy = profile.inherits_from.is_none()
&& profile.arguments.is_none()
&& profile.minecraft_arguments.is_none();
&& profile.minecraft_arguments.is_none()
&& profile.game_arguments.is_some();
if !is_legacy {
return Ok(None);
}
let loader_version = config.loader_version.as_deref().unwrap_or("unknown");
let Some(loader_version) = config.loader_version.as_deref() else {
return Err(LaunchError::Parse(format!(
"Loader profile at {} is in an outdated format and the instance config has no \
loader_version recorded. Reinstall {} for this instance.",
profile_path.display(),
config.loader
)));
};
let Some(version_dir) =
installer_version_dir_name(config.loader, &config.game_version, loader_version)
else {
// Fabric/Quilt fall through to the same path but don't have an
// installer-written JSON to fall back on. Phase 6 will widen
// those structs to capture the full upstream JSON at install
// time; until then, the user reinstalls.
// unreachable today: only Vanilla/Fabric/Quilt return None, and
// Vanilla doesn't pass this code path (no loader profile to
// migrate) while Fabric/Quilt are filtered above.
return Err(LaunchError::Parse(format!(
"Loader profile at {} is in an outdated format. Reinstall {} for this instance.",
profile_path.display(),
@@ -201,17 +227,11 @@ pub async fn launch(
};
let current_features = crate::launch_profile::rules::FeatureSet::default();
let host_os_version = crate::launch_profile::system::mojang_os_version();
let rule_ctx = crate::launch_profile::rules::RuleContext {
os_name: match std::env::consts::OS {
"macos" => "osx",
other => other,
},
arch: match std::env::consts::ARCH {
"x86" => "x86",
"x86_64" => "x86_64",
"aarch64" => "arm64",
other => other,
},
os_name: crate::launch_profile::system::mojang_os_name(),
os_version: &host_os_version,
arch: crate::launch_profile::system::mojang_arch_name(),
features: &current_features,
};
@@ -617,6 +637,7 @@ mod tests {
let features = FeatureSet::default();
let rule_ctx = RuleContext {
os_name: "linux",
os_version: "6.0",
arch: "x86_64",
features: &features,
};
@@ -642,11 +663,12 @@ mod tests {
downloads: None,
release_time: None,
time: None,
game_arguments: None,
type_: None,
};
let (jvm, game_args) =
build_game_args(&profile, &rule_ctx, &template_ctx).unwrap();
let (jvm, game_args) = build_game_args(&profile, &rule_ctx, &template_ctx).unwrap();
assert_eq!(jvm, vec!["-Djava.library.path=/m/natives"]);
assert_eq!(game_args, vec!["--username", "Player"]);
}
@@ -688,6 +710,8 @@ mod tests {
downloads: None,
release_time: None,
time: None,
game_arguments: None,
type_: None,
};
assert!(stripped.arguments.is_none() && stripped.minecraft_arguments.is_none());
@@ -709,6 +733,8 @@ mod tests {
downloads: None,
release_time: None,
time: None,
game_arguments: None,
type_: None,
};
assert!(modern.arguments.is_some());
@@ -730,6 +756,8 @@ mod tests {
downloads: None,
release_time: None,
time: None,
game_arguments: None,
type_: None,
};
assert!(legacy.minecraft_arguments.is_some());
@@ -774,6 +802,8 @@ mod tests {
downloads: None,
release_time: None,
time: None,
game_arguments: None,
type_: None,
};
let is_legacy = legacy.inherits_from.is_none()
@@ -798,6 +828,8 @@ mod tests {
downloads: None,
release_time: None,
time: None,
game_arguments: None,
type_: None,
};
let is_legacy = modern.inherits_from.is_none()
@@ -835,6 +867,8 @@ mod tests {
downloads: None,
release_time: None,
time: None,
game_arguments: None,
type_: None,
};
+9 -15
View File
@@ -46,20 +46,6 @@ pub trait ModLoaderInstaller: Send + Sync {
) -> Result<(), NetError>;
}
pub(crate) fn save_profile_json(
meta_dir: &Path,
filename: &str,
profile: &impl serde::Serialize,
) -> Result<(), NetError> {
let profiles_dir = meta_dir.join("loader-profiles");
std::fs::create_dir_all(&profiles_dir)?;
let profile_path = profiles_dir.join(filename);
let json = serde_json::to_string_pretty(profile)
.map_err(|e| NetError::Parse(format!("Failed to serialize profile {filename}: {e}")))?;
std::fs::write(&profile_path, &json)?;
Ok(())
}
// used by forge/neoforge. their java installer drops a version json into
// .minecraft/versions/. we copy that file byte-for-byte to our loader
// profile cache so launch-time code sees the full upstream JSON -
@@ -214,7 +200,15 @@ mod tests {
]
});
save_profile_json(&meta_dir, "forge-1.7.10-10.13.4.1614.json", &version_info).unwrap();
// mirror the install path: write versionInfo as compact JSON.
let profiles_dir = meta_dir.join("loader-profiles");
std::fs::create_dir_all(&profiles_dir).unwrap();
let serialized = serde_json::to_vec(&version_info).unwrap();
std::fs::write(
profiles_dir.join("forge-1.7.10-10.13.4.1614.json"),
&serialized,
)
.unwrap();
let saved_bytes = std::fs::read(
meta_dir