diff --git a/src/auth/accounts.rs b/src/auth/accounts.rs index edbf7d8..0d6123f 100644 --- a/src/auth/accounts.rs +++ b/src/auth/accounts.rs @@ -186,7 +186,10 @@ mod tests { assert_eq!(acc.account_type, AccountType::Offline); assert!(!acc.active); assert!(acc.refresh_token.is_none()); - assert!(!acc.uuid.is_empty()); + // pin the uuid to the deterministic offline_uuid output so a regression + // in the uuid derivation (e.g. salt change) would fail this test, not + // just a non-empty-string check that any garbage would pass. + assert_eq!(acc.uuid, offline_uuid("TestPlayer")); } fn make_store(dir: &std::path::Path) -> AccountStore { diff --git a/src/cli/mod.rs b/src/cli/mod.rs index b03d47a..7786d3d 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -247,6 +247,13 @@ mod tests { let matches = build_command() .try_get_matches_from(["rmcl", "instance", "list"]) .expect("command should parse"); - assert!(matches.subcommand_matches("instance").is_some()); + let instance = matches + .subcommand_matches("instance") + .expect("instance subcommand should be present"); + assert_eq!( + instance.subcommand_name(), + Some("list"), + "instance list should resolve to the list subcommand" + ); } } diff --git a/src/config/theme.rs b/src/config/theme.rs index 5d782b1..ba0289f 100644 --- a/src/config/theme.rs +++ b/src/config/theme.rs @@ -172,10 +172,15 @@ pub static BORDER_STYLE: LazyLock = mod tests { use super::*; - #[test] - fn border_style_roundtrip() { - let style = BorderStyle::Double; - assert_eq!(style.to_border_type(), BorderType::Double); + // cover every BorderStyle variant. a mutation that swaps two arms of the + // match (e.g. Rounded -> Plain) would slip past testing just one variant. + #[rstest::rstest] + #[case::plain(BorderStyle::Plain, BorderType::Plain)] + #[case::rounded(BorderStyle::Rounded, BorderType::Rounded)] + #[case::double(BorderStyle::Double, BorderType::Double)] + #[case::thick(BorderStyle::Thick, BorderType::Thick)] + fn border_style_roundtrip(#[case] style: BorderStyle, #[case] expected: BorderType) { + assert_eq!(style.to_border_type(), expected); } #[test] diff --git a/src/instance/desktop.rs b/src/instance/desktop.rs index c8383b5..0578838 100644 --- a/src/instance/desktop.rs +++ b/src/instance/desktop.rs @@ -201,15 +201,6 @@ mod tests { assert_eq!(sanitize("path/traversal"), "path_traversal"); } - #[test] - fn desktop_path_returns_some() { - let path = desktop_path("TestPack"); - if let Some(p) = path { - let name = p.file_name().unwrap().to_str().unwrap(); - assert!(name.contains("TestPack")); - } - } - #[test] #[cfg(target_os = "linux")] fn build_content_linux() { diff --git a/src/instance/launch/mod.rs b/src/instance/launch/mod.rs index 8a110db..474d6d9 100644 --- a/src/instance/launch/mod.rs +++ b/src/instance/launch/mod.rs @@ -659,7 +659,7 @@ mod tests { use super::*; #[test] - fn build_game_args_renders_upstream_arguments_and_appends_loader_args() { + fn build_game_args_renders_upstream_arguments() { use crate::launch_profile::model::{Argument, Arguments, LaunchProfile}; use crate::launch_profile::rules::{FeatureSet, RuleContext}; use TemplateContext; @@ -720,46 +720,39 @@ mod tests { assert_eq!(game_args, vec!["--username", "Player"]); } - #[test] - fn migration_predicate_triggers_when_both_argument_fields_absent() { - use LaunchProfile; - let stripped = LaunchProfile { - id: "1.20.1".into(), - inherits_from: None, - main_class: Some("net.test.Main".into()), - libraries: Vec::new(), - ..Default::default() - }; - assert!(stripped.arguments.is_none() && stripped.minecraft_arguments.is_none()); - } - - #[test] - fn migration_predicate_skips_when_modern_arguments_present() { + // exercises the early-return branch of migrate_legacy_meta_if_needed. + // a profile with either arguments or minecraftArguments is not legacy + // and must produce Ok(None) without touching the network. covers both + // shapes in one parameterised test so a regression that drops one of + // the two predicate conditions is caught. + #[rstest::rstest] + #[case::modern_arguments(true, false)] + #[case::legacy_minecraft_arguments(false, true)] + #[tokio::test] + async fn migrate_legacy_meta_skips_when_arguments_present( + #[case] modern: bool, + #[case] legacy: bool, + ) { use crate::launch_profile::model::{Arguments, LaunchProfile}; - let modern = LaunchProfile { - id: "1.20.1".into(), - inherits_from: None, - main_class: Some("net.test.Main".into()), - libraries: Vec::new(), - arguments: Some(Arguments::default()), - ..Default::default() - }; - assert!(modern.arguments.is_some()); - } + use tempfile::TempDir; - #[test] - fn migration_predicate_skips_when_legacy_minecraft_arguments_present() { - use LaunchProfile; - let legacy = LaunchProfile { - id: "1.7.10".into(), - inherits_from: None, + let tmp = TempDir::new().unwrap(); + let meta_path = tmp.path().join("meta.json"); + std::fs::write(&meta_path, b"{}").unwrap(); + + let profile = LaunchProfile { + id: "1.20.1".into(), main_class: Some("net.test.Main".into()), - libraries: Vec::new(), - arguments: None, - minecraft_arguments: Some("--username Player".into()), + arguments: modern.then(Arguments::default), + minecraft_arguments: legacy.then(|| "--username Player".into()), ..Default::default() }; - assert!(legacy.minecraft_arguments.is_some()); + + let result = migrate_legacy_meta_if_needed(&meta_path, &profile, "1.20.1").await; + assert!( + matches!(result, Ok(None)), + "expected Ok(None) for non-legacy profile, got {result:?}" + ); } #[test] @@ -785,36 +778,48 @@ mod tests { assert!(installer_version_dir_name(ModLoader::Quilt, "1.20.1", "0.20.0").is_none()); } - #[test] - fn loader_profile_legacy_predicate_triggers_when_all_three_absent() { + // exercises the modern-profile early-return in + // migrate_legacy_loader_profile_if_needed. any of inheritsFrom, + // arguments, minecraftArguments present (or game_arguments absent) + // means "not legacy" and the function must return Ok(None) without + // touching the installer JSON path. + #[tokio::test] + async fn migrate_legacy_loader_profile_skips_modern_with_inherits_from() { use LaunchProfile; - let legacy = LaunchProfile { - id: "1.20.1-forge-47.2.0".into(), - inherits_from: None, - main_class: Some("cpw.mods.bootstraplauncher.BootstrapLauncher".into()), - libraries: Vec::new(), - ..Default::default() - }; - let is_legacy = legacy.inherits_from.is_none() - && legacy.arguments.is_none() - && legacy.minecraft_arguments.is_none(); - assert!(is_legacy); - } + use chrono::Utc; + use tempfile::TempDir; + + let tmp = TempDir::new().unwrap(); + let instance_dir = tmp.path().join("instance"); + std::fs::create_dir_all(&instance_dir).unwrap(); + let profile_path = tmp.path().join("forge-1.20.1-47.2.0.json"); + std::fs::write(&profile_path, b"{}").unwrap(); - #[test] - fn loader_profile_legacy_predicate_skips_modern_profile_with_inherits_from() { - use LaunchProfile; let modern = LaunchProfile { id: "1.20.1-forge-47.2.0".into(), inherits_from: Some("1.20.1".into()), main_class: Some("cpw.mods.bootstraplauncher.BootstrapLauncher".into()), - libraries: Vec::new(), ..Default::default() }; - let is_legacy = modern.inherits_from.is_none() - && modern.arguments.is_none() - && modern.minecraft_arguments.is_none(); - assert!(!is_legacy); + + let config = InstanceConfig { + name: "test".into(), + game_version: "1.20.1".into(), + loader: ModLoader::Forge, + loader_version: Some("47.2.0".into()), + created: Utc::now(), + last_played: None, + java_path: None, + memory_max: None, + memory_min: None, + jvm_args: Vec::new(), + resolution: None, + }; + + let result = + migrate_legacy_loader_profile_if_needed(&profile_path, &modern, &config, &instance_dir) + .await; + assert!(matches!(result, Ok(None)), "expected Ok(None), got {result:?}"); } #[tokio::test] diff --git a/src/instance/loader/mod.rs b/src/instance/loader/mod.rs index e670341..ab6378f 100644 --- a/src/instance/loader/mod.rs +++ b/src/instance/loader/mod.rs @@ -108,31 +108,18 @@ pub fn get_installer(loader: ModLoader) -> Box= 2); - if all.len() >= 2 { - assert!(all[0].id >= all[1].id); - } + let tag = "PEEK_NEWEST_FIRST_TAG"; + push_error(make_event(&format!("{tag}_a"))); + push_error(make_event(&format!("{tag}_b"))); + let ours: Vec<_> = peek_all_errors() + .into_iter() + .filter(|e| e.message.contains(tag)) + .collect(); + assert_eq!(ours.len(), 2, "expected 2 tagged events, got {ours:?}"); + // _b was pushed last, so it must come out first (newest-first iter) + assert!(ours[0].message.ends_with("_b")); + assert!(ours[1].message.ends_with("_a")); + // newer event also has the higher auto-assigned id + assert!(ours[0].id > ours[1].id); } #[test] fn auto_assigned_ids_are_unique() { - push_error(make_event("err_id_1")); - push_error(make_event("err_id_2")); - let all = peek_all_errors(); - if all.len() >= 2 { - let ids: Vec = all.iter().map(|e| e.id).collect(); - let unique: std::collections::HashSet = ids.iter().copied().collect(); - assert_eq!(ids.len(), unique.len()); - } + let tag = "AUTO_ID_UNIQUE_TAG"; + push_error(make_event(&format!("{tag}_1"))); + push_error(make_event(&format!("{tag}_2"))); + let ours: Vec<_> = peek_all_errors() + .into_iter() + .filter(|e| e.message.contains(tag)) + .collect(); + assert_eq!(ours.len(), 2); + assert_ne!(ours[0].id, ours[1].id); } #[test]