From 5b767cdd832d39816ee4c2dbf94274c0130dd572 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 2 May 2026 17:01:54 +0900 Subject: refactor(registry): route Packagist queries through RepositorySet Replace direct packagist::fetch_package_versions calls in resolver::resolve (seed + transitive loops) and lockfile::generate_lock_file with repo_set.load_packages calls. PackagistRepository now propagates errors instead of swallowing them, so the seed loop's strictness and the transitive loop's local-leniency are both preserved exactly. VCS and inline-package repositories are still preloaded directly into the pool builder for now, with their names tracked in skip lists so we don't double-load them through the trait. Migrating them through RepositorySet is a follow-up - vcs_to_pool_inputs and packagist_to_pool_inputs differ in dev-branch handling that needs to be unified first. All 136 enabled installer fixtures + 114 mozart-registry tests + 541 mozart lib tests remain green; clippy clean. Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/mozart-registry/src/lockfile.rs | 39 ++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'crates/mozart-registry/src/lockfile.rs') diff --git a/crates/mozart-registry/src/lockfile.rs b/crates/mozart-registry/src/lockfile.rs index a99c921..edda3e9 100644 --- a/crates/mozart-registry/src/lockfile.rs +++ b/crates/mozart-registry/src/lockfile.rs @@ -1,5 +1,7 @@ use crate::cache::Cache; -use crate::packagist::{self, PackagistDist, PackagistSource, PackagistVersion}; +use crate::packagist::{PackagistDist, PackagistSource, PackagistVersion}; +use crate::repository::packagist_repo::PackagistRepository; +use crate::repository::{Repository, RepositorySet}; use crate::resolver::ResolvedPackage; use mozart_core::package::{RawPackageData, to_json_pretty}; use serde::{Deserialize, Serialize}; @@ -7,6 +9,18 @@ use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; use std::fs; use std::path::Path; +/// Build a [`RepositorySet`] containing only [`PackagistRepository`]. +/// +/// Used by `generate_lock_file` to fetch full metadata for resolved packages +/// not already covered by inline `type: package` repositories. Step B routes +/// only Packagist queries through the trait; VCS/inline migration is a +/// follow-up. +fn build_packagist_repo_set(repo_cache: &Cache) -> RepositorySet { + let repos: Vec> = + vec![Box::new(PackagistRepository::new(repo_cache.clone()))]; + RepositorySet::new(repos) +} + fn default_stability() -> String { "stable".to_string() } @@ -514,21 +528,28 @@ fn extract_platform_requirements(requirements: &BTreeMap) -> ser /// 3. Computes the content-hash /// 4. Assembles the complete `LockFile` struct pub async fn generate_lock_file(request: &LockFileGenerationRequest) -> anyhow::Result { - // 1. Fetch full metadata for all resolved packages + // 1. Fetch full metadata for all resolved packages. + // + // Inline `type: package` repositories carry full metadata in composer.json + // — short-circuit those before hitting the network. Everything else goes + // through `RepositorySet`, which today contains only Packagist; future + // steps will move VCS / inline through the same set. let mut package_metadata: HashMap = HashMap::new(); + let repo_set = build_packagist_repo_set(&request.repo_cache); for pkg in &request.resolved_packages { - // Inline `type: package` repositories carry full metadata in - // composer.json — use it directly instead of hitting Packagist. if let Some(inline) = request.inline_lookup(&pkg.name, &pkg.version_normalized) { package_metadata.insert(pkg.name.clone(), inline); continue; } - let versions = packagist::fetch_package_versions(&pkg.name, &request.repo_cache).await?; - // Find the exact version matching pkg.version_normalized - let matching = versions + let queries = [crate::repository::PackageQuery { + name: pkg.name.as_str(), + constraint: None, + }]; + let results = repo_set.load_packages(&queries).await?; + let matching = results .into_iter() - .find(|v| v.version_normalized == pkg.version_normalized) + .find(|r| r.version.version_normalized == pkg.version_normalized) .ok_or_else(|| { anyhow::anyhow!( "Could not find version {} for package {} in Packagist response", @@ -536,7 +557,7 @@ pub async fn generate_lock_file(request: &LockFileGenerationRequest) -> anyhow:: pkg.name ) })?; - package_metadata.insert(pkg.name.clone(), matching); + package_metadata.insert(pkg.name.clone(), matching.version); } // 2. Classify dev vs non-dev packages -- cgit v1.3.1