feat(content): manage required mod dependencies

This commit is contained in:
objz committed 2026-07-28 19:38:38 +02:00
1 parent de6defa1ff
commit 3b26581af5
27 files changed
+2487 -75

No files matched your search

+153 -1
View File
@@ -1,7 +1,11 @@
use crossterm::event::{KeyCode, MouseEventKind};
use std::path::{Path, PathBuf};
use super::harness::UiHarness;
use crate::instance::ProviderProject;
use crate::instance::content::entry::ContentEntry;
use crate::instance::{
ContentFileRecord, ContentKind, ContentManifest, FileFingerprint, ProviderProject, Resolution,
};
use crate::net::modrinth::DiscoveryProject;
use crate::tui::{
app::{FocusedArea, ProviderConflictState},
@@ -160,6 +164,151 @@ fn confirmed_screenshot_delete_removes_state_and_file() {
assert!(!path.exists());
}
fn managed_mod_record(
path: &str,
project_id: &str,
automatic_dependency: bool,
required_dependencies: Vec<ProviderProject>,
) -> ContentFileRecord {
ContentFileRecord {
relative_path: PathBuf::from(path),
kind: ContentKind::Mod,
enabled: true,
fingerprint: FileFingerprint {
size: 1,
modified_ns: 1,
hashes: Default::default(),
},
resolution: Resolution::Resolved {
project: ProviderProject {
provider: "modrinth".to_owned(),
project_id: project_id.to_owned(),
version_id: format!("{project_id}-version"),
},
},
provider_aliases: Vec::new(),
required_dependencies,
automatic_dependency,
}
}
fn content_entry(name: &str, path: PathBuf) -> ContentEntry {
ContentEntry {
file_stem: name.to_owned(),
name: name.to_owned(),
source_slug: None,
installed_path: Some(path.clone()),
provider_project: None,
title_suffix: None,
footer_label: None,
description: String::new(),
enabled: true,
icon_bytes: None,
provider_icon: false,
provider_description: false,
path,
icon_lines: None,
}
}
#[test]
fn deleting_a_mod_offers_its_unused_dependency_chain() {
let mut ui = UiHarness::new();
ui.add_instance("Dependencies");
let minecraft = ui
.instance_path("Dependencies")
.join(crate::storage::MINECRAFT_DIR_NAME);
let root_path = minecraft.join("mods/root.jar");
let library_path = minecraft.join("mods/library.jar");
std::fs::create_dir_all(root_path.parent().unwrap()).unwrap();
std::fs::write(&root_path, b"r").unwrap();
std::fs::write(&library_path, b"l").unwrap();
let dependency = ProviderProject {
provider: "modrinth".to_owned(),
project_id: "library".to_owned(),
version_id: "library-version".to_owned(),
};
ContentManifest {
version: 1,
files: vec![
managed_mod_record("mods/root.jar", "root", false, vec![dependency]),
managed_mod_record("mods/library.jar", "library", true, Vec::new()),
],
}
.save(&crate::storage::InstancePaths::new(ui.instance_path("Dependencies")).content_manifest())
.unwrap();
ui.app.mods_state.entries = vec![content_entry("Root", root_path.clone())];
ui.app.mods_state.list_state.selected = Some(0);
ui.app.focused = FocusedArea::Content;
ui.app.content_tab = ContentTab::Mods;
ui.key(KeyCode::Char('d'));
ui.key(KeyCode::Enter);
assert!(!root_path.exists());
assert!(library_path.exists());
assert!(matches!(
confirm::pending_target(),
Some(confirm::ConfirmTarget::OrphanDependencies { paths })
if paths == vec![library_path.clone()]
));
assert_eq!(ui.app.focused, FocusedArea::ConfirmDelete);
ui.key(KeyCode::Enter);
assert!(!library_path.exists());
assert_eq!(ui.app.focused, FocusedArea::Content);
let manifest = ContentManifest::load(
&crate::storage::InstancePaths::new(ui.instance_path("Dependencies")).content_manifest(),
)
.unwrap();
assert!(manifest.files.is_empty());
}
#[test]
fn deleting_a_required_library_warns_but_can_continue() {
let mut ui = UiHarness::new();
ui.add_instance("Required");
let minecraft = ui
.instance_path("Required")
.join(crate::storage::MINECRAFT_DIR_NAME);
let library_path = minecraft.join("mods/library.jar");
std::fs::create_dir_all(library_path.parent().unwrap()).unwrap();
std::fs::write(&library_path, b"l").unwrap();
ContentManifest {
version: 1,
files: vec![
managed_mod_record(
"mods/root.jar",
"root",
false,
vec![ProviderProject {
provider: "modrinth".to_owned(),
project_id: "library".to_owned(),
version_id: "library-version".to_owned(),
}],
),
managed_mod_record("mods/library.jar", "library", true, Vec::new()),
],
}
.save(&crate::storage::InstancePaths::new(ui.instance_path("Required")).content_manifest())
.unwrap();
ui.app.mods_state.entries = vec![content_entry("Library", library_path.clone())];
ui.app.mods_state.list_state.selected = Some(0);
ui.app.focused = FocusedArea::Content;
ui.app.content_tab = ContentTab::Mods;
ui.key(KeyCode::Char('d'));
assert!(matches!(
confirm::pending_target(),
Some(confirm::ConfirmTarget::Content { dependents, .. })
if dependents == vec!["root"]
));
ui.key(KeyCode::Enter);
assert!(!Path::new(&library_path).exists());
}
#[test]
fn confirmed_account_delete_updates_the_account_panel() {
let mut ui = UiHarness::new();
@@ -278,6 +427,9 @@ fn provider_conflict_selection_is_persisted() {
resolution: crate::instance::Resolution::Ambiguous {
candidates: candidates.clone(),
},
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
}],
};
let manifest_path =
+15
View File
@@ -36,6 +36,21 @@ fn instance_delete_confirmation_renders_the_complete_frame() {
insta::assert_snapshot!(ui.screen());
}
#[test]
fn orphan_dependency_confirmation_wraps_its_complete_message() {
let mut ui = UiHarness::new();
crate::tui::widgets::popups::confirm::set_pending_orphan_dependencies(vec![
"mods/sodium-fabric-0.9.1+mc26.2.jar".into(),
]);
ui.app.focused = crate::tui::app::FocusedArea::ConfirmDelete;
ui.draw();
let screen = ui.screen();
assert!(screen.contains("longer required"));
assert!(screen.contains("sodium-fabric-0.9.1+mc26.2.jar"));
}
#[test]
fn provider_conflict_renders_the_complete_frame() {
let mut ui = UiHarness::new();
@@ -52,6 +52,8 @@ fn version(id: &str) -> VersionInfo {
version_number: id.to_owned(),
game_versions: vec!["1.21.1".to_owned()],
loaders: vec!["fabric".to_owned()],
version_type: crate::net::modrinth::VersionType::Release,
dependencies: Vec::new(),
date_published: "2026-01-02T12:00:00Z".to_owned(),
files: Vec::new(),
}
@@ -478,6 +480,64 @@ fn confirmation_can_return_to_version_selection() {
assert!(state.version_popup.is_some());
}
#[test]
fn dependency_resolution_opens_the_existing_confirmation() {
let project = DiscoveryProject {
id: "project".to_owned(),
slug: "project".to_owned(),
title: "Project".to_owned(),
description: String::new(),
downloads: 0,
icon_url: None,
icon_bytes: None,
};
let mut state = DiscoveryState::new(ContentKind::Mod);
state.list.entries.push(project_entry(project, None));
state.list.list_state.selected = Some(0);
let versions = state.begin_versions().unwrap();
DiscoveryState::push_action_result(
&versions.pending,
DiscoveryActionResult::Versions {
request_id: versions.request_id,
project_id: versions.project_id,
result: Ok(vec![version("1.0.0")]),
},
);
state.drain_pending();
let request = state.begin_dependency_resolution().unwrap();
assert!(state.version_popup.as_ref().unwrap().loading);
let root_version = request.root.version.clone();
DiscoveryState::push_action_result(
&request.pending,
DiscoveryActionResult::Dependencies {
request_id: request.request_id,
project_id: request.project_id,
result: Ok(crate::instance::content::dependencies::DependencyPlan {
items: vec![crate::instance::content::dependencies::PlannedInstall {
provider: "modrinth".to_owned(),
project_id: "project".to_owned(),
title: "Project".to_owned(),
version: root_version,
installed_path: None,
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
replacement: false,
}],
optional_dependencies: 0,
}),
},
);
state.drain_pending();
let popup = state.version_popup.as_ref().unwrap();
assert!(popup.confirming);
assert!(!popup.loading);
assert!(popup.dependency_plan.is_some());
assert!(state.begin_install().unwrap().dependency_plan.is_some());
}
#[test]
fn discovery_delete_only_clears_the_matching_installed_badge() {
let first_path = PathBuf::from("mods/first.jar");
@@ -559,6 +619,7 @@ fn successful_install_marks_the_project_and_closes_the_popup() {
path: PathBuf::from("mods/project.jar"),
replaced: false,
skipped: false,
orphaned_dependencies: Vec::new(),
}),
},
);
@@ -607,6 +668,9 @@ fn installed_labels_follow_exact_manifest_projects() {
version_id: "version".to_owned(),
},
},
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
});
state.refresh_installed_manifest(&manifest, std::path::Path::new("first"));
assert_eq!(
+3
View File
@@ -521,6 +521,9 @@ fn manifest_metadata_keeps_an_embedded_icon_renderer() {
version_id: "version".to_owned(),
},
},
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
});
state.apply_manifest(&manifest, &minecraft_dir, crate::instance::ContentKind::Mod);
+4 -2
View File
@@ -37,6 +37,8 @@ fn discovery_version_rows_only_show_the_version_number() {
version_number: "3.2.4-fabric-26.1".to_owned(),
game_versions: vec![],
loaders: vec![],
version_type: crate::net::modrinth::VersionType::Release,
dependencies: Vec::new(),
date_published: String::new(),
files: vec![],
};
@@ -46,8 +48,8 @@ fn discovery_version_rows_only_show_the_version_number() {
#[test]
fn discovery_confirmation_popup_fits_its_summary() {
assert_eq!(version_popup_height(false), VERSION_POPUP_HEIGHT);
assert_eq!(version_popup_height(true), 6);
assert_eq!(version_popup_height(false, None), VERSION_POPUP_HEIGHT);
assert_eq!(version_popup_height(true, None), 6);
}
#[test]
@@ -102,6 +102,8 @@ fn import_modpack_renders_version_step() {
version_number: "1.0.0".into(),
game_versions: vec!["1.20.1".into()],
loaders: vec!["fabric".into()],
version_type: crate::net::modrinth::VersionType::Release,
dependencies: Vec::new(),
date_published: String::new(),
files: vec![],
},
@@ -112,6 +114,8 @@ fn import_modpack_renders_version_step() {
version_number: "0.9.0".into(),
game_versions: vec!["1.20.1".into()],
loaders: vec!["fabric".into()],
version_type: crate::net::modrinth::VersionType::Release,
dependencies: Vec::new(),
date_published: String::new(),
files: vec![],
},
@@ -108,6 +108,8 @@ fn discovered_modpack_version_skips_content_install_confirmation() {
version_number: "1.0".to_owned(),
game_versions: vec!["1.21.1".to_owned()],
loaders: vec!["fabric".to_owned()],
version_type: crate::net::modrinth::VersionType::Release,
dependencies: Vec::new(),
date_published: String::new(),
files: Vec::new(),
}]),
+1
View File
@@ -15,6 +15,7 @@ fn keybind_wrapping_uses_terminal_width_for_unicode_keys() {
fn word_wrap_size_uses_terminal_width_for_unicode_text() {
assert_eq!(word_wrap_size("Übergröße", 20), (9, 1));
assert_eq!(word_wrap_size("世界 test", 6), (4, 2));
assert_eq!(word_wrap_size("one\n\ntwo", 20), (3, 3));
}
#[test]