added: deferred tests-only items (extra wizard snapshots + library/asset downloads)

Closes the "zero production touches" subset of the deferred coverage
items the audit had flagged.

- src/tui/widgets/popups/new_instance/render.rs: three new snapshots
  for the Version, LoaderVersion, and Confirm steps. Each pre-populates
  WIZARD_STATE so ensure_versions_loaded and ensure_loader_versions_loaded
  short-circuit on LoadState::Loaded and never spawn a network task. The
  TEST_SERIAL mutex established in the earlier batch serialises against
  the existing Name/Loader snapshots.

- src/tui/widgets/popups/import_modpack/render.rs: two new snapshots
  for the Version step (synthetic VersionInfo entries) and the Confirm
  step (synthetic ImportSummary). Same serialisation pattern.

- tests/net_mojang.rs: three new wiremock tests.
  download_libraries_writes_artifact_to_meta_dir constructs a synthetic
  VersionMeta whose single library points at the wiremock server, then
  asserts the bytes land at meta_dir/libraries/<artifact.path>.
  download_libraries_skips_when_destination_exists verifies the cache
  hit path via wiremock's expect(0).
  download_assets_writes_index_when_objects_is_empty exercises the
  index fetch+write code path with an empty objects map so the per-asset
  download loop never fires.

  Zero production touches. download_libraries already takes a
  VersionMeta whose libraries carry their own URLs; download_assets'
  index fetch reads from meta.asset_index.url (also configurable
  per-call), so the empty-objects path doesn't need ASSETS_BASE_URL
  overridable. Full per-asset coverage lands in a separate commit.
This commit is contained in:
objz committed 2026-05-27 18:03:57 +02:00
1 parent d612f83446
commit 0d1b7984fc
8 files changed
+431 -1

No files matched your search

@@ -279,4 +279,80 @@ mod tests {
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
// Version step: pre-populate versions as LoadState::Loaded with synthetic
// VersionInfo entries so render walks the list path without triggering
// any network helpers.
#[test]
fn import_modpack_renders_version_step() {
use crate::net::modrinth::VersionInfo;
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
{
let mut guard = IMPORT_STATE.lock().expect("IMPORT_STATE lock");
*guard = ImportWizardState::default();
guard.step = ImportStep::Version;
guard.project_title = Some("Synthetic Pack".into());
guard.versions = LoadState::Loaded(vec![
VersionInfo {
id: "v1".into(),
name: "1.0.0".into(),
version_number: "1.0.0".into(),
game_versions: vec!["1.20.1".into()],
loaders: vec!["fabric".into()],
files: vec![],
},
VersionInfo {
id: "v2".into(),
name: "0.9.0".into(),
version_number: "0.9.0".into(),
game_versions: vec!["1.20.1".into()],
loaders: vec!["fabric".into()],
files: vec![],
},
]);
}
let backend = TestBackend::new(60, 14);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::ImportPopup))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
// Confirm step: needs a populated ImportSummary so the render path
// doesn't bail. ImportSummary is constructed manually with synthetic
// values; archive_path is a fake tempdir-ish path that never gets read.
#[test]
fn import_modpack_renders_confirm_step() {
use crate::instance::import::{ImportSummary, PackFormat};
use crate::instance::models::ModLoader;
use std::path::PathBuf;
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
{
let mut guard = IMPORT_STATE.lock().expect("IMPORT_STATE lock");
*guard = ImportWizardState::default();
guard.step = ImportStep::Confirm;
guard.summary = Some(ImportSummary {
name: "Synthetic Pack".into(),
pack_version: "1.0.0".into(),
game_version: "1.20.1".into(),
loader: ModLoader::Fabric,
loader_version: Some("0.15.0".into()),
mod_count: 42,
override_count: 3,
format: PackFormat::Mrpack,
archive_path: PathBuf::from("/tmp/synthetic.mrpack"),
});
}
let backend = TestBackend::new(60, 14);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::ImportPopup))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
}
@@ -0,0 +1,18 @@
---
source: src/tui/widgets/popups/import_modpack/render.rs
expression: terminal.backend()
---
"╭Import Modpack────────────────────────────────────────────╮"
"│Name: Synthetic Pack │"
"│Pack Version: 1.0.0 │"
"│MC Version: 1.20.1 │"
"│Loader: Fabric 0.15.0 │"
"│Mods: 42 files │"
"│Overrides: 3 files │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"╰──────────────────────────────────[h] back [Enter] import╯"
@@ -0,0 +1,18 @@
---
source: src/tui/widgets/popups/import_modpack/render.rs
expression: terminal.backend()
---
"╭Import Modpack────────────────────────────────────────────╮"
"│▶ 1.0.0 1.20.1 fabric │"
"│ 0.9.0 1.20.1 fabric │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"╰──────────────────────[/] search [h] back [Enter] select╯"
@@ -371,4 +371,104 @@ mod tests {
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
// Version step: pre-populate versions as LoadState::Loaded so
// ensure_versions_loaded short-circuits and never spawns a network task.
// the three synthetic versions are marked stable=true so they show with
// show_snapshots=false (the default).
#[test]
fn new_instance_renders_version_step() {
use crate::instance::loader::GameVersion;
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
{
let mut guard = WIZARD_STATE.lock().expect("WIZARD_STATE lock");
*guard = WizardState::default();
guard.step = WizardStep::Version;
guard.versions = LoadState::Loaded(vec![
GameVersion {
id: "1.20.1".into(),
stable: true,
},
GameVersion {
id: "1.19.4".into(),
stable: true,
},
GameVersion {
id: "1.18.2".into(),
stable: true,
},
]);
}
let backend = TestBackend::new(60, 14);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::Popup))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
// LoaderVersion step: needs both versions and loader_versions pre-loaded.
// pick a non-Vanilla loader (loader_idx=2 = Forge) so the step doesn't
// skip itself to Confirm.
#[test]
fn new_instance_renders_loader_version_step() {
use crate::instance::loader::GameVersion;
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
{
let mut guard = WIZARD_STATE.lock().expect("WIZARD_STATE lock");
*guard = WizardState::default();
guard.step = WizardStep::LoaderVersion;
guard.loader_idx = 2; // Forge
guard.versions = LoadState::Loaded(vec![GameVersion {
id: "1.20.1".into(),
stable: true,
}]);
guard.loader_versions = LoadState::Loaded(vec![
"47.2.0".into(),
"47.1.0".into(),
"47.0.50".into(),
]);
}
let backend = TestBackend::new(60, 14);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::Popup))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
// Confirm step: paints a summary, no network, no list. requires
// versions + loader_versions Loaded so selected_*() return Some.
#[test]
fn new_instance_renders_confirm_step() {
use crate::instance::loader::GameVersion;
use tui_prompts::TextState;
let _serial = TEST_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
{
let mut guard = WIZARD_STATE.lock().expect("WIZARD_STATE lock");
*guard = WizardState::default();
guard.step = WizardStep::Confirm;
guard.loader_idx = 1; // Fabric
guard.versions = LoadState::Loaded(vec![GameVersion {
id: "1.20.1".into(),
stable: true,
}]);
guard.loader_versions = LoadState::Loaded(vec!["0.15.0".into()]);
// TextState exposes only constructors; rebuilding with the
// desired initial value is the supported path.
guard.name_state = TextState::new().with_value("MyPack");
}
let backend = TestBackend::new(60, 12);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|f| render(f, f.area(), FocusedArea::Popup))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
}
@@ -0,0 +1,16 @@
---
source: src/tui/widgets/popups/new_instance/render.rs
expression: terminal.backend()
---
"╭New Instance──────────────────────────────────────────────╮"
"│Name: MyPack │"
"│MC: 1.20.1 │"
"│Loader: Fabric │"
"│Loader version: 0.15.0 │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"╰──────────────────────────────────[h] back [Enter] create╯"
@@ -0,0 +1,18 @@
---
source: src/tui/widgets/popups/new_instance/render.rs
expression: terminal.backend()
---
"╭New Instance──────────────────────────────────────────────╮"
"│▶ 47.2.0 │"
"│ 47.1.0 │"
"│ 47.0.50 │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"╰──────────────────────────────────[h] back [Enter] select╯"
@@ -0,0 +1,18 @@
---
source: src/tui/widgets/popups/new_instance/render.rs
expression: terminal.backend()
---
"╭New Instance──────────────────────────────────────────────╮"
"│▶ 1.20.1 │"
"│ 1.19.4 │"
"│ 1.18.2 │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"│ │"
"╰────────────[/] search [s] snap [h] back [Enter] select╯"