diff options
| -rw-r--r-- | crates/mozart-registry/src/inline_package.rs | 22 | ||||
| -rw-r--r-- | crates/mozart/tests/installer.rs | 11 |
2 files changed, 24 insertions, 9 deletions
diff --git a/crates/mozart-registry/src/inline_package.rs b/crates/mozart-registry/src/inline_package.rs index e10cd2b..bad00fb 100644 --- a/crates/mozart-registry/src/inline_package.rs +++ b/crates/mozart-registry/src/inline_package.rs @@ -7,6 +7,7 @@ use crate::packagist::PackagistVersion; use mozart_core::package::RawRepository; +use std::collections::HashSet; /// One package extracted from a `type: package` repository. pub struct InlinePackage { @@ -20,8 +21,14 @@ pub struct InlinePackage { /// objects. Entries that fail to parse (missing `name`/`version`, etc.) are /// silently skipped so the rest of the repositories list still applies — /// matching Composer's lenient PackageRepository constructor. +/// +/// Repositories are processed in declaration order. Once any repository +/// authoritatively answers for a package name, lower-priority `type: package` +/// repositories that list the same name are skipped — mirroring Composer's +/// first-repo-wins priority via `RepositorySet::findPackages`. pub fn collect_inline_packages(repositories: &[RawRepository]) -> Vec<InlinePackage> { let mut packages = Vec::new(); + let mut claimed: HashSet<String> = HashSet::new(); for repo in repositories { if repo.repo_type != "package" { continue; @@ -30,21 +37,32 @@ pub fn collect_inline_packages(repositories: &[RawRepository]) -> Vec<InlinePack continue; }; + let mut from_this_repo: Vec<InlinePackage> = Vec::new(); match value { serde_json::Value::Array(arr) => { for entry in arr { if let Some(pkg) = parse_inline_package(entry) { - packages.push(pkg); + from_this_repo.push(pkg); } } } serde_json::Value::Object(_) => { if let Some(pkg) = parse_inline_package(value) { - packages.push(pkg); + from_this_repo.push(pkg); } } _ => {} } + + let mut names_this_repo: HashSet<String> = HashSet::new(); + for pkg in from_this_repo { + if claimed.contains(&pkg.name) { + continue; + } + names_this_repo.insert(pkg.name.clone()); + packages.push(pkg); + } + claimed.extend(names_this_repo); } packages } diff --git a/crates/mozart/tests/installer.rs b/crates/mozart/tests/installer.rs index 6c0291b..7ba53a8 100644 --- a/crates/mozart/tests/installer.rs +++ b/crates/mozart/tests/installer.rs @@ -275,7 +275,7 @@ installer_fixture!(install_ignore_platform_package_requirements); installer_fixture!(install_missing_alias_from_lock, ignore); installer_fixture!(install_overridden_platform_packages, ignore); installer_fixture!(install_package_and_its_provider_skips_original); -installer_fixture!(install_prefers_repos_over_package_versions, ignore); +installer_fixture!(install_prefers_repos_over_package_versions); installer_fixture!(install_reference); installer_fixture!(install_security_advisory_matching_dependency); installer_fixture!(install_self_from_root); @@ -344,9 +344,9 @@ installer_fixture!( ); installer_fixture!(replacer_satisfies_its_own_requirement); installer_fixture!(repositories_priorities, ignore); -installer_fixture!(repositories_priorities2, ignore); +installer_fixture!(repositories_priorities2); installer_fixture!(repositories_priorities3, ignore); -installer_fixture!(repositories_priorities4, ignore); +installer_fixture!(repositories_priorities4); installer_fixture!(repositories_priorities5, ignore); installer_fixture!(root_alias_change_with_circular_dep, ignore); installer_fixture!(root_alias_gets_loaded_for_locked_pkgs); @@ -413,10 +413,7 @@ installer_fixture!(update_no_install); installer_fixture!(update_package_present_in_lock_but_not_at_all_in_remote); installer_fixture!(update_package_present_in_lock_but_not_in_remote); installer_fixture!(update_package_present_in_lock_but_not_in_remote_due_to_min_stability); -installer_fixture!( - update_package_present_in_lower_repo_prio_but_not_main_due_to_min_stability, - ignore -); +installer_fixture!(update_package_present_in_lower_repo_prio_but_not_main_due_to_min_stability); installer_fixture!(update_picks_up_change_of_vcs_type, ignore); installer_fixture!(update_prefer_lowest_stable); installer_fixture!(update_reference, ignore); |
