diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-07 20:51:59 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-07 20:51:59 +0900 |
| commit | cd9e4a2b67cdea258e1daa2d9d830b7643bc19bb (patch) | |
| tree | e3dd09ac9f471b3c3900f61a6e5d58d9636dab45 /crates/shirabe/tests/installer_test.rs | |
| parent | 427e059e4ffc6ce5ff130c803f9e533b7c125089 (diff) | |
| download | php-shirabe-cd9e4a2b67cdea258e1daa2d9d830b7643bc19bb.tar.gz php-shirabe-cd9e4a2b67cdea258e1daa2d9d830b7643bc19bb.tar.zst php-shirabe-cd9e4a2b67cdea258e1daa2d9d830b7643bc19bb.zip | |
fix(autoload-generator): survive listeners that re-enter dump()
AutoloadGenerator::dump dispatches PRE_AUTOLOAD_DUMP / POST_AUTOLOAD_DUMP, and
EventDispatcher::make_autoloader answers those by walking back into the Composer
graph -- the local repository, the installation manager, and the generator
itself. Installer::run held mutable borrows of all three across the dump call,
so any plugin subscribing to either event panicked with "RefCell already
borrowed" before its listener ran.
dump() and build_package_map() now take the local repository, the installation
manager and the locker as shared handles instead of &mut dyn, and the borrow is
taken where it is used.
The generator itself is re-entered, not just borrowed twice: PHP listeners reach
it through Composer::getAutoloadGenerator() and call setDevMode() while dump()
is running, and make_autoloader asks the same object for a package map. That is
not expressible behind &mut self, so the mutable state moves into Cell/RefCell
fields and the whole AutoloadGeneratorInterface takes &self.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/installer_test.rs')
| -rw-r--r-- | crates/shirabe/tests/installer_test.rs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/crates/shirabe/tests/installer_test.rs b/crates/shirabe/tests/installer_test.rs index f5e84558..90dca3ca 100644 --- a/crates/shirabe/tests/installer_test.rs +++ b/crates/shirabe/tests/installer_test.rs @@ -34,8 +34,8 @@ use shirabe::package::{ RootPackageInterfaceHandle, }; use shirabe::repository::{ - ArrayRepository, InstalledArrayRepository, InstalledRepositoryInterface, - RepositoryInterfaceHandle, RepositoryManager, RepositoryManagerInterface, + ArrayRepository, InstalledArrayRepository, RepositoryInterfaceHandle, RepositoryManager, + RepositoryManagerInterface, }; use shirabe::util::http_downloader::HttpDownloader; use shirabe::util::r#loop::Loop; @@ -206,34 +206,38 @@ impl EventDispatcherInterface for StubEventDispatcher { struct StubAutoloadGenerator; impl AutoloadGeneratorInterface for StubAutoloadGenerator { - fn set_dev_mode(&mut self, _dev_mode: bool) {} - fn set_class_map_authoritative(&mut self, _class_map_authoritative: bool) {} - fn set_apcu(&mut self, _apcu: bool, _apcu_prefix: Option<String>) {} - fn set_run_scripts(&mut self, _run_scripts: bool) {} - fn set_dry_run(&mut self, _dry_run: bool) {} + fn set_dev_mode(&self, _dev_mode: bool) {} + fn set_class_map_authoritative(&self, _class_map_authoritative: bool) {} + fn set_apcu(&self, _apcu: bool, _apcu_prefix: Option<String>) {} + fn set_run_scripts(&self, _run_scripts: bool) {} + fn set_dry_run(&self, _dry_run: bool) {} fn set_platform_requirement_filter( - &mut self, + &self, _platform_requirement_filter: std::rc::Rc<dyn PlatformRequirementFilterInterface>, ) { } #[allow(clippy::too_many_arguments)] fn dump( - &mut self, + &self, _config: &Config, - _local_repo: &mut dyn InstalledRepositoryInterface, + _local_repo: shirabe::repository::RepositoryInterfaceHandle, _root_package: RootPackageInterfaceHandle, - _installation_manager: &mut dyn shirabe::installer::InstallationManagerInterface, + _installation_manager: std::rc::Rc< + std::cell::RefCell<dyn shirabe::installer::InstallationManagerInterface>, + >, _target_dir: &str, _scan_psr_packages: bool, _suffix: Option<String>, - _locker: Option<&mut dyn LockerInterface>, + _locker: Option<std::rc::Rc<std::cell::RefCell<dyn LockerInterface>>>, _strict_ambiguous: bool, ) -> anyhow::Result<ClassMap> { Ok(ClassMap::new()) } fn build_package_map( &self, - _installation_manager: &mut dyn shirabe::installer::InstallationManagerInterface, + _installation_manager: std::rc::Rc< + std::cell::RefCell<dyn shirabe::installer::InstallationManagerInterface>, + >, _root_package: RootPackageInterfaceHandle, _packages: Vec<PackageInterfaceHandle>, ) -> anyhow::Result<Vec<(PackageInterfaceHandle, Option<String>)>> { |
