fix: launch with the selected JVM and own subprocess lifetimes
This commit is contained in:
1 parent
eb436c2ab8
commit
dc351df546
31 files changed
+3061
-820
No files matched your search
+527
-26
@@ -8,7 +8,7 @@ use serde_json::json;
|
||||
use tempfile::TempDir;
|
||||
|
||||
use rmcl::instance::launch::{
|
||||
LaunchAuth, LaunchError, build_launch_invocation, supports_quick_play,
|
||||
LaunchAuth, LaunchError, build_launch_invocation_with_settings, supports_quick_play,
|
||||
};
|
||||
use rmcl::instance::models::{InstanceConfig, ModLoader};
|
||||
|
||||
@@ -16,6 +16,24 @@ const PLAYER: &str = "TestPlayer";
|
||||
const PLAYER_UUID: &str = "00000000-0000-0000-0000-000000000001";
|
||||
const PLAYER_TOKEN: &str = "secret-access-token";
|
||||
|
||||
async fn build_launch_invocation(
|
||||
config: &InstanceConfig,
|
||||
instances_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
auth: &LaunchAuth<'_>,
|
||||
quick_play_world: Option<&str>,
|
||||
) -> Result<rmcl::instance::launch::LaunchInvocation, LaunchError> {
|
||||
build_launch_invocation_with_settings(
|
||||
config,
|
||||
instances_dir,
|
||||
meta_dir,
|
||||
auth,
|
||||
quick_play_world,
|
||||
&rmcl::config::Config::default(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
fn test_auth() -> LaunchAuth<'static> {
|
||||
LaunchAuth {
|
||||
username: PLAYER,
|
||||
@@ -42,9 +60,7 @@ fn make_config_with(
|
||||
loader_version: loader_version.map(str::to_owned),
|
||||
created: Utc::now(),
|
||||
last_played: None,
|
||||
// pinned to a deterministic value so detect_java_path is never
|
||||
// invoked and tests don't depend on the host's java install.
|
||||
java_path: Some("/usr/bin/java-test".into()),
|
||||
java_path: Some(default_fake_java()),
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
@@ -62,22 +78,117 @@ fn make_config_with(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn fake_java(tmp: &TempDir, major: u32) -> String {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
fake_java_platform(tmp, major, &host_java_platform())
|
||||
}
|
||||
|
||||
let path = tmp.path().join(format!("java-{major}"));
|
||||
fn host_java_platform() -> rmcl::launch_profile::system::JavaPlatform {
|
||||
rmcl::launch_profile::system::JavaPlatform::from_java_properties(
|
||||
match std::env::consts::OS {
|
||||
"windows" => "Windows 10",
|
||||
"macos" => "Mac OS X",
|
||||
_ => "Linux",
|
||||
},
|
||||
std::env::consts::ARCH,
|
||||
if cfg!(target_pointer_width = "64") {
|
||||
"64"
|
||||
} else {
|
||||
"32"
|
||||
},
|
||||
"10.0",
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn default_fake_java() -> String {
|
||||
static JAVA: std::sync::OnceLock<(TempDir, String)> = std::sync::OnceLock::new();
|
||||
JAVA.get_or_init(|| {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let java = fake_java(&temp, 25);
|
||||
(temp, java)
|
||||
})
|
||||
.1
|
||||
.clone()
|
||||
}
|
||||
|
||||
fn fake_java_platform(
|
||||
tmp: &TempDir,
|
||||
major: u32,
|
||||
platform: &rmcl::launch_profile::system::JavaPlatform,
|
||||
) -> String {
|
||||
let os_name = match platform.os_name {
|
||||
"windows" => "Windows 10",
|
||||
"osx" => "Mac OS X",
|
||||
_ => "Linux",
|
||||
};
|
||||
let text = format!(
|
||||
"java.version = {major}.0.1\nos.name = {os_name}\nos.arch = {}\nsun.arch.data.model = {}\nos.version = {}",
|
||||
platform.arch, platform.bitness, platform.os_version
|
||||
);
|
||||
let path = tmp.path().join(format!(
|
||||
"java probe-{major}-{}.{}",
|
||||
platform.arch,
|
||||
if cfg!(windows) { "cmd" } else { "sh" }
|
||||
));
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
std::fs::write(
|
||||
&path,
|
||||
format!(
|
||||
"#!/bin/sh\nprintf '%s\\n' {} >&2\n",
|
||||
text.lines()
|
||||
.map(|line| format!("'{line}'"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();
|
||||
}
|
||||
#[cfg(windows)]
|
||||
std::fs::write(
|
||||
&path,
|
||||
format!("#!/bin/sh\necho 'openjdk version \"{major}.0.1\"' >&2\n"),
|
||||
format!(
|
||||
"@echo off\r\n{}\r\n",
|
||||
text.lines()
|
||||
.map(|line| format!("echo {line} 1>&2"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\r\n")
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let mut permissions = std::fs::metadata(&path).unwrap().permissions();
|
||||
permissions.set_mode(0o755);
|
||||
std::fs::set_permissions(&path, permissions).unwrap();
|
||||
path.to_string_lossy().into_owned()
|
||||
}
|
||||
|
||||
fn cache_fixture_artifacts(meta_dir: &Path, profile: &mut serde_json::Value) {
|
||||
use sha1::Digest;
|
||||
let bytes = b"synthetic jar";
|
||||
if let Some(libraries) = profile["libraries"].as_array_mut() {
|
||||
for library in libraries {
|
||||
let name = library["name"].as_str().unwrap().to_owned();
|
||||
if let Some(artifact) = library["downloads"]
|
||||
.get_mut("artifact")
|
||||
.filter(|value| value.is_object())
|
||||
{
|
||||
let path = artifact["path"]
|
||||
.as_str()
|
||||
.filter(|path| !path.is_empty())
|
||||
.map(str::to_owned)
|
||||
.or_else(|| rmcl::instance::loader::maven::maven_coord_to_path(&name))
|
||||
.unwrap();
|
||||
let dest = rmcl::storage::MetadataPaths::new(meta_dir)
|
||||
.libraries()
|
||||
.join(path);
|
||||
std::fs::create_dir_all(dest.parent().unwrap()).unwrap();
|
||||
std::fs::write(dest, bytes).unwrap();
|
||||
artifact["sha1"] = json!(format!("{:x}", sha1::Sha1::digest(bytes)));
|
||||
artifact["size"] = json!(bytes.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Fixture {
|
||||
_tmp: TempDir,
|
||||
instances_dir: PathBuf,
|
||||
@@ -85,7 +196,7 @@ struct Fixture {
|
||||
}
|
||||
|
||||
impl Fixture {
|
||||
fn new(instance_name: &str, game_version: &str, vanilla_meta: serde_json::Value) -> Self {
|
||||
fn new(instance_name: &str, game_version: &str, mut vanilla_meta: serde_json::Value) -> Self {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let instances_dir = tmp.path().join("instances");
|
||||
let meta_dir = tmp.path().join("meta");
|
||||
@@ -94,6 +205,7 @@ impl Fixture {
|
||||
std::fs::create_dir_all(&instance_minecraft).unwrap();
|
||||
|
||||
std::fs::create_dir_all(meta_dir.join("cache/minecraft/libraries")).unwrap();
|
||||
cache_fixture_artifacts(&meta_dir, &mut vanilla_meta);
|
||||
std::fs::create_dir_all(meta_dir.join("cache/loaders/profiles")).unwrap();
|
||||
let version_dir = meta_dir.join("cache/minecraft/versions").join(game_version);
|
||||
std::fs::create_dir_all(&version_dir).unwrap();
|
||||
@@ -110,7 +222,8 @@ impl Fixture {
|
||||
}
|
||||
}
|
||||
|
||||
fn write_loader_profile(&self, filename: &str, content: serde_json::Value) {
|
||||
fn write_loader_profile(&self, filename: &str, mut content: serde_json::Value) {
|
||||
cache_fixture_artifacts(&self.meta_dir, &mut content);
|
||||
std::fs::write(
|
||||
self.meta_dir.join("cache/loaders/profiles").join(filename),
|
||||
serde_json::to_vec_pretty(&content).unwrap(),
|
||||
@@ -166,7 +279,6 @@ fn modern_vanilla_meta(id: &str) -> serde_json::Value {
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn modern_vanilla_meta_with_java(id: &str, java_major: u32) -> serde_json::Value {
|
||||
let mut meta = modern_vanilla_meta(id);
|
||||
meta["javaVersion"] = json!({
|
||||
@@ -204,15 +316,11 @@ async fn vanilla_modern_builds_complete_invocation() {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(inv.java, "/usr/bin/java-test");
|
||||
assert_eq!(inv.java, config.java_path.as_deref().unwrap());
|
||||
assert_eq!(inv.main_class, "net.minecraft.client.main.Main");
|
||||
assert!(inv.extra_args.is_empty());
|
||||
|
||||
let expected_natives = fx
|
||||
.meta_dir
|
||||
.join("cache/minecraft/versions")
|
||||
.join("1.20.1")
|
||||
.join("natives");
|
||||
let expected_natives = host_java_platform().natives_directory(&fx.meta_dir, "1.20.1");
|
||||
let actual_natives = inv
|
||||
.jvm_args
|
||||
.iter()
|
||||
@@ -283,7 +391,6 @@ async fn quick_play_passes_the_selected_save_folder() {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn launch_fails_when_selected_java_is_older_than_profile_requires() {
|
||||
let fx = Fixture::new(
|
||||
@@ -322,7 +429,8 @@ async fn vanilla_legacy_args_format_substitutes_tokens() {
|
||||
|
||||
assert_eq!(inv.main_class, "net.minecraft.launchwrapper.Launch");
|
||||
|
||||
assert_eq!(inv.jvm_args.len(), 2);
|
||||
assert_eq!(inv.jvm_args.len(), 3);
|
||||
assert!(inv.jvm_args[2].starts_with("-Djava.library.path="));
|
||||
assert!(inv.jvm_args[0].starts_with("-Xms"));
|
||||
assert!(inv.jvm_args[1].starts_with("-Xmx"));
|
||||
|
||||
@@ -333,6 +441,38 @@ async fn vanilla_legacy_args_format_substitutes_tokens() {
|
||||
assert!(joined.contains("--userType msa"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn missing_or_empty_artifact_paths_use_maven_coordinates() {
|
||||
for path in [None, Some("")] {
|
||||
let mut meta = modern_vanilla_meta("1.20.1");
|
||||
let artifact = meta["libraries"][0]["downloads"]["artifact"]
|
||||
.as_object_mut()
|
||||
.unwrap();
|
||||
if let Some(path) = path {
|
||||
artifact.insert("path".to_owned(), json!(path));
|
||||
} else {
|
||||
artifact.remove("path");
|
||||
}
|
||||
let fixture = Fixture::new("artifact", "1.20.1", meta);
|
||||
let invocation = build_launch_invocation(
|
||||
&make_config("artifact", "1.20.1", ModLoader::Vanilla),
|
||||
&fixture.instances_dir,
|
||||
&fixture.meta_dir,
|
||||
&test_auth(),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
invocation.classpath.contains(
|
||||
&rmcl::storage::MetadataPaths::new(&fixture.meta_dir)
|
||||
.libraries()
|
||||
.join("org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.jar")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn forge_modern_includes_add_opens() {
|
||||
let fx = Fixture::new("f1", "1.20.1", modern_vanilla_meta("1.20.1"));
|
||||
@@ -423,9 +563,9 @@ async fn forge_local_lib_dir_preferred_over_meta_dir() {
|
||||
"expected local fmlloader on classpath: {:?}",
|
||||
inv.classpath
|
||||
);
|
||||
let meta_candidate = fx
|
||||
.meta_dir
|
||||
.join("libraries/net/minecraftforge/fmlloader/1.20.1-47.2.0/fmlloader-1.20.1-47.2.0.jar");
|
||||
let meta_candidate = rmcl::storage::MetadataPaths::new(&fx.meta_dir)
|
||||
.libraries()
|
||||
.join("net/minecraftforge/fmlloader/1.20.1-47.2.0/fmlloader-1.20.1-47.2.0.jar");
|
||||
assert!(
|
||||
!inv.classpath.contains(&meta_candidate),
|
||||
"meta-dir candidate should not be on classpath when local exists"
|
||||
@@ -612,7 +752,9 @@ async fn rule_disallow_excludes_library() {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let denied = fx.meta_dir.join("libraries/com/denied/lib/1.0/lib-1.0.jar");
|
||||
let denied = rmcl::storage::MetadataPaths::new(&fx.meta_dir)
|
||||
.libraries()
|
||||
.join("com/denied/lib/1.0/lib-1.0.jar");
|
||||
assert!(
|
||||
!inv.classpath.contains(&denied),
|
||||
"denied library was included: {:?}",
|
||||
@@ -790,3 +932,362 @@ async fn legacy_loader_profile_missing_installer_json_errors() {
|
||||
"expected Parse error about missing installer JSON, got: {err:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn rules_and_natives_directory_follow_the_selected_java_properties() {
|
||||
for (os, arch, bits, normalized) in [
|
||||
("Windows 10", "x86", "32", "x86"),
|
||||
("Windows 10", "amd64", "64", "x86_64"),
|
||||
("Mac OS X", "x86_64", "64", "x86_64"),
|
||||
("Mac OS X", "aarch64", "64", "arm64"),
|
||||
("Linux", "amd64", "64", "x86_64"),
|
||||
] {
|
||||
let platform = rmcl::launch_profile::system::JavaPlatform::from_java_properties(
|
||||
os, arch, bits, "10.0",
|
||||
)
|
||||
.unwrap();
|
||||
let mut meta = modern_vanilla_meta("1.16.5");
|
||||
for cpu in ["x86", "x86_64", "arm64"] {
|
||||
meta["libraries"].as_array_mut().unwrap().push(json!({
|
||||
"name":format!("test:only-{cpu}:1"), "rules":[{"action":"allow", "os":{"arch":cpu}}],
|
||||
}));
|
||||
}
|
||||
meta["arguments"]["jvm"]
|
||||
.as_array_mut()
|
||||
.unwrap()
|
||||
.push(json!({
|
||||
"rules":[{"action":"allow", "os":{"name":"windows", "version":"^10\\."}}],
|
||||
"value":["-Dos.name=Windows 10", "-Dos.version=10.0"],
|
||||
}));
|
||||
let fixture = Fixture::new("java rules", "1.16.5", meta);
|
||||
let mut config = make_config("java rules", "1.16.5", ModLoader::Vanilla);
|
||||
config.java_path = Some(fake_java_platform(&fixture._tmp, 25, &platform));
|
||||
let invocation = build_launch_invocation(
|
||||
&config,
|
||||
&fixture.instances_dir,
|
||||
&fixture.meta_dir,
|
||||
&test_auth(),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let cpu_jars: Vec<_> = invocation
|
||||
.classpath
|
||||
.iter()
|
||||
.filter(|path| path.to_string_lossy().contains("only-"))
|
||||
.collect();
|
||||
assert_eq!(cpu_jars.len(), 1);
|
||||
assert!(cpu_jars[0].ends_with(format!("only-{normalized}-1.jar")));
|
||||
assert!(invocation.jvm_args.contains(&format!(
|
||||
"-Djava.library.path={}",
|
||||
platform
|
||||
.natives_directory(&fixture.meta_dir, "1.16.5")
|
||||
.display()
|
||||
)));
|
||||
assert_eq!(
|
||||
invocation
|
||||
.jvm_args
|
||||
.contains(&"-Dos.version=10.0".to_owned()),
|
||||
platform.os_name == "windows"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn zip_entries(entries: &[(&str, &[u8])]) -> Vec<u8> {
|
||||
use std::io::Write;
|
||||
let mut zip = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for (name, bytes) in entries {
|
||||
zip.start_file(*name, zip::write::SimpleFileOptions::default())
|
||||
.unwrap();
|
||||
zip.write_all(bytes).unwrap();
|
||||
}
|
||||
zip.finish().unwrap().into_inner()
|
||||
}
|
||||
|
||||
fn install_test_lwjgl3ify(fixture: &Fixture, base_url: &str) {
|
||||
use sha1::Digest;
|
||||
let bytes = b"declared library bytes";
|
||||
let mut libraries = Vec::new();
|
||||
for module in ["lwjgl", "lwjgl-sdl", "lwjgl-spng"] {
|
||||
libraries.push(json!({"name":format!("org.lwjgl:{module}:3.4.2"), "downloads":{"artifact":{
|
||||
"url":format!("{base_url}/{module}-3.4.2.jar"), "sha1":format!("{:x}", sha1::Sha1::digest(bytes)), "size":bytes.len(),
|
||||
}}}));
|
||||
for (classifier, os) in [
|
||||
("natives-linux", "linux"),
|
||||
("natives-linux-arm64", "linux"),
|
||||
("natives-macos", "osx"),
|
||||
("natives-macos-arm64", "osx"),
|
||||
("natives-windows", "windows"),
|
||||
("natives-windows-x86", "windows"),
|
||||
("natives-windows-arm64", "windows"),
|
||||
] {
|
||||
libraries.push(
|
||||
json!({"name":format!("org.lwjgl:{module}-{classifier}:3.4.2"),
|
||||
"rules":[{"action":"allow", "os":{"name":os}}], "downloads":{"artifact":{
|
||||
"url":format!("{base_url}/{module}-3.4.2-{classifier}.jar"),
|
||||
"sha1":format!("{:x}", sha1::Sha1::digest(bytes)), "size":bytes.len(),
|
||||
}}}),
|
||||
);
|
||||
}
|
||||
}
|
||||
let payload = zip_entries(&[("META-INF/MANIFEST.MF", b"Manifest-Version: 1.0\r\n")]);
|
||||
libraries.push(json!({"name":"com.github.GTNewHorizons:lwjgl3ify:3.0.35:forgePatches", "downloads":{"artifact":{
|
||||
"url":format!("{base_url}/forgePatches.jar"), "sha1":format!("{:x}", sha1::Sha1::digest(&payload)), "size":payload.len(),
|
||||
}}}));
|
||||
let profile = json!({"id":"lwjgl3ify-client", "mainClass":"com.gtnewhorizons.retrofuturabootstrap.MainStartOnFirstThread",
|
||||
"javaVersion":{"majorVersion":25}, "libraries":libraries,
|
||||
"arguments":{"game":["--username", "${auth_player_name}", "--tweakClass", "metadata.ClientTweaker"], "jvm":[
|
||||
{"rules":[{"action":"allow", "os":{"name":"osx"}}], "value":"-XstartOnFirstThread"},
|
||||
"--add-opens", "java.base/java.lang=ALL-UNNAMED", "--enable-native-access", "ALL-UNNAMED",
|
||||
"-Djava.library.path=${natives_directory}", "-cp", "${classpath}",
|
||||
"-Djava.system.class.loader=com.gtnewhorizons.retrofuturabootstrap.RfbSystemClassLoader",
|
||||
]},
|
||||
});
|
||||
let mods = fixture.instances_dir.join("patched/minecraft/mods");
|
||||
std::fs::create_dir_all(&mods).unwrap();
|
||||
std::fs::write(
|
||||
mods.join("lwjgl3ify-3.0.35.jar"),
|
||||
zip_entries(&[
|
||||
(
|
||||
"me/eigenraven/lwjgl3ify/relauncher/version.json",
|
||||
&serde_json::to_vec(&profile).unwrap(),
|
||||
),
|
||||
(
|
||||
"me/eigenraven/lwjgl3ify/relauncher/forgePatches.zip",
|
||||
&payload,
|
||||
),
|
||||
]),
|
||||
)
|
||||
.unwrap();
|
||||
fixture.write_loader_profile("forge-1.7.10-10.13.4.1614.json", json!({
|
||||
"id":"forge-1.7.10", "inheritsFrom":"1.7.10", "mainClass":"net.minecraft.launchwrapper.Launch",
|
||||
"libraries":[{"name":"net.minecraft:launchwrapper:1.12"}, {"name":"org.lwjgl.lwjgl:lwjgl-platform:2.9.4"}],
|
||||
"arguments":{"game":["--tweakClass", "old.parent.Tweaker"], "jvm":["-Dold.parent.jvm=true"]},
|
||||
}));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn lwjgl3ify_empty_cache_downloads_exact_metadata_and_renders_client_startup() {
|
||||
use wiremock::{Mock, MockServer, ResponseTemplate, matchers::method};
|
||||
for (os, arch, bits, classifier) in [
|
||||
("Linux", "amd64", "64", "natives-linux"),
|
||||
("Linux", "aarch64", "64", "natives-linux-arm64"),
|
||||
("Mac OS X", "amd64", "64", "natives-macos"),
|
||||
("Mac OS X", "aarch64", "64", "natives-macos-arm64"),
|
||||
("Windows 10", "x86", "32", "natives-windows-x86"),
|
||||
("Windows 10", "amd64", "64", "natives-windows"),
|
||||
("Windows 10", "aarch64", "64", "natives-windows-arm64"),
|
||||
] {
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
.respond_with(
|
||||
ResponseTemplate::new(200).set_body_bytes(b"declared library bytes".to_vec()),
|
||||
)
|
||||
.expect(6)
|
||||
.mount(&server)
|
||||
.await;
|
||||
let fixture = Fixture::new("patched", "1.7.10", legacy_vanilla_meta("1.7.10"));
|
||||
install_test_lwjgl3ify(&fixture, &server.uri());
|
||||
let platform = rmcl::launch_profile::system::JavaPlatform::from_java_properties(
|
||||
os, arch, bits, "10.0",
|
||||
)
|
||||
.unwrap();
|
||||
let mut config =
|
||||
make_config_with("patched", "1.7.10", ModLoader::Forge, Some("10.13.4.1614"));
|
||||
config.java_path = Some(fake_java_platform(&fixture._tmp, 25, &platform));
|
||||
for _ in 0..2 {
|
||||
let invocation = build_launch_invocation(
|
||||
&config,
|
||||
&fixture.instances_dir,
|
||||
&fixture.meta_dir,
|
||||
&test_auth(),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(invocation.main_class, "RmclShim");
|
||||
assert_eq!(
|
||||
invocation.extra_args,
|
||||
["com.gtnewhorizons.retrofuturabootstrap.MainStartOnFirstThread"]
|
||||
);
|
||||
assert_eq!(
|
||||
invocation
|
||||
.jvm_args
|
||||
.contains(&"-XstartOnFirstThread".to_owned()),
|
||||
platform.os_name == "osx"
|
||||
);
|
||||
assert!(
|
||||
invocation
|
||||
.jvm_args
|
||||
.windows(2)
|
||||
.any(|args| args == ["--enable-native-access", "ALL-UNNAMED"])
|
||||
);
|
||||
assert!(
|
||||
invocation
|
||||
.jvm_args
|
||||
.windows(2)
|
||||
.any(|args| args[0] == "-cp" && args[1] == invocation.classpath_string)
|
||||
);
|
||||
assert!(
|
||||
invocation
|
||||
.game_args
|
||||
.contains(&"metadata.ClientTweaker".to_owned())
|
||||
);
|
||||
assert!(
|
||||
!invocation
|
||||
.game_args
|
||||
.contains(&"old.parent.Tweaker".to_owned())
|
||||
);
|
||||
assert!(
|
||||
!invocation
|
||||
.jvm_args
|
||||
.contains(&"-Dold.parent.jvm=true".to_owned())
|
||||
);
|
||||
assert!(invocation.game_args.contains(&PLAYER.to_owned()));
|
||||
let natives: Vec<_> = invocation
|
||||
.classpath
|
||||
.iter()
|
||||
.filter(|path| path.to_string_lossy().contains("-natives-"))
|
||||
.collect();
|
||||
assert_eq!(natives.len(), 3);
|
||||
assert!(natives.iter().all(|path| {
|
||||
path.to_string_lossy()
|
||||
.contains(&format!("-{classifier}-3.4.2.jar"))
|
||||
}));
|
||||
for path in invocation.classpath.iter().filter(|path| {
|
||||
path.to_string_lossy().contains("org/lwjgl")
|
||||
|| path.to_string_lossy().contains("org\\lwjgl")
|
||||
}) {
|
||||
assert_eq!(std::fs::read(path).unwrap(), b"declared library bytes");
|
||||
}
|
||||
assert!(
|
||||
!invocation
|
||||
.classpath
|
||||
.iter()
|
||||
.any(|path| path.to_string_lossy().contains("2.9.4")
|
||||
|| path.to_string_lossy().contains("launchwrapper-"))
|
||||
);
|
||||
}
|
||||
server.verify().await;
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn lwjgl3ify_download_failure_does_not_launch_with_missing_libraries() {
|
||||
use wiremock::{Mock, MockServer, ResponseTemplate, matchers::method};
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
.respond_with(ResponseTemplate::new(404))
|
||||
.mount(&server)
|
||||
.await;
|
||||
let fixture = Fixture::new("patched", "1.7.10", legacy_vanilla_meta("1.7.10"));
|
||||
install_test_lwjgl3ify(&fixture, &server.uri());
|
||||
let config = make_config_with("patched", "1.7.10", ModLoader::Forge, Some("10.13.4.1614"));
|
||||
let error = build_launch_invocation(
|
||||
&config,
|
||||
&fixture.instances_dir,
|
||||
&fixture.meta_dir,
|
||||
&test_auth(),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert!(matches!(error, LaunchError::Download(_)), "{error}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn selected_java_is_resolved_and_probed_in_the_launch_environment_and_cwd() {
|
||||
let fixture = Fixture::new("context", "1.20.1", modern_vanilla_meta("1.20.1"));
|
||||
let minecraft = fixture.instances_dir.join("context/minecraft");
|
||||
std::fs::write(minecraft.join("expected-cwd"), b"ready").unwrap();
|
||||
let bin = fixture._tmp.path().join("custom java bin");
|
||||
std::fs::create_dir_all(&bin).unwrap();
|
||||
let name = if cfg!(windows) {
|
||||
"context-java.cmd"
|
||||
} else {
|
||||
"context-java"
|
||||
};
|
||||
let java = bin.join(name);
|
||||
let original = fake_java(&fixture._tmp, 25);
|
||||
let mut script = std::fs::read_to_string(original).unwrap();
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
script = script.replacen("#!/bin/sh\n", "#!/bin/sh\n[ \"$PROBE_CONTEXT\" = instance ] && [ -f expected-cwd ] || exit 77\nprintf '%s' \"$PROBE_CONTEXT\" > probe-context\n", 1);
|
||||
std::fs::write(&java, &script).unwrap();
|
||||
std::fs::set_permissions(&java, std::fs::Permissions::from_mode(0o755)).unwrap();
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
script = script.replacen("@echo off\r\n", "@echo off\r\nif not \"%PROBE_CONTEXT%\"==\"instance\" exit /b 77\r\nif not exist expected-cwd exit /b 78\r\necho %PROBE_CONTEXT%>probe-context\r\n", 1);
|
||||
std::fs::write(&java, &script).unwrap();
|
||||
}
|
||||
let mut settings = rmcl::config::Config::default();
|
||||
settings
|
||||
.defaults
|
||||
.environment
|
||||
.insert("PATH".into(), "missing-global-path".into());
|
||||
settings
|
||||
.defaults
|
||||
.environment
|
||||
.insert("PROBE_CONTEXT".into(), "global".into());
|
||||
let mut config = make_config("context", "1.20.1", ModLoader::Vanilla);
|
||||
config.java_path = Some(name.into());
|
||||
config.environment.insert(
|
||||
if cfg!(windows) { "path" } else { "PATH" }.into(),
|
||||
bin.to_string_lossy().into_owned(),
|
||||
);
|
||||
config.environment.insert(
|
||||
if cfg!(windows) {
|
||||
"probe_context"
|
||||
} else {
|
||||
"PROBE_CONTEXT"
|
||||
}
|
||||
.into(),
|
||||
"instance".into(),
|
||||
);
|
||||
let invocation = build_launch_invocation_with_settings(
|
||||
&config,
|
||||
&fixture.instances_dir,
|
||||
&fixture.meta_dir,
|
||||
&test_auth(),
|
||||
None,
|
||||
&settings,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
Path::new(&invocation.java).canonicalize().unwrap(),
|
||||
java.canonicalize().unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(minecraft.join("probe-context"))
|
||||
.unwrap()
|
||||
.trim(),
|
||||
"instance"
|
||||
);
|
||||
assert_eq!(invocation.working_dir, minecraft);
|
||||
let cwd = invocation.working_dir.clone();
|
||||
let environment = invocation.environment.clone();
|
||||
let installation = tokio::task::spawn_blocking(move || {
|
||||
rmcl::instance::java::inspect_installation_in(Path::new(name), &cwd, &environment)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
installation.path.canonicalize().unwrap(),
|
||||
java.canonicalize().unwrap()
|
||||
);
|
||||
assert_eq!(installation.version.as_deref(), Some("25.0.1"));
|
||||
if cfg!(windows) {
|
||||
assert_eq!(
|
||||
invocation
|
||||
.environment
|
||||
.keys()
|
||||
.filter(|key| key.eq_ignore_ascii_case("PATH"))
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user