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

+25 -15
View File
@@ -103,27 +103,37 @@ mod tests {
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]
fn peek_all_returns_newest_first() {
push_error(make_event("err_all_a"));
push_error(make_event("err_all_b"));
let all = peek_all_errors();
assert!(all.len() >= 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<u64> = all.iter().map(|e| e.id).collect();
let unique: std::collections::HashSet<u64> = 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]