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

+16 -5
View File
@@ -27,6 +27,7 @@ pub struct PlannedInstall {
pub provider_aliases: Vec<ProviderProject>,
pub required_dependencies: Vec<ProviderProject>,
pub automatic_dependency: bool,
pub cleanup_eligible: bool,
pub replacement: bool,
}
@@ -300,6 +301,7 @@ fn build_records(
}
record.required_dependencies = item.required_dependencies.clone();
record.automatic_dependency = item.automatic_dependency;
record.cleanup_eligible = item.cleanup_eligible;
return Ok((Some(old_relative), record));
}
let path = staged
@@ -326,6 +328,7 @@ fn build_records(
provider_aliases: item.provider_aliases.clone(),
required_dependencies: item.required_dependencies.clone(),
automatic_dependency: item.automatic_dependency,
cleanup_eligible: item.cleanup_eligible,
},
))
})
@@ -374,6 +377,7 @@ struct Node {
version: VersionInfo,
installed: Option<InstalledMatch>,
automatic_dependency: bool,
cleanup_eligible: bool,
exact: bool,
dependencies: Vec<ProjectKey>,
optional_dependencies: usize,
@@ -428,6 +432,7 @@ pub async fn resolve(
title: root.title,
version: root_version.clone(),
automatic_dependency: false,
cleanup_eligible: false,
exact: true,
installed: root_installed,
dependencies: Vec::new(),
@@ -494,6 +499,7 @@ pub async fn resolve(
version: choice.version.clone(),
installed: choice.installed,
automatic_dependency: choice.automatic_dependency,
cleanup_eligible: choice.cleanup_eligible,
exact,
dependencies: Vec::new(),
optional_dependencies: 0,
@@ -537,6 +543,7 @@ struct ResolvedChoice {
version: VersionInfo,
installed: Option<InstalledMatch>,
automatic_dependency: bool,
cleanup_eligible: bool,
}
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?;
let automatic_dependency = installed
.as_ref()
.is_none_or(|installed| installed.automatic_dependency);
let cleanup_eligible = automatic_dependency && project.is_library_only();
Ok(ResolvedChoice {
title,
title: project.title,
version,
automatic_dependency: installed
.as_ref()
.is_none_or(|installed| installed.automatic_dependency),
automatic_dependency,
cleanup_eligible,
installed,
})
}
@@ -884,6 +894,7 @@ fn planned_install(
})
.collect(),
automatic_dependency: node.automatic_dependency,
cleanup_eligible: node.cleanup_eligible,
replacement,
}
}
+6 -1
View File
@@ -91,6 +91,8 @@ pub struct ContentFileRecord {
pub required_dependencies: Vec<ProviderProject>,
#[serde(default)]
pub automatic_dependency: bool,
#[serde(default)]
pub cleanup_eligible: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -250,7 +252,10 @@ impl ContentManifest {
loop {
let mut found = false;
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;
}
let still_required = self
+3
View File
@@ -332,6 +332,7 @@ fn reconcile_inventory(
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
}
} else if oversized {
tracing::debug!(
@@ -352,6 +353,7 @@ fn reconcile_inventory(
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
}
} else {
ContentFileRecord {
@@ -363,6 +365,7 @@ fn reconcile_inventory(
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
}
};
record.kind = kind;
+1
View File
@@ -350,6 +350,7 @@ fn seed_content_manifest(
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
});
}
let seeded = manifest.files.len();
@@ -15,6 +15,7 @@ struct FakeProvider {
versions: HashMap<String, VersionInfo>,
compatible: HashMap<String, Vec<String>>,
projects: HashMap<String, String>,
categories: HashMap<String, Vec<String>>,
resolved: HashMap<String, ProviderProject>,
fail_download: Option<String>,
}
@@ -72,6 +73,8 @@ impl ContentProvider for FakeProvider {
description: String::new(),
body: String::new(),
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()
.map(|version| (version.project_id.clone(), version.project_id.clone()))
.collect();
let categories = versions
.iter()
.map(|version| (version.project_id.clone(), vec!["library".to_owned()]))
.collect();
FakeProvider {
versions: versions
.into_iter()
@@ -199,6 +206,7 @@ fn provider(versions: Vec<VersionInfo>) -> FakeProvider {
.collect(),
compatible,
projects,
categories,
resolved: HashMap::new(),
fail_download: None,
}
@@ -255,6 +263,43 @@ async fn required_dependencies_prefer_the_newest_stable_release() {
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]
async fn exact_cross_provider_match_replaces_only_the_wrong_version() {
let root_version = version(
@@ -307,6 +352,7 @@ async fn exact_cross_provider_match_replaces_only_the_wrong_version() {
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
}],
};
@@ -429,6 +475,7 @@ async fn installed_incompatible_projects_block_the_plan() {
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
}],
};
@@ -490,6 +537,12 @@ async fn dependency_install_commits_files_and_manifest_together() {
.unwrap()
.automatic_dependency
);
assert!(
manifest
.record(Path::new("mods/library.jar"))
.unwrap()
.cleanup_eligible
);
assert_eq!(
manifest
.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(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
};
let mut manifest = ContentManifest::default();
manifest.upsert(record);
@@ -90,6 +91,7 @@ fn renaming_a_record_preserves_its_resolution() {
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
});
assert!(manifest.rename_record(
@@ -129,6 +131,7 @@ fn managed_record(
provider_aliases: Vec::new(),
required_dependencies,
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()
);
}
+32 -8
View File
@@ -41,6 +41,14 @@ struct Mod {
#[serde(default)]
download_count: u64,
logo: Option<Logo>,
#[serde(default)]
categories: Vec<Category>,
}
#[derive(Debug, Deserialize)]
struct Category {
name: String,
slug: String,
}
#[derive(Debug, Deserialize)]
@@ -283,14 +291,30 @@ pub async fn fetch_project(
),
)
.await?;
Ok(ProjectInfo {
id: project.data.id.to_string(),
slug: project.data.slug,
title: project.data.name,
description: project.data.summary,
body: description.data,
icon_url: project.data.logo.map(|logo| logo.thumbnail_url),
})
Ok(project_info(project.data, description.data))
}
fn project_info(project: Mod, body: String) -> ProjectInfo {
ProjectInfo {
id: project.id.to_string(),
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(
+26
View File
@@ -14,6 +14,32 @@ pub struct ProjectInfo {
pub body: String,
#[serde(default)]
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)]
+18
View File
@@ -40,6 +40,24 @@ fn curseforge_file_maps_to_shared_version() {
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]
async fn curseforge_versions_follow_pagination() {
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]
fn discovery_mod_facets_include_instance_compatibility() {
let facets = discovery_facets(ContentKind::Mod, "1.21.1", ModLoader::Fabric);
+1
View File
@@ -1068,6 +1068,7 @@ impl App {
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
};
crate::instance::ContentManifest::update(&manifest_path, |manifest| {
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(),
required_dependencies,
automatic_dependency,
cleanup_eligible: automatic_dependency,
}
}
@@ -430,6 +431,7 @@ fn provider_conflict_selection_is_persisted() {
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
}],
};
let manifest_path =
@@ -352,6 +352,8 @@ fn project_page_loads_for_the_selected_discovery_entry() {
description: "Short description".to_owned(),
body: "Long **Markdown** description.".to_owned(),
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(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
replacement: false,
}],
optional_dependencies: 0,
@@ -671,6 +674,7 @@ fn installed_labels_follow_exact_manifest_projects() {
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
});
state.refresh_installed_manifest(&manifest, std::path::Path::new("first"));
assert_eq!(
+3
View File
@@ -524,6 +524,7 @@ fn manifest_metadata_keeps_an_embedded_icon_renderer() {
provider_aliases: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
});
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(),
body: String::new(),
icon_url: None,
categories: Vec::new(),
additional_categories: Vec::new(),
})
.unwrap(),
)