aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/repository/array_repository_test.rs
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/repository/array_repository_test.rs
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/repository/array_repository_test.rs')
-rw-r--r--crates/shirabe/tests/repository/array_repository_test.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/shirabe/tests/repository/array_repository_test.rs b/crates/shirabe/tests/repository/array_repository_test.rs
index 069e9113..e3fbf93c 100644
--- a/crates/shirabe/tests/repository/array_repository_test.rs
+++ b/crates/shirabe/tests/repository/array_repository_test.rs
@@ -48,7 +48,7 @@ fn reprs(results: &[SearchResult]) -> Vec<(String, Option<String>, Abandoned)> {
#[test]
fn test_add_package() {
- let repo = ArrayRepository::new(vec![]).unwrap();
+ let mut repo = ArrayRepository::new(vec![]).unwrap();
repo.add_package(get_package("foo", "1")).unwrap();
assert_eq!(1, repo.count().unwrap());
@@ -74,12 +74,12 @@ fn test_remove_package() {
#[test]
fn test_has_package() {
- let repo = ArrayRepository::new(vec![]).unwrap();
+ let mut repo = ArrayRepository::new(vec![]).unwrap();
repo.add_package(get_package("foo", "1")).unwrap();
repo.add_package(get_package("bar", "2")).unwrap();
- assert!(repo.has_package(get_package("foo", "1")));
- assert!(!repo.has_package(get_package("bar", "1")));
+ assert!(repo.has_package(get_package("foo", "1")).unwrap());
+ assert!(!repo.has_package(get_package("bar", "1")).unwrap());
}
#[test]
@@ -100,7 +100,7 @@ fn test_find_packages() {
#[test]
fn test_automatically_add_aliased_package_but_not_remove() {
- let repo = ArrayRepository::new(vec![]).unwrap();
+ let mut repo = ArrayRepository::new(vec![]).unwrap();
let package = get_package("foo", "1");
let alias = get_alias_package(&package, "2");
@@ -108,8 +108,8 @@ fn test_automatically_add_aliased_package_but_not_remove() {
repo.add_package(alias.clone()).unwrap();
assert_eq!(2, repo.count().unwrap());
- assert!(repo.has_package(get_package("foo", "1")));
- assert!(repo.has_package(get_package("foo", "2")));
+ assert!(repo.has_package(get_package("foo", "1")).unwrap());
+ assert!(repo.has_package(get_package("foo", "2")).unwrap());
repo.remove_package(alias);