refactored: final review polish and detect_format + neoforge coverage

Addresses the six items the last review flagged. Four are polish for
existing tests; two add coverage for previously-untested public APIs.

Polish:

- instance/content/mods.rs: icon_path_from_value_map now asserts a
  single deterministic value. serde_json::Map is a BTreeMap so the
  "128" key sorts before "64" and the test no longer needs an
  order-tolerant disjunction.

- cli/log.rs: replace the hand-rolled unique_temp_dir with
  tempfile::tempdir() across both tests. Drop the trailing
  remove_dir_all cleanup since TempDir handles that on Drop. Last
  inline test file using the hand-rolled pattern.

- running.rs: remove drain_empty_returns_empty. Two consecutive calls
  to drain_last_played in the same test can race with the parallel
  push_and_drain_last_played test which pushes to the same global
  LAST_PLAYED state. drain semantics are covered by the existing
  push_and_drain test.

- tui/error_buffer.rs: peek_does_not_remove now actually verifies the
  invariant the name promises. Pushes a tagged event, captures the
  count before and after peek_error, asserts the count is unchanged
  and the tagged event is still in the queue. Previous version only
  asserted that something was returned.

New coverage:

- net/neoforge.rs: added fetch_neoforge_game_versions_from(client,
  api_url) mirroring the existing _from pattern. tests/net_loaders.rs
  gains neoforge_fetch_game_versions_reverse_engineers_mc_versions
  covering the maven-version-to-MC-version reverse mapping, which was
  only touched by the #[ignore] live API test before.

- instance/import/mod.rs: six new tests for detect_format covering
  mrpack detection, mmc-pack at root and nested, the priority case
  where both markers are present, unknown archives, and missing
  files. Helper make_pack_zip builds in-memory zips so the tests
  don't need fixture files on disk.
This commit is contained in:
objz committed 2026-05-27 18:55:19 +02:00
1 parent 5f43128a80
commit c6c774b1e3
7 files changed
+157 -36

No files matched your search

+33 -1
View File
@@ -12,7 +12,7 @@ use rmcl::net::fabric::{
fetch_fabric_game_versions_from, fetch_fabric_profile_from, fetch_fabric_versions_from,
};
use rmcl::net::forge::{fetch_forge_game_versions_from, fetch_forge_versions_from};
use rmcl::net::neoforge::fetch_neoforge_versions_from;
use rmcl::net::neoforge::{fetch_neoforge_game_versions_from, fetch_neoforge_versions_from};
use rmcl::net::quilt::{
fetch_quilt_game_versions_from, fetch_quilt_profile_from, fetch_quilt_versions_from,
};
@@ -229,6 +229,38 @@ async fn neoforge_fetch_versions_filters_by_prefix() {
assert_eq!(versions, vec!["20.4.190", "20.4.150"]);
}
#[tokio::test]
async fn neoforge_fetch_game_versions_reverse_engineers_mc_versions() {
// neoforge "21.0.x" maps back to MC 1.21 (minor=0 strips the suffix);
// "20.4.x" maps to MC 1.20.4. beta/alpha suffixes don't affect the
// reverse mapping since the major/minor extraction happens first.
let server = MockServer::start().await;
Mock::given(method("GET"))
.and(path("/maven-api"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"versions": [
"21.0.10",
"21.0.5",
"20.4.190",
"20.4.150"
]
})))
.mount(&server)
.await;
let url = format!("{}/maven-api", server.uri());
let versions = fetch_neoforge_game_versions_from(&HttpClient::new(), &url)
.await
.expect("neoforge game versions");
let ids: Vec<&str> = versions.iter().map(|v| v.id.as_str()).collect();
// dedup keeps the first occurrence, output is reversed, so the
// resulting list is in upstream maven-version order, deduped.
assert!(ids.contains(&"1.21"));
assert!(ids.contains(&"1.20.4"));
// both versions should be marked stable (no snapshot flag in maven)
assert!(versions.iter().all(|v| v.stable));
}
#[tokio::test]
async fn neoforge_fetch_versions_rejects_invalid_game_version() {
let server = MockServer::start().await;