From c2a2bd3a2573f585c902c39bd28b8c3cad10c317 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 2 Aug 2026 20:11:51 +0900 Subject: fix(repository): resolve remaining late-binding hazards from the audit Three fixes for the ComposerRepository/FilesystemRepository/PlatformRepository hazards where inner-composition delegation skipped PHP's late-bound virtual dispatch: - ComposerRepository::has_package now builds its packageMap through the late-bound getPackages() equivalent, so lazy-providers repos surface the LogicException and available-packages repos load their package list, as in PHP, instead of silently answering false from the raw array. - RepositoryInterface::get_repo_name returns anyhow::Result: PHP's getRepoName() counts through the late-bound initialize(), which is fallible in file-reading subclasses. FilesystemRepository and PackageRepository now run that initialization instead of freezing the inner array repository to an empty state (which also made a later write() truncate installed.json). Supporting changes keep the initialization chain callable from &self: JsonFile::read takes &self (indent moved into a RefCell), FilesystemRepository dev_mode became a Cell, and WritableArrayRepository dev_package_names a RefCell. - PlatformRepository::new routes constructor packages through its own add_package so the override handling and full platform initialization run as they do via PHP's parent constructor; the inner find_package/add_package delegations inside add_package (and ComposerRepository::add_package) gained the same is_initialized guard, since the constructor path would otherwise freeze the repository. Same defect class as 7db937af, 97b5211a and 3e367f78. Co-Authored-By: Claude Fable 5 --- crates/shirabe/tests/command/bump_command_test.rs | 2 +- crates/shirabe/tests/command/init_command_test.rs | 2 +- crates/shirabe/tests/command/remove_command_test.rs | 2 +- crates/shirabe/tests/command/repository_command_test.rs | 2 +- crates/shirabe/tests/command/require_command_test.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/shirabe/tests/command') diff --git a/crates/shirabe/tests/command/bump_command_test.rs b/crates/shirabe/tests/command/bump_command_test.rs index d511f2a1..14ac17a6 100644 --- a/crates/shirabe/tests/command/bump_command_test.rs +++ b/crates/shirabe/tests/command/bump_command_test.rs @@ -41,7 +41,7 @@ fn run_bump_case( let status_code = app_tester.run(input, RunOptions::default()).unwrap(); assert_eq!(exit_code, status_code); - let mut json = JsonFile::new("./composer.json".to_string(), None, None).unwrap(); + let json = JsonFile::new("./composer.json".to_string(), None, None).unwrap(); let read = json.read().unwrap(); let actual: serde_json::Value = serde_json::from_str(&JsonFile::encode(&read).unwrap()).unwrap(); diff --git a/crates/shirabe/tests/command/init_command_test.rs b/crates/shirabe/tests/command/init_command_test.rs index 57777e35..914680fb 100644 --- a/crates/shirabe/tests/command/init_command_test.rs +++ b/crates/shirabe/tests/command/init_command_test.rs @@ -23,7 +23,7 @@ fn default_authors() -> serde_json::Value { /// `serde_json::Value` so the comparison ignores object key order (matching PHPUnit's `assertEquals` /// on arrays) while staying order-sensitive for lists. fn read_composer_json(dir: &std::path::Path) -> serde_json::Value { - let mut file = JsonFile::new( + let file = JsonFile::new( dir.join("composer.json").to_string_lossy().to_string(), None, None, diff --git a/crates/shirabe/tests/command/remove_command_test.rs b/crates/shirabe/tests/command/remove_command_test.rs index 7b195746..9139bf26 100644 --- a/crates/shirabe/tests/command/remove_command_test.rs +++ b/crates/shirabe/tests/command/remove_command_test.rs @@ -26,7 +26,7 @@ fn input(pairs: Vec<(&str, PhpMixed)>) -> Vec<(PhpMixed, PhpMixed)> { /// Read a JSON file in the CWD and decode it to a `serde_json::Value`. fn read_json_file(path: &str) -> serde_json::Value { - let mut json = JsonFile::new(path.to_string(), None, None).unwrap(); + let json = JsonFile::new(path.to_string(), None, None).unwrap(); let read = json.read().unwrap(); serde_json::from_str(&JsonFile::encode(&read).unwrap()).unwrap() } diff --git a/crates/shirabe/tests/command/repository_command_test.rs b/crates/shirabe/tests/command/repository_command_test.rs index 48ca301a..36b74cc8 100644 --- a/crates/shirabe/tests/command/repository_command_test.rs +++ b/crates/shirabe/tests/command/repository_command_test.rs @@ -7,7 +7,7 @@ use shirabe_php_shim::PhpMixed; /// Read the composer.json in the CWD and decode it. fn read_composer_json() -> serde_json::Value { - let mut json = JsonFile::new("./composer.json".to_string(), None, None).unwrap(); + let json = JsonFile::new("./composer.json".to_string(), None, None).unwrap(); let read = json.read().unwrap(); serde_json::from_str(&JsonFile::encode(&read).unwrap()).unwrap() } diff --git a/crates/shirabe/tests/command/require_command_test.rs b/crates/shirabe/tests/command/require_command_test.rs index 4237c4f8..2a9a0411 100644 --- a/crates/shirabe/tests/command/require_command_test.rs +++ b/crates/shirabe/tests/command/require_command_test.rs @@ -382,7 +382,7 @@ fn test_inconsistent_require_keys() { app_tester.get_display() ); - let mut composer_content = + let composer_content = JsonFile::new(format!("{}/composer.json", dir.display()), None, None).unwrap(); let content = composer_content.read().unwrap(); let content: serde_json::Value = -- cgit v1.3.1