aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/installer
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-02 08:42:55 +0900
committernsfisis <nsfisis@gmail.com>2026-08-02 08:42:55 +0900
commitb5d6d91054b9ceef95aef0819bb5c4ef7db1abdd (patch)
tree0bd12e599f48fcc63375363363416ca48766c698 /crates/shirabe/tests/installer
parent3e367f78eec3521106979461fda717926717515a (diff)
downloadphp-shirabe-b5d6d91054b9ceef95aef0819bb5c4ef7db1abdd.tar.gz
php-shirabe-b5d6d91054b9ceef95aef0819bb5c4ef7db1abdd.tar.zst
php-shirabe-b5d6d91054b9ceef95aef0819bb5c4ef7db1abdd.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/installer')
-rw-r--r--crates/shirabe/tests/installer/installation_manager_test.rs12
-rw-r--r--crates/shirabe/tests/installer/library_installer_test.rs28
-rw-r--r--crates/shirabe/tests/installer/metapackage_installer_test.rs8
3 files changed, 30 insertions, 18 deletions
diff --git a/crates/shirabe/tests/installer/installation_manager_test.rs b/crates/shirabe/tests/installer/installation_manager_test.rs
index 3f18e925..6cc231f5 100644
--- a/crates/shirabe/tests/installer/installation_manager_test.rs
+++ b/crates/shirabe/tests/installer/installation_manager_test.rs
@@ -75,10 +75,10 @@ impl InstallerInterface for MockInstaller {
fn is_installed(
&self,
- _repo: &dyn InstalledRepositoryInterface,
+ _repo: &mut dyn InstalledRepositoryInterface,
_package: PackageInterfaceHandle,
- ) -> bool {
- false
+ ) -> anyhow::Result<bool> {
+ Ok(false)
}
async fn download(
@@ -175,10 +175,10 @@ impl InstallerInterface for BinaryInstaller {
fn is_installed(
&self,
- _repo: &dyn InstalledRepositoryInterface,
+ _repo: &mut dyn InstalledRepositoryInterface,
_package: PackageInterfaceHandle,
- ) -> bool {
- false
+ ) -> anyhow::Result<bool> {
+ Ok(false)
}
async fn download(
diff --git a/crates/shirabe/tests/installer/library_installer_test.rs b/crates/shirabe/tests/installer/library_installer_test.rs
index 8a063941..baa4f13a 100644
--- a/crates/shirabe/tests/installer/library_installer_test.rs
+++ b/crates/shirabe/tests/installer/library_installer_test.rs
@@ -200,19 +200,31 @@ fn test_is_installed() {
let package = get_package("test/pkg", "1.0.0");
let mut repository = InstalledArrayRepository::new().unwrap();
- assert!(!library.is_installed(&repository, package.clone()));
+ assert!(
+ !library
+ .is_installed(&mut repository, package.clone())
+ .unwrap()
+ );
// package being in repo is not enough to be installed
repository.add_package(package.clone()).unwrap();
- assert!(!library.is_installed(&repository, package.clone()));
+ assert!(
+ !library
+ .is_installed(&mut repository, package.clone())
+ .unwrap()
+ );
// package being in repo and vendor/pkg/foo dir present means it is seen as installed
let pkg_dir = format!("{}/{}", setup.vendor_dir, package.get_pretty_name());
fs::create_dir_all(&pkg_dir).unwrap();
- assert!(library.is_installed(&repository, package.clone()));
+ assert!(
+ library
+ .is_installed(&mut repository, package.clone())
+ .unwrap()
+ );
repository.remove_package(package.clone()).unwrap();
- assert!(!library.is_installed(&repository, package));
+ assert!(!library.is_installed(&mut repository, package).unwrap());
tear_down(&mut setup);
}
@@ -249,7 +261,7 @@ fn test_install() {
.unwrap();
// PHP asserts repository->addPackage was called once with $package.
- assert!(repository.has_package(package));
+ assert!(repository.has_package(package).unwrap());
assert!(
std::path::Path::new(&setup.vendor_dir).exists(),
@@ -317,8 +329,8 @@ fn test_update() {
);
assert!(!std::path::Path::new(&old_target_dir).exists());
- assert!(!repository.has_package(initial.clone()));
- assert!(repository.has_package(target.clone()));
+ assert!(!repository.has_package(initial.clone()).unwrap());
+ assert!(repository.has_package(target.clone()).unwrap());
assert!(
std::path::Path::new(&setup.vendor_dir).exists(),
@@ -379,7 +391,7 @@ fn test_uninstall() {
))
.unwrap();
- assert!(!repository.has_package(package.clone()));
+ assert!(!repository.has_package(package.clone()).unwrap());
// Uninstalling again, with the package no longer installed, fails.
assert!(
diff --git a/crates/shirabe/tests/installer/metapackage_installer_test.rs b/crates/shirabe/tests/installer/metapackage_installer_test.rs
index 86013871..b87fdebd 100644
--- a/crates/shirabe/tests/installer/metapackage_installer_test.rs
+++ b/crates/shirabe/tests/installer/metapackage_installer_test.rs
@@ -30,7 +30,7 @@ fn test_install() {
))
.unwrap();
- assert!(repository.has_package(package));
+ assert!(repository.has_package(package).unwrap());
}
#[test]
@@ -50,8 +50,8 @@ fn test_update() {
))
.unwrap();
- assert!(!repository.has_package(initial.clone()));
- assert!(repository.has_package(target.clone()));
+ assert!(!repository.has_package(initial.clone()).unwrap());
+ assert!(repository.has_package(target.clone()).unwrap());
// Updating again, with the initial package no longer installed, fails.
assert!(
@@ -81,7 +81,7 @@ fn test_uninstall() {
))
.unwrap();
- assert!(!repository.has_package(package.clone()));
+ assert!(!repository.has_package(package.clone()).unwrap());
// Uninstalling again, with the package no longer installed, fails.
assert!(