Launcher: test a Java mod's install, dependencies, id clash and removal offline

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-22 18:10:20 +02:00
parent 3530560581
commit a3f81f3a30
+82
View File
@@ -250,3 +250,85 @@ fn shader_packs_go_to_their_folder_and_modpacks_download_checked() {
assert!(!downloads.join("atm-2.zip").exists());
fs::remove_dir_all(&home).unwrap();
}
/// A NeoForge jar with `files` beside its `neoforge.mods.toml` for mod `id`.
fn mod_jar(id: &str, files: &[(&str, &str)]) -> Vec<u8> {
use std::io::Write;
let mut zip = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
let toml = format!(
"modLoader = \"javafml\"\nlicense = \"MIT\"\n[[mods]]\nmodId = \"{id}\"\nversion = \"1.0\"\ndisplayName = \"{id}\"\n"
);
for (name, text) in [("META-INF/neoforge.mods.toml", toml.as_str())]
.into_iter()
.chain(files.iter().copied())
{
zip.start_file(name, zip::write::SimpleFileOptions::default())
.unwrap();
zip.write_all(text.as_bytes()).unwrap();
}
zip.finish().unwrap().into_inner()
}
#[test]
fn java_mods_are_ported_turned_on_refused_on_clashes_and_removed() {
let home = home("java");
let mut fake = Fake::default();
for id in ["ruby", "lib", "gem"] {
let mut p = project(id, Kind::Mod);
p.loaders = vec!["neoforge".into()];
fake.add(p);
}
let block = r#"{"variants": {"": {"model": "ruby:block/ruby_block"}}}"#;
let recipe = r#"{"type": "minecraft:crafting_shapeless", "ingredients": ["minecraft:red_dye"], "result": {"id": "ruby:ruby_block"}}"#;
let ruby = mod_jar(
"ruby",
&[
("assets/ruby/blockstates/ruby_block.json", block),
("data/ruby/recipe/ruby_block.json", recipe),
],
);
// A library: nothing to port.
let lib = mod_jar("lib", &[]);
// Another project with the same mod id.
let gem = mod_jar("ruby", &[("assets/ruby/blockstates/gem.json", block)]);
fake.release("ruby", "1", &["lib"], &ruby, false);
fake.release("lib", "1", &[], &lib, false);
fake.release("gem", "1", &[], &gem, false);
let done = install(&fake, &fake.project("ruby").unwrap(), false, &home, NONE).unwrap();
assert_eq!(done.len(), 1, "the library isn't installed");
let entry = &done[0];
assert_eq!(entry.file, "horizon-mods/ruby");
assert_eq!(entry.verdict.as_deref(), Some("Works"));
assert!(
entry
.skipped
.iter()
.any(|s| s.starts_with("needs Pack lib")),
"{:?}",
entry.skipped
);
assert!(entry.namespaces.contains(&"ruby".to_owned()));
assert!(home.join("horizon-mods/ruby/horizon-mod.toml").is_file());
assert_eq!(
fs::read_to_string(home.join("horizon-mods.txt")).unwrap(),
"mod.ruby:true\n"
);
// The jar isn't kept, its check is.
assert!(!home
.join("mod-browser/checks-1/.downloads/ruby-1.zip")
.exists());
let clash = install(&fake, &fake.project("gem").unwrap(), false, &home, NONE).unwrap_err();
assert!(clash.contains("shares its id or namespace"), "{clash}");
assert!(!home.join("horizon-mods/gem").exists());
let removed = remove(&home, "ruby").unwrap();
assert_eq!(removed.kind, Kind::Mod);
assert!(!home.join("horizon-mods/ruby").exists());
assert_eq!(
fs::read_to_string(home.join("horizon-mods.txt")).unwrap(),
""
);
fs::remove_dir_all(&home).unwrap();
}