From b5d6d91054b9ceef95aef0819bb5c4ef7db1abdd Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 2 Aug 2026 08:42:55 +0900 Subject: fix(repository): run lazy initialization in count/has_package PHP's ArrayRepository::count()/hasPackage() call $this->initialize(), which late-binds to the concrete repository class and lazily loads its packages. The Rust pass-throughs skipped that: they ran ArrayRepository's stub initialize instead, returning 0/false and marking the repository initialized with an empty package list, which made ensure_initialized() skip the real initialization forever after. Take &mut self in RepositoryInterface::count/has_package so the lazy repositories (Filesystem, Platform, Composer) can guard with their real initialize, and return Result from has_package since that initialization can fail (PHP propagates the exception). InstallerInterface::is_installed and InstallationManager::is_package_installed/mark_alias_installed propagate the same way, which also resolves the TODO(phase-d) markers on Package/Path/Artifact/Vcs repositories about initialization errors being swallowed. Co-Authored-By: Claude Fable 5 --- crates/shirabe/src/installer/noop_installer.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/shirabe/src/installer/noop_installer.rs') diff --git a/crates/shirabe/src/installer/noop_installer.rs b/crates/shirabe/src/installer/noop_installer.rs index c83bf674..d76ad4ad 100644 --- a/crates/shirabe/src/installer/noop_installer.rs +++ b/crates/shirabe/src/installer/noop_installer.rs @@ -16,9 +16,9 @@ impl InstallerInterface for NoopInstaller { fn is_installed( &self, - repo: &dyn InstalledRepositoryInterface, + repo: &mut dyn InstalledRepositoryInterface, package: PackageInterfaceHandle, - ) -> bool { + ) -> anyhow::Result { repo.has_package(package) } @@ -54,7 +54,7 @@ impl InstallerInterface for NoopInstaller { package: PackageInterfaceHandle, ) -> anyhow::Result> { let mut repo = repo.borrow_mut(); - if !repo.has_package(package.clone()) { + if !repo.has_package(package.clone())? { repo.add_package(PackageInterfaceHandle::dup(&package)); } @@ -68,7 +68,7 @@ impl InstallerInterface for NoopInstaller { target: PackageInterfaceHandle, ) -> anyhow::Result> { let mut repo = repo.borrow_mut(); - if !repo.has_package(initial.clone()) { + if !repo.has_package(initial.clone())? { return Err(InvalidArgumentException { message: format!("Package is not installed: {}", initial), code: 0, @@ -77,7 +77,7 @@ impl InstallerInterface for NoopInstaller { } repo.remove_package(initial); - if !repo.has_package(target.clone()) { + if !repo.has_package(target.clone())? { repo.add_package(PackageInterfaceHandle::dup(&target)); } @@ -90,7 +90,7 @@ impl InstallerInterface for NoopInstaller { package: PackageInterfaceHandle, ) -> anyhow::Result> { let mut repo = repo.borrow_mut(); - if !repo.has_package(package.clone()) { + if !repo.has_package(package.clone())? { return Err(InvalidArgumentException { message: format!("Package is not installed: {}", package), code: 0, -- cgit v1.3.1