refactored: rework weak unit tests to catch real regressions

Audit found 9 confirmed-weak unit tests plus several newly-found ones that
asserted things equivalent to themselves, returned vacuous truth, or had
assertions guarded behind conditionals that silently swallowed failure.

Changes by file:

- auth/accounts.rs: create_offline_account_fields now pins the uuid to
  offline_uuid("TestPlayer") instead of !is_empty(); mutating the uuid
  derivation would fail this now.
- cli/mod.rs: parses_instance_list_subcommand drills into the list
  subcommand under instance rather than only verifying the instance
  group exists.
- config/theme.rs: border_style_roundtrip is now an rstest covering all
  four BorderStyle variants; mutating any non-Double arm is caught.
- instance/desktop.rs: removed desktop_path_returns_some (assertion was
  gated behind if let Some so could pass when the function returned
  None); build_content_linux* already covers the real behaviour.
- instance/launch/mod.rs: removed five predicate-only tests that
  asserted serde defaulting on LaunchProfile rather than invoking the
  migration predicate. Added two tests that actually call
  migrate_legacy_meta_if_needed (rstest over modern/legacy arg shapes)
  and migrate_legacy_loader_profile_if_needed (modern-with-inheritsFrom
  early-return). Renamed build_game_args_renders_upstream_arguments,
  dropping the misleading "and appends loader args" clause that the
  test never covered.
- instance/loader/mod.rs: removed test_vanilla_install_noop (no
  assertion at all) and test_vanilla_get_versions (asserted a hardcoded
  Ok(vec!["vanilla"]) return). Replaced test_vanilla_factory with an
  rstest covering all five ModLoader variants; a misordered match arm
  in get_installer is caught.
- migrate.rs: removed cleanup_instance_leftovers_handles_missing_dir
  (had no assertions and was redundant with
  cleanup_instance_leftovers_removes_shim_and_log4j).
- net/mod.rs: removed detect_java_falls_back_to_java which asserted
  !is_empty() against a function whose worst-case fallback is the
  literal string "java"; structurally uncatchable.
- tui/error_buffer.rs: peek_all_returns_newest_first and
  auto_assigned_ids_are_unique now tag their pushed events with a
  unique substring and filter peek_all_errors to just those, so the
  assertions actually fire instead of being silently skipped via
  if all.len() >= 2 when shared static state interfered.

Total: net zero change in test count (deletions and parameterised
replacements roughly balance), but mutation coverage of the surviving
suite is materially stronger.
This commit is contained in:
objz committed 2026-05-27 16:43:47 +02:00
1 parent d2e08d818b
commit 7a9dfa850d
9 files changed
+121 -124

No files matched your search

+4 -1
View File
@@ -186,7 +186,10 @@ mod tests {
assert_eq!(acc.account_type, AccountType::Offline); assert_eq!(acc.account_type, AccountType::Offline);
assert!(!acc.active); assert!(!acc.active);
assert!(acc.refresh_token.is_none()); 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 { fn make_store(dir: &std::path::Path) -> AccountStore {
+8 -1
View File
@@ -247,6 +247,13 @@ mod tests {
let matches = build_command() let matches = build_command()
.try_get_matches_from(["rmcl", "instance", "list"]) .try_get_matches_from(["rmcl", "instance", "list"])
.expect("command should parse"); .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"
);
} }
} }
+9 -4
View File
@@ -172,10 +172,15 @@ pub static BORDER_STYLE: LazyLock<BorderStyle> =
mod tests { mod tests {
use super::*; use super::*;
#[test] // cover every BorderStyle variant. a mutation that swaps two arms of the
fn border_style_roundtrip() { // match (e.g. Rounded -> Plain) would slip past testing just one variant.
let style = BorderStyle::Double; #[rstest::rstest]
assert_eq!(style.to_border_type(), BorderType::Double); #[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] #[test]
-9
View File
@@ -201,15 +201,6 @@ mod tests {
assert_eq!(sanitize("path/traversal"), "path_traversal"); 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] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn build_content_linux() { fn build_content_linux() {
+63 -58
View File
@@ -659,7 +659,7 @@ mod tests {
use super::*; use super::*;
#[test] #[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::model::{Argument, Arguments, LaunchProfile};
use crate::launch_profile::rules::{FeatureSet, RuleContext}; use crate::launch_profile::rules::{FeatureSet, RuleContext};
use TemplateContext; use TemplateContext;
@@ -720,46 +720,39 @@ mod tests {
assert_eq!(game_args, vec!["--username", "Player"]); assert_eq!(game_args, vec!["--username", "Player"]);
} }
#[test] // exercises the early-return branch of migrate_legacy_meta_if_needed.
fn migration_predicate_triggers_when_both_argument_fields_absent() { // a profile with either arguments or minecraftArguments is not legacy
use LaunchProfile; // and must produce Ok(None) without touching the network. covers both
let stripped = LaunchProfile { // shapes in one parameterised test so a regression that drops one of
id: "1.20.1".into(), // the two predicate conditions is caught.
inherits_from: None, #[rstest::rstest]
main_class: Some("net.test.Main".into()), #[case::modern_arguments(true, false)]
libraries: Vec::new(), #[case::legacy_minecraft_arguments(false, true)]
..Default::default() #[tokio::test]
}; async fn migrate_legacy_meta_skips_when_arguments_present(
assert!(stripped.arguments.is_none() && stripped.minecraft_arguments.is_none()); #[case] modern: bool,
} #[case] legacy: bool,
) {
#[test]
fn migration_predicate_skips_when_modern_arguments_present() {
use crate::launch_profile::model::{Arguments, LaunchProfile}; use crate::launch_profile::model::{Arguments, LaunchProfile};
let modern = LaunchProfile { use tempfile::TempDir;
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());
}
#[test] let tmp = TempDir::new().unwrap();
fn migration_predicate_skips_when_legacy_minecraft_arguments_present() { let meta_path = tmp.path().join("meta.json");
use LaunchProfile; std::fs::write(&meta_path, b"{}").unwrap();
let legacy = LaunchProfile {
id: "1.7.10".into(), let profile = LaunchProfile {
inherits_from: None, id: "1.20.1".into(),
main_class: Some("net.test.Main".into()), main_class: Some("net.test.Main".into()),
libraries: Vec::new(), arguments: modern.then(Arguments::default),
arguments: None, minecraft_arguments: legacy.then(|| "--username Player".into()),
minecraft_arguments: Some("--username Player".into()),
..Default::default() ..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] #[test]
@@ -785,36 +778,48 @@ mod tests {
assert!(installer_version_dir_name(ModLoader::Quilt, "1.20.1", "0.20.0").is_none()); assert!(installer_version_dir_name(ModLoader::Quilt, "1.20.1", "0.20.0").is_none());
} }
#[test] // exercises the modern-profile early-return in
fn loader_profile_legacy_predicate_triggers_when_all_three_absent() { // 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; use LaunchProfile;
let legacy = LaunchProfile { use chrono::Utc;
id: "1.20.1-forge-47.2.0".into(), use tempfile::TempDir;
inherits_from: None,
main_class: Some("cpw.mods.bootstraplauncher.BootstrapLauncher".into()), let tmp = TempDir::new().unwrap();
libraries: Vec::new(), let instance_dir = tmp.path().join("instance");
..Default::default() std::fs::create_dir_all(&instance_dir).unwrap();
}; let profile_path = tmp.path().join("forge-1.20.1-47.2.0.json");
let is_legacy = legacy.inherits_from.is_none() std::fs::write(&profile_path, b"{}").unwrap();
&& legacy.arguments.is_none()
&& legacy.minecraft_arguments.is_none();
assert!(is_legacy);
}
#[test]
fn loader_profile_legacy_predicate_skips_modern_profile_with_inherits_from() {
use LaunchProfile;
let modern = LaunchProfile { let modern = LaunchProfile {
id: "1.20.1-forge-47.2.0".into(), id: "1.20.1-forge-47.2.0".into(),
inherits_from: Some("1.20.1".into()), inherits_from: Some("1.20.1".into()),
main_class: Some("cpw.mods.bootstraplauncher.BootstrapLauncher".into()), main_class: Some("cpw.mods.bootstraplauncher.BootstrapLauncher".into()),
libraries: Vec::new(),
..Default::default() ..Default::default()
}; };
let is_legacy = modern.inherits_from.is_none()
&& modern.arguments.is_none() let config = InstanceConfig {
&& modern.minecraft_arguments.is_none(); name: "test".into(),
assert!(!is_legacy); 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] #[tokio::test]
+12 -25
View File
@@ -108,31 +108,18 @@ pub fn get_installer(loader: ModLoader) -> Box<dyn ModLoaderInstaller + Send + S
mod tests { mod tests {
use super::*; use super::*;
#[test] // the factory maps every ModLoader variant to its concrete installer.
fn test_vanilla_factory() { // covering all five arms catches a misordered match or a copy-paste typo
let installer = get_installer(ModLoader::Vanilla); // that would route, say, NeoForge to the Forge installer.
assert_eq!(installer.loader_type(), ModLoader::Vanilla); #[rstest::rstest]
} #[case::vanilla(ModLoader::Vanilla)]
#[case::forge(ModLoader::Forge)]
#[tokio::test] #[case::neoforge(ModLoader::NeoForge)]
async fn test_vanilla_get_versions() { #[case::fabric(ModLoader::Fabric)]
let client = HttpClient::new(); #[case::quilt(ModLoader::Quilt)]
let installer = VanillaInstaller; fn get_installer_returns_matching_loader_type(#[case] loader: ModLoader) {
let versions = installer.get_versions(&client, "1.20.1").await.unwrap(); let installer = get_installer(loader);
assert!(!versions.is_empty()); assert_eq!(installer.loader_type(), loader);
assert_eq!(versions[0], "vanilla");
}
#[tokio::test]
async fn test_vanilla_install_noop() {
let client = HttpClient::new();
let installer = VanillaInstaller;
let tmp = std::env::temp_dir().join("rmcl_test_vanilla_install");
let meta = std::env::temp_dir().join("rmcl_test_meta");
installer
.install(&client, "1.20.1", "vanilla", &tmp, &meta)
.await
.unwrap();
} }
#[tokio::test] #[tokio::test]
-6
View File
@@ -262,12 +262,6 @@ mod tests {
assert!(mc.join("keep.txt").exists()); assert!(mc.join("keep.txt").exists());
} }
#[test]
fn cleanup_instance_leftovers_handles_missing_dir() {
let nowhere = unique_tmp("missing").join("does-not-exist");
cleanup_instance_leftovers(&nowhere);
}
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn rewrite_linux_desktop_entries_renames_and_rewrites_exec() { fn rewrite_linux_desktop_entries_renames_and_rewrites_exec() {
-5
View File
@@ -298,9 +298,4 @@ mod tests {
assert_eq!(maven_coord_to_path(""), None); assert_eq!(maven_coord_to_path(""), None);
} }
#[test]
fn detect_java_falls_back_to_java() {
let result = detect_java_path();
assert!(!result.is_empty());
}
} }
+25 -15
View File
@@ -103,27 +103,37 @@ mod tests {
assert!(has_errors()); assert!(has_errors());
} }
// ERROR_EVENTS is a global static shared across tests, so we tag our
// events with a unique substring and filter to just those before
// asserting; otherwise concurrent tests would interfere.
#[test] #[test]
fn peek_all_returns_newest_first() { fn peek_all_returns_newest_first() {
push_error(make_event("err_all_a")); let tag = "PEEK_NEWEST_FIRST_TAG";
push_error(make_event("err_all_b")); push_error(make_event(&format!("{tag}_a")));
let all = peek_all_errors(); push_error(make_event(&format!("{tag}_b")));
assert!(all.len() >= 2); let ours: Vec<_> = peek_all_errors()
if all.len() >= 2 { .into_iter()
assert!(all[0].id >= all[1].id); .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] #[test]
fn auto_assigned_ids_are_unique() { fn auto_assigned_ids_are_unique() {
push_error(make_event("err_id_1")); let tag = "AUTO_ID_UNIQUE_TAG";
push_error(make_event("err_id_2")); push_error(make_event(&format!("{tag}_1")));
let all = peek_all_errors(); push_error(make_event(&format!("{tag}_2")));
if all.len() >= 2 { let ours: Vec<_> = peek_all_errors()
let ids: Vec<u64> = all.iter().map(|e| e.id).collect(); .into_iter()
let unique: std::collections::HashSet<u64> = ids.iter().copied().collect(); .filter(|e| e.message.contains(tag))
assert_eq!(ids.len(), unique.len()); .collect();
} assert_eq!(ours.len(), 2);
assert_ne!(ours[0].id, ours[1].id);
} }
#[test] #[test]