Files
rmcl/src/net/quilt.rs
T
objz 5f43128a80 added: tests for patches helpers, forge installer detection, url_encode, profile fetchers
Closes the seven remaining tractable coverage gaps the final review
flagged. All tests-only or tiny *_from variants matching the existing
pattern. 18 new tests.

- src/instance/launch/patches.rs: seven inline tests for the lwjgl3ify
  patch helpers that were entirely untested before. strip_replaced_libs
  has happy + no-op cases. parse_add_opens covers the basic Add-Opens
  extraction, the MANIFEST.MF continuation-line case (the tricky one:
  jar manifests wrap lines with a trailing space + leading-space marker
  that gets stripped on join), missing manifest, and missing file.
  add_lwjgl3 verifies that only jars that actually exist in lib_dir
  end up on the classpath.

- src/net/forge.rs: three inline tests for has_legacy_install_profile.
  Builds synthetic forge installer zips in a tempdir with and without
  the versionInfo key in install_profile.json; covers the missing-jar
  branch with a path that doesn't exist.

- src/net/modrinth.rs: five-case rstest for url_encode covering the
  unreserved set, space, RFC 3986 reserved characters, multi-byte UTF-8
  (the encoder operates per-byte so emoji exercises the multi-byte
  path), and empty input.

- src/net/fabric.rs / src/net/quilt.rs: added fetch_*_profile_from and
  fetch_*_profile_with_raw_from variants mirroring the existing pattern.
  Existing fetch_*_profile and *_with_raw delegate to them with the
  upstream constants.

- tests/net_loaders.rs: two new wiremock tests (fabric_fetch_profile
  parses libraries, quilt_fetch_profile parses libraries) using the
  new _from variants.

- src/tui/widgets/popups/import_modpack/render.rs: extra snapshot for
  the Confirm step when loader_version is None (vanilla pack or old
  mmc pack). The previous Confirm snapshot covered Some(_) only.

Production touches stay minimal: the four new pub fn delegators in
fabric.rs and quilt.rs, all behaviour-preserving.
2026-05-27 18:19:26 +02:00

198 lines
5.7 KiB
Rust

// quilt mod loader: fabric fork with a nearly identical metadata API.
// if you're getting deja vu reading this after fabric.rs, that's why.
use std::path::Path;
use serde::{Deserialize, Serialize};
use crate::instance::loader::GameVersion;
use crate::net::{HttpClient, NetError, download_file};
use crate::tui::progress::set_sub_action;
const QUILT_META_BASE: &str = "https://meta.quiltmc.org/v3";
#[derive(Debug, Clone, Deserialize)]
pub struct QuiltLoaderVersion {
pub loader: QuiltVersion,
}
#[derive(Debug, Clone, Deserialize)]
pub struct QuiltVersion {
pub version: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct QuiltGameVersion {
pub version: String,
pub stable: bool,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct QuiltProfile {
pub id: String,
pub main_class: String,
pub libraries: Vec<QuiltLibrary>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct QuiltLibrary {
pub name: String,
pub url: String,
}
pub async fn fetch_quilt_game_versions(client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
fetch_quilt_game_versions_from(client, QUILT_META_BASE).await
}
// same as fetch_quilt_game_versions but lets tests point at a wiremock
// server. quilt mirrors the fabric API shape.
pub async fn fetch_quilt_game_versions_from(
client: &HttpClient,
meta_base: &str,
) -> Result<Vec<GameVersion>, NetError> {
let url = format!("{}/versions/game", meta_base);
let versions: Vec<QuiltGameVersion> = client.get_json(&url).await?;
Ok(versions
.into_iter()
.map(|version| GameVersion {
id: version.version,
stable: version.stable,
})
.collect())
}
pub async fn fetch_quilt_versions(
client: &HttpClient,
game_version: &str,
) -> Result<Vec<QuiltLoaderVersion>, NetError> {
fetch_quilt_versions_from(client, QUILT_META_BASE, game_version).await
}
pub async fn fetch_quilt_versions_from(
client: &HttpClient,
meta_base: &str,
game_version: &str,
) -> Result<Vec<QuiltLoaderVersion>, NetError> {
let url = format!("{}/versions/loader/{}", meta_base, game_version);
client.get_json(&url).await
}
pub async fn fetch_quilt_profile(
client: &HttpClient,
game_version: &str,
loader_version: &str,
) -> Result<QuiltProfile, NetError> {
fetch_quilt_profile_from(client, QUILT_META_BASE, game_version, loader_version).await
}
pub async fn fetch_quilt_profile_from(
client: &HttpClient,
meta_base: &str,
game_version: &str,
loader_version: &str,
) -> Result<QuiltProfile, NetError> {
let url = format!(
"{}/versions/loader/{}/{}/profile/json",
meta_base, game_version, loader_version
);
client.get_json(&url).await
}
// like fetch_quilt_profile but also returns the raw response bytes so the
// caller can write the upstream JSON byte-for-byte to disk. used by the
// install path so we don't lose data (e.g. any future arguments field) by
// re-serializing through our narrow QuiltProfile struct.
pub async fn fetch_quilt_profile_with_raw(
client: &HttpClient,
game_version: &str,
loader_version: &str,
) -> Result<(QuiltProfile, Vec<u8>), NetError> {
fetch_quilt_profile_with_raw_from(client, QUILT_META_BASE, game_version, loader_version).await
}
pub async fn fetch_quilt_profile_with_raw_from(
client: &HttpClient,
meta_base: &str,
game_version: &str,
loader_version: &str,
) -> Result<(QuiltProfile, Vec<u8>), NetError> {
let url = format!(
"{}/versions/loader/{}/{}/profile/json",
meta_base, game_version, loader_version
);
client.get_json_with_raw(&url, "Quilt profile").await
}
pub async fn download_quilt_libraries(
client: &HttpClient,
profile: &QuiltProfile,
meta_dir: &Path,
) -> Result<(), NetError> {
let libraries_dir = meta_dir.join("libraries");
for lib in &profile.libraries {
let maven_path = match crate::net::maven_coord_to_path(&lib.name) {
Some(p) => p,
None => {
return Err(NetError::Parse(format!(
"Invalid Maven coordinate: {}",
lib.name
)));
}
};
let dest = libraries_dir.join(&maven_path);
if dest.exists() {
tracing::debug!("Quilt library already exists: {}", lib.name);
continue;
}
let base_url = lib.url.trim_end_matches('/');
let download_url = format!("{}/{}", base_url, maven_path);
set_sub_action(&lib.name);
tracing::info!("Downloading Quilt library: {}", lib.name);
download_file(client, &download_url, &dest, |_, _| {}).await?;
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use crate::net::HttpClient;
#[tokio::test]
#[ignore = "hits live Quilt API"]
async fn test_fetch_versions() {
let client = HttpClient::new();
match fetch_quilt_versions(&client, "1.20.1").await {
Ok(versions) => {
assert!(
!versions.is_empty(),
"Should have Quilt versions for 1.20.1"
);
}
Err(e) => panic!("fetch_quilt_versions failed: {}", e),
}
}
#[tokio::test]
#[ignore = "hits live Quilt API"]
async fn test_fetch_game_versions() {
let client = HttpClient::new();
match fetch_quilt_game_versions(&client).await {
Ok(versions) => {
assert!(!versions.is_empty(), "Should have Quilt game versions");
assert!(versions.iter().any(|version| version.id == "1.20.1"));
}
Err(e) => panic!("fetch_quilt_game_versions failed: {}", e),
}
}
}