added: tests for retry envelope, manager rename, mod precedence, time buckets

Audit identified six high-priority coverage gaps. This commit closes
them with 30 net new passing tests.

- tests/net_retry.rs (new): 5 wiremock-based tests for the retry
  envelope in net/mod.rs. Covers get_json + download_file across:
  5xx retry-then-succeed, 4xx fail-fast (asserted via wiremock
  expect(1) so any retry attempt fails the test), and exhaust at
  MAX_RETRIES = 3 (asserted via expect(4)). The exhaust test takes
  ~3.5s of wall time because the production code sleeps 500 + 1000 +
  2000 ms between attempts; this is unavoidable without making the
  delays configurable.

- tests/launch_pipeline.rs: 3 new error-path tests against
  build_launch_invocation. merged_profile_missing_main_class_fails
  surfaces the LaunchError::Parse branch when meta.json deserialises
  cleanly but lacks mainClass. legacy_loader_profile_missing_loader_version_errors
  and legacy_loader_profile_missing_installer_json_errors exercise the
  two Parse branches inside migrate_legacy_loader_profile_if_needed.

- instance/manager.rs: 6 tests for rename (happy path, noop on same
  name, empty target rejected, missing source, target collision) and
  touch_last_played (sets the field to a stamp within 5 seconds of
  now). The InstanceManager rename surface had no coverage before;
  mutating the validation order or the std::fs::rename target would
  not have failed any existing test.

- instance/content/mods.rs: 4 new precedence-chain tests. The reader
  chain is fabric > quilt > forge-toml (which itself tries
  neoforge.mods.toml before mods.toml) > mcmod.info. Only the
  fabric-over-forge precedence had a test before. Adds quilt > forge,
  forge_toml > mcmod_info, neoforge.mods.toml > mods.toml, and a test
  that a mods.toml carrying only logoFile (no [[mods]] array) still
  resolves the icon.

- tui/widgets/instances.rs: 12 new tests for format_last_played. One
  case for the None input (returns "Never played"), then an rstest
  covering each bucket boundary in the match (0/59 just-now,
  60/3599 minutes, 3600/86399 hours, 86400/2591999 days,
  2592000/31535999 months, >=31536000 over-a-year). A mutation that
  bumps any boundary by one second, or swaps a unit suffix, fails at
  least one case.
This commit is contained in:
objz committed 2026-05-27 16:44:05 +02:00
1 parent 7a9dfa850d
commit 623acd9e2c
5 files changed
+438

No files matched your search

+30
View File
@@ -337,3 +337,33 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
&mut state.scrollbar_state,
);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn format_last_played_none_returns_never_played() {
assert_eq!(format_last_played(None), "Never played");
}
// each #[case] picks a "seconds ago" value that lands in exactly one
// bucket of the match. mutating any bucket boundary (e.g. 3600 to 3601,
// or "minutes" to "seconds") makes one of these cases fail.
#[rstest::rstest]
#[case::just_now(0, "Just now")]
#[case::just_now_upper(59, "Just now")]
#[case::minutes(60, "1 minutes ago")]
#[case::minutes_upper(3599, "59 minutes ago")]
#[case::hours(3600, "1 hours ago")]
#[case::hours_upper(86_399, "23 hours ago")]
#[case::days(86_400, "1 days ago")]
#[case::days_upper(2_591_999, "29 days ago")]
#[case::months(2_592_000, "1 months ago")]
#[case::months_upper(31_535_999, "12 months ago")]
#[case::over_a_year(31_536_000, "Over a year ago")]
fn format_last_played_buckets(#[case] seconds_ago: i64, #[case] expected: &str) {
let dt = chrono::Utc::now() - chrono::Duration::seconds(seconds_ago);
assert_eq!(format_last_played(Some(dt)), expected);
}
}