fix(content): only clean up library dependencies

This commit is contained in:
objz committed 2026-07-28 20:37:10 +02:00
1 parent 8f920080d1
commit aefc4535e1
14 files changed
+209 -14

No files matched your search

+17 -6
View File
@@ -27,6 +27,7 @@ pub struct PlannedInstall {
pub provider_aliases: Vec<ProviderProject>, pub provider_aliases: Vec<ProviderProject>,
pub required_dependencies: Vec<ProviderProject>, pub required_dependencies: Vec<ProviderProject>,
pub automatic_dependency: bool, pub automatic_dependency: bool,
pub cleanup_eligible: bool,
pub replacement: bool, pub replacement: bool,
} }
@@ -300,6 +301,7 @@ fn build_records(
} }
record.required_dependencies = item.required_dependencies.clone(); record.required_dependencies = item.required_dependencies.clone();
record.automatic_dependency = item.automatic_dependency; record.automatic_dependency = item.automatic_dependency;
record.cleanup_eligible = item.cleanup_eligible;
return Ok((Some(old_relative), record)); return Ok((Some(old_relative), record));
} }
let path = staged let path = staged
@@ -326,6 +328,7 @@ fn build_records(
provider_aliases: item.provider_aliases.clone(), provider_aliases: item.provider_aliases.clone(),
required_dependencies: item.required_dependencies.clone(), required_dependencies: item.required_dependencies.clone(),
automatic_dependency: item.automatic_dependency, automatic_dependency: item.automatic_dependency,
cleanup_eligible: item.cleanup_eligible,
}, },
)) ))
}) })
@@ -374,6 +377,7 @@ struct Node {
version: VersionInfo, version: VersionInfo,
installed: Option<InstalledMatch>, installed: Option<InstalledMatch>,
automatic_dependency: bool, automatic_dependency: bool,
cleanup_eligible: bool,
exact: bool, exact: bool,
dependencies: Vec<ProjectKey>, dependencies: Vec<ProjectKey>,
optional_dependencies: usize, optional_dependencies: usize,
@@ -428,6 +432,7 @@ pub async fn resolve(
title: root.title, title: root.title,
version: root_version.clone(), version: root_version.clone(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
exact: true, exact: true,
installed: root_installed, installed: root_installed,
dependencies: Vec::new(), dependencies: Vec::new(),
@@ -494,6 +499,7 @@ pub async fn resolve(
version: choice.version.clone(), version: choice.version.clone(),
installed: choice.installed, installed: choice.installed,
automatic_dependency: choice.automatic_dependency, automatic_dependency: choice.automatic_dependency,
cleanup_eligible: choice.cleanup_eligible,
exact, exact,
dependencies: Vec::new(), dependencies: Vec::new(),
optional_dependencies: 0, optional_dependencies: 0,
@@ -537,6 +543,7 @@ struct ResolvedChoice {
version: VersionInfo, version: VersionInfo,
installed: Option<InstalledMatch>, installed: Option<InstalledMatch>,
automatic_dependency: bool, automatic_dependency: bool,
cleanup_eligible: bool,
} }
async fn resolve_requirement( async fn resolve_requirement(
@@ -586,13 +593,16 @@ async fn resolve_requirement(
)) ))
})? })?
}; };
let title = provider.project(&project_id).await?.title; let project = provider.project(&project_id).await?;
Ok(ResolvedChoice { let automatic_dependency = installed
title,
version,
automatic_dependency: installed
.as_ref() .as_ref()
.is_none_or(|installed| installed.automatic_dependency), .is_none_or(|installed| installed.automatic_dependency);
let cleanup_eligible = automatic_dependency && project.is_library_only();
Ok(ResolvedChoice {
title: project.title,
version,
automatic_dependency,
cleanup_eligible,
installed, installed,
}) })
} }
@@ -884,6 +894,7 @@ fn planned_install(
}) })
.collect(), .collect(),
automatic_dependency: node.automatic_dependency, automatic_dependency: node.automatic_dependency,
cleanup_eligible: node.cleanup_eligible,
replacement, replacement,
} }
} }
+6 -1
View File
@@ -91,6 +91,8 @@ pub struct ContentFileRecord {
pub required_dependencies: Vec<ProviderProject>, pub required_dependencies: Vec<ProviderProject>,
#[serde(default)] #[serde(default)]
pub automatic_dependency: bool, pub automatic_dependency: bool,
#[serde(default)]
pub cleanup_eligible: bool,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@@ -250,7 +252,10 @@ impl ContentManifest {
loop { loop {
let mut found = false; let mut found = false;
for candidate in &self.files { for candidate in &self.files {
if !candidate.automatic_dependency || removed.contains(&candidate.relative_path) { if !candidate.automatic_dependency
|| !candidate.cleanup_eligible
|| removed.contains(&candidate.relative_path)
{
continue; continue;
} }
let still_required = self let still_required = self
+3
View File
@@ -332,6 +332,7 @@ fn reconcile_inventory(
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
} }
} else if oversized { } else if oversized {
tracing::debug!( tracing::debug!(
@@ -352,6 +353,7 @@ fn reconcile_inventory(
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
} }
} else { } else {
ContentFileRecord { ContentFileRecord {
@@ -363,6 +365,7 @@ fn reconcile_inventory(
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
} }
}; };
record.kind = kind; record.kind = kind;
+1
View File
@@ -350,6 +350,7 @@ fn seed_content_manifest(
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
}); });
} }
let seeded = manifest.files.len(); let seeded = manifest.files.len();
@@ -15,6 +15,7 @@ struct FakeProvider {
versions: HashMap<String, VersionInfo>, versions: HashMap<String, VersionInfo>,
compatible: HashMap<String, Vec<String>>, compatible: HashMap<String, Vec<String>>,
projects: HashMap<String, String>, projects: HashMap<String, String>,
categories: HashMap<String, Vec<String>>,
resolved: HashMap<String, ProviderProject>, resolved: HashMap<String, ProviderProject>,
fail_download: Option<String>, fail_download: Option<String>,
} }
@@ -72,6 +73,8 @@ impl ContentProvider for FakeProvider {
description: String::new(), description: String::new(),
body: String::new(), body: String::new(),
icon_url: None, icon_url: None,
categories: self.categories.get(project_id).cloned().unwrap_or_default(),
additional_categories: Vec::new(),
}) })
} }
@@ -192,6 +195,10 @@ fn provider(versions: Vec<VersionInfo>) -> FakeProvider {
.iter() .iter()
.map(|version| (version.project_id.clone(), version.project_id.clone())) .map(|version| (version.project_id.clone(), version.project_id.clone()))
.collect(); .collect();
let categories = versions
.iter()
.map(|version| (version.project_id.clone(), vec!["library".to_owned()]))
.collect();
FakeProvider { FakeProvider {
versions: versions versions: versions
.into_iter() .into_iter()
@@ -199,6 +206,7 @@ fn provider(versions: Vec<VersionInfo>) -> FakeProvider {
.collect(), .collect(),
compatible, compatible,
projects, projects,
categories,
resolved: HashMap::new(), resolved: HashMap::new(),
fail_download: None, fail_download: None,
} }
@@ -255,6 +263,43 @@ async fn required_dependencies_prefer_the_newest_stable_release() {
assert_eq!(plan.optional_dependencies, 1); assert_eq!(plan.optional_dependencies, 1);
} }
#[tokio::test]
async fn functional_mod_dependencies_are_not_cleanup_eligible() {
let root_version = version(
"root",
"root",
VersionType::Release,
"2026-01-01",
vec![dependency("sodium", DependencyType::Required)],
);
let sodium = version(
"sodium",
"sodium",
VersionType::Release,
"2026-01-01",
Vec::new(),
);
let mut fake = provider(vec![root_version.clone(), sodium]);
fake.categories.insert(
"sodium".to_owned(),
vec!["library".to_owned(), "optimization".to_owned()],
);
let registry = fake.registry();
let plan = resolve(
&registry,
&ContentManifest::default(),
Path::new("/minecraft"),
&instance(),
root(root_version),
)
.await
.unwrap();
assert!(plan.items[1].automatic_dependency);
assert!(!plan.items[1].cleanup_eligible);
}
#[tokio::test] #[tokio::test]
async fn exact_cross_provider_match_replaces_only_the_wrong_version() { async fn exact_cross_provider_match_replaces_only_the_wrong_version() {
let root_version = version( let root_version = version(
@@ -307,6 +352,7 @@ async fn exact_cross_provider_match_replaces_only_the_wrong_version() {
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
}], }],
}; };
@@ -429,6 +475,7 @@ async fn installed_incompatible_projects_block_the_plan() {
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
}], }],
}; };
@@ -490,6 +537,12 @@ async fn dependency_install_commits_files_and_manifest_together() {
.unwrap() .unwrap()
.automatic_dependency .automatic_dependency
); );
assert!(
manifest
.record(Path::new("mods/library.jar"))
.unwrap()
.cleanup_eligible
);
assert_eq!( assert_eq!(
manifest manifest
.record(Path::new("mods/root.jar")) .record(Path::new("mods/root.jar"))
+22
View File
@@ -38,6 +38,7 @@ fn manifest_round_trip_and_lookup_are_exact() {
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
}; };
let mut manifest = ContentManifest::default(); let mut manifest = ContentManifest::default();
manifest.upsert(record); manifest.upsert(record);
@@ -90,6 +91,7 @@ fn renaming_a_record_preserves_its_resolution() {
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
}); });
assert!(manifest.rename_record( assert!(manifest.rename_record(
@@ -129,6 +131,7 @@ fn managed_record(
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies, required_dependencies,
automatic_dependency, automatic_dependency,
cleanup_eligible: automatic_dependency,
} }
} }
@@ -211,3 +214,22 @@ fn orphan_cleanup_follows_automatic_dependency_chains() {
] ]
); );
} }
#[test]
fn orphan_cleanup_keeps_automatic_non_library_dependencies() {
let mut dependency_record = managed_record("mods/sodium.jar", "sodium", true, Vec::new());
dependency_record.cleanup_eligible = false;
let manifest = ContentManifest {
version: 1,
files: vec![
managed_record("mods/root.jar", "root", false, vec![dependency("sodium")]),
dependency_record,
],
};
assert!(
manifest
.orphaned_dependencies_after_removing(Path::new("mods/root.jar"))
.is_empty()
);
}
+31 -7
View File
@@ -41,6 +41,14 @@ struct Mod {
#[serde(default)] #[serde(default)]
download_count: u64, download_count: u64,
logo: Option<Logo>, logo: Option<Logo>,
#[serde(default)]
categories: Vec<Category>,
}
#[derive(Debug, Deserialize)]
struct Category {
name: String,
slug: String,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@@ -283,14 +291,30 @@ pub async fn fetch_project(
), ),
) )
.await?; .await?;
Ok(ProjectInfo { Ok(project_info(project.data, description.data))
id: project.data.id.to_string(), }
slug: project.data.slug,
title: project.data.name, fn project_info(project: Mod, body: String) -> ProjectInfo {
description: project.data.summary, ProjectInfo {
body: description.data, id: project.id.to_string(),
icon_url: project.data.logo.map(|logo| logo.thumbnail_url), slug: project.slug,
title: project.name,
description: project.summary,
body,
icon_url: project.logo.map(|logo| logo.thumbnail_url),
categories: project
.categories
.into_iter()
.map(|category| {
if category.slug.is_empty() {
category.name
} else {
category.slug
}
}) })
.collect(),
additional_categories: Vec::new(),
}
} }
pub async fn fetch_versions( pub async fn fetch_versions(
+26
View File
@@ -14,6 +14,32 @@ pub struct ProjectInfo {
pub body: String, pub body: String,
#[serde(default)] #[serde(default)]
pub icon_url: Option<String>, pub icon_url: Option<String>,
#[serde(default)]
pub categories: Vec<String>,
#[serde(default)]
pub additional_categories: Vec<String>,
}
impl ProjectInfo {
pub fn is_library_only(&self) -> bool {
let mut categories = self
.categories
.iter()
.chain(self.additional_categories.iter())
.peekable();
categories.peek().is_some()
&& categories.all(|category| {
matches!(
category
.chars()
.filter(|character| character.is_alphanumeric())
.flat_map(char::to_lowercase)
.collect::<String>()
.as_str(),
"library" | "libraries" | "apiandlibrary" | "libraryapi"
)
})
}
} }
#[derive(Debug, Clone, Deserialize, serde::Serialize)] #[derive(Debug, Clone, Deserialize, serde::Serialize)]
+18
View File
@@ -40,6 +40,24 @@ fn curseforge_file_maps_to_shared_version() {
assert_eq!(version.files[0].hashes["sha1"], "abc"); assert_eq!(version.files[0].hashes["sha1"], "abc");
} }
#[test]
fn curseforge_library_category_maps_to_cleanup_metadata() {
let project: Mod = serde_json::from_str(
r#"{
"id": 7,
"name": "Library",
"slug": "library",
"categories": [{
"name": "API and Library",
"slug": "library-api"
}]
}"#,
)
.unwrap();
assert!(project_info(project, String::new()).is_library_only());
}
#[tokio::test] #[tokio::test]
async fn curseforge_versions_follow_pagination() { async fn curseforge_versions_follow_pagination() {
use wiremock::matchers::{method, path, query_param}; use wiremock::matchers::{method, path, query_param};
+22
View File
@@ -47,6 +47,28 @@ fn version_dependencies_and_release_type_are_deserialized() {
); );
} }
#[test]
fn only_exclusively_library_categorized_projects_are_cleanup_eligible() {
let project = |categories: &[&str]| ProjectInfo {
id: "project".to_owned(),
slug: "project".to_owned(),
title: "Project".to_owned(),
description: String::new(),
body: String::new(),
icon_url: None,
categories: categories
.iter()
.map(|category| (*category).to_owned())
.collect(),
additional_categories: Vec::new(),
};
assert!(project(&["library"]).is_library_only());
assert!(project(&["api-and-library"]).is_library_only());
assert!(!project(&[]).is_library_only());
assert!(!project(&["library", "utility"]).is_library_only());
}
#[test] #[test]
fn discovery_mod_facets_include_instance_compatibility() { fn discovery_mod_facets_include_instance_compatibility() {
let facets = discovery_facets(ContentKind::Mod, "1.21.1", ModLoader::Fabric); let facets = discovery_facets(ContentKind::Mod, "1.21.1", ModLoader::Fabric);
+1
View File
@@ -1068,6 +1068,7 @@ impl App {
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
}; };
crate::instance::ContentManifest::update(&manifest_path, |manifest| { crate::instance::ContentManifest::update(&manifest_path, |manifest| {
if let Some(old_path) = request.installed_path.as_ref() if let Some(old_path) = request.installed_path.as_ref()
+2
View File
@@ -189,6 +189,7 @@ fn managed_mod_record(
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies, required_dependencies,
automatic_dependency, automatic_dependency,
cleanup_eligible: automatic_dependency,
} }
} }
@@ -430,6 +431,7 @@ fn provider_conflict_selection_is_persisted() {
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
}], }],
}; };
let manifest_path = let manifest_path =
@@ -352,6 +352,8 @@ fn project_page_loads_for_the_selected_discovery_entry() {
description: "Short description".to_owned(), description: "Short description".to_owned(),
body: "Long **Markdown** description.".to_owned(), body: "Long **Markdown** description.".to_owned(),
icon_url: None, icon_url: None,
categories: Vec::new(),
additional_categories: Vec::new(),
}), }),
}, },
); );
@@ -522,6 +524,7 @@ fn dependency_resolution_opens_the_existing_confirmation() {
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
replacement: false, replacement: false,
}], }],
optional_dependencies: 0, optional_dependencies: 0,
@@ -671,6 +674,7 @@ fn installed_labels_follow_exact_manifest_projects() {
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
}); });
state.refresh_installed_manifest(&manifest, std::path::Path::new("first")); state.refresh_installed_manifest(&manifest, std::path::Path::new("first"));
assert_eq!( assert_eq!(
+3
View File
@@ -524,6 +524,7 @@ fn manifest_metadata_keeps_an_embedded_icon_renderer() {
provider_aliases: Vec::new(), provider_aliases: Vec::new(),
required_dependencies: Vec::new(), required_dependencies: Vec::new(),
automatic_dependency: false, automatic_dependency: false,
cleanup_eligible: false,
}); });
state.apply_manifest(&manifest, &minecraft_dir, crate::instance::ContentKind::Mod); state.apply_manifest(&manifest, &minecraft_dir, crate::instance::ContentKind::Mod);
@@ -583,6 +584,8 @@ async fn provider_metadata_loads_from_cache_without_network() {
description: "Cached description".to_owned(), description: "Cached description".to_owned(),
body: String::new(), body: String::new(),
icon_url: None, icon_url: None,
categories: Vec::new(),
additional_categories: Vec::new(),
}) })
.unwrap(), .unwrap(),
) )