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()
);
}