aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-registry/src/repository/vcs_repo.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-02 16:53:41 +0900
committernsfisis <nsfisis@gmail.com>2026-05-02 16:53:41 +0900
commitc1733d88510b7afb88f7a17849de514365e42c84 (patch)
tree57f9eb854cb226059df90d190626e090ae07d639 /crates/mozart-registry/src/repository/vcs_repo.rs
parent82501a36a0fa6725d656742da42c860e75a89b89 (diff)
downloadphp-mozart-c1733d88510b7afb88f7a17849de514365e42c84.tar.gz
php-mozart-c1733d88510b7afb88f7a17849de514365e42c84.tar.zst
php-mozart-c1733d88510b7afb88f7a17849de514365e42c84.zip
refactor(registry): introduce Repository and InstallerExecutor traits
Sets up DI scaffolding for in-process installer E2E tests, mirroring how Composer's PHPUnit suite swaps Packagist (FactoryMock) and the install manager (InstallationManagerMock) without touching the network or filesystem. Additions: - Repository trait + RepositorySet (Composer's RepositoryInterface analog), with PackagistRepository, InlinePackageRepository, VcsRepository impls. - InstallerExecutor trait (Composer's InstallationManager analog) with FilesystemExecutor extracted from install_from_lock. install_from_lock now delegates per-package install/uninstall verbs to FilesystemExecutor; console output orchestration stays in the caller so existing --EXPECT-OUTPUT-shape assertions remain comparable. No behavior change - all 136 enabled installer fixtures still pass. Also tightens the installer_fixture\! ignore form to a single token (installer_fixture\!(name, ignore)) for readability. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart-registry/src/repository/vcs_repo.rs')
-rw-r--r--crates/mozart-registry/src/repository/vcs_repo.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/crates/mozart-registry/src/repository/vcs_repo.rs b/crates/mozart-registry/src/repository/vcs_repo.rs
new file mode 100644
index 0000000..fff5f6f
--- /dev/null
+++ b/crates/mozart-registry/src/repository/vcs_repo.rs
@@ -0,0 +1,63 @@
+//! [`Repository`] for VCS-type repositories.
+//!
+//! Wraps [`crate::vcs_bridge::scan_vcs_repositories`] + [`crate::vcs_bridge::vcs_to_packagist_version`].
+//! Scanning is expensive (clones / fetches), so we do it once at construction
+//! and serve subsequent queries from the in-memory cache. Mirrors
+//! `Composer\Repository\Vcs\VcsRepository`'s lazy-then-memoized behavior.
+
+use super::{LoadResult, NamedPackagistVersion, PackageQuery, Repository};
+use crate::packagist::PackagistVersion;
+use crate::vcs_bridge::{scan_vcs_repositories, vcs_to_packagist_version};
+use mozart_core::package::RawRepository;
+
+pub struct VcsRepository {
+ id: String,
+ versions: Vec<(String, PackagistVersion)>,
+}
+
+impl VcsRepository {
+ /// Scan every VCS-type entry in `repositories` and cache the resulting
+ /// versions. Non-VCS entries are ignored. This performs network I/O.
+ pub async fn from_repositories(repositories: &[RawRepository]) -> Self {
+ let scanned = scan_vcs_repositories(repositories).await;
+ let versions = scanned
+ .iter()
+ .map(|v| (v.name.clone(), vcs_to_packagist_version(v)))
+ .collect();
+ Self {
+ id: "vcs".to_string(),
+ versions,
+ }
+ }
+
+ pub fn version_count(&self) -> usize {
+ self.versions.len()
+ }
+}
+
+#[async_trait::async_trait]
+impl Repository for VcsRepository {
+ fn id(&self) -> &str {
+ &self.id
+ }
+
+ async fn load_packages(&self, queries: &[PackageQuery<'_>]) -> anyhow::Result<LoadResult> {
+ let mut result = LoadResult::default();
+ for query in queries {
+ let mut found_any = false;
+ for (name, version) in &self.versions {
+ if name == query.name {
+ found_any = true;
+ result.packages.push(NamedPackagistVersion {
+ name: name.clone(),
+ version: version.clone(),
+ });
+ }
+ }
+ if found_any {
+ result.names_found.push(query.name.to_string());
+ }
+ }
+ Ok(result)
+ }
+}