From cd9e4a2b67cdea258e1daa2d9d830b7643bc19bb Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 7 Aug 2026 20:51:59 +0900 Subject: 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) --- .../event_dispatcher/event_dispatcher_test.rs | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs') diff --git a/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs b/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs index d97c14f0..af8a33db 100644 --- a/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs +++ b/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs @@ -19,8 +19,7 @@ use shirabe::package::{ LockerInterface, PackageInterfaceHandle, RootPackageHandle, RootPackageInterfaceHandle, }; use shirabe::repository::{ - InstalledArrayRepository, InstalledRepositoryInterface, RepositoryInterfaceHandle, - RepositoryManagerInterface, + InstalledArrayRepository, RepositoryInterfaceHandle, RepositoryManagerInterface, }; use shirabe::script::Event as ScriptEvent; use shirabe::script::ScriptEvents; @@ -405,30 +404,30 @@ mockall::mock! { #[derive(Debug)] pub AutoloadGenerator {} impl AutoloadGeneratorInterface for AutoloadGenerator { - 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); - 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); + 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, ); - fn dump<'a>( - &mut self, + fn dump( + &self, config: &Config, - local_repo: &mut dyn InstalledRepositoryInterface, + local_repo: shirabe::repository::RepositoryInterfaceHandle, root_package: RootPackageInterfaceHandle, - installation_manager: &mut dyn InstallationManagerInterface, + installation_manager: std::rc::Rc>, target_dir: &str, scan_psr_packages: bool, suffix: Option, - locker: Option<&'a mut dyn LockerInterface>, + locker: Option>>, strict_ambiguous: bool, ) -> anyhow::Result; fn build_package_map( &self, - installation_manager: &mut dyn InstallationManagerInterface, + installation_manager: std::rc::Rc>, root_package: RootPackageInterfaceHandle, packages: Vec, ) -> anyhow::Result)>>; -- cgit v1.3.1