From 6a2040e9c1b200530269d65e5e57f897a4f95584 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 20 Jul 2026 05:32:30 +0900 Subject: fix(installation-manager): un-ignore test_add_remove_installer Add the __add_installer test seam that registers an installer as a pre-built Rc handle, so the test can reproduce PHP's object-identity semantics (assertSame / removeInstaller) via Rc::ptr_eq; add_installer cannot serve because Rc::from(Box) reallocates, losing the caller's pointer identity. Co-Authored-By: Claude Fable 5 --- .../tests/installer/installation_manager_test.rs | 40 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'crates/shirabe/tests/installer') diff --git a/crates/shirabe/tests/installer/installation_manager_test.rs b/crates/shirabe/tests/installer/installation_manager_test.rs index f5012ef7..867e759a 100644 --- a/crates/shirabe/tests/installer/installation_manager_test.rs +++ b/crates/shirabe/tests/installer/installation_manager_test.rs @@ -283,13 +283,43 @@ fn test_add_get_installer() { assert!(manager.get_installer("unregistered").is_err()); } -#[ignore = "removeInstaller compares installers by object identity, but add_installer moves the Box into the manager, leaving no &dyn reference to pass back to remove_installer; faithful reproduction needs a shared-ownership installer registry"] #[test] fn test_add_remove_installer() { - // TODO(phase-d): removeInstaller compares installers by object identity, but add_installer - // moves the Box into the manager, leaving no &dyn reference to pass - // back to remove_installer; faithful reproduction needs a shared-ownership installer registry. - todo!() + let set_up = set_up(); + let mut installer = MockInstaller::new(); + installer + .expect_supports() + .times(2) + .returning(|arg| arg == "vendor"); + // The manager stores installers as Rc, so the PHP object-identity semantics (assertSame, + // removeInstaller) map to Rc::ptr_eq on a handle registered via __add_installer. + let installer: std::rc::Rc = std::rc::Rc::new(installer); + + let mut installer2 = MockInstaller::new(); + installer2 + .expect_supports() + .times(1) + .returning(|arg| arg == "vendor"); + let installer2: std::rc::Rc = std::rc::Rc::new(installer2); + + let mut manager = + shirabe::installer::InstallationManager::new(set_up.loop_.clone(), set_up.io.clone(), None); + + manager.__add_installer(installer.clone()); + assert!(std::rc::Rc::ptr_eq( + &installer, + &manager.get_installer("vendor").unwrap() + )); + manager.__add_installer(installer2.clone()); + assert!(std::rc::Rc::ptr_eq( + &installer2, + &manager.get_installer("vendor").unwrap() + )); + manager.remove_installer(&*installer2); + assert!(std::rc::Rc::ptr_eq( + &installer, + &manager.get_installer("vendor").unwrap() + )); } #[ignore = "partial mock of InstallationManager (onlyMethods install/update/uninstall) with expects(once)->with(...) is not reproducible without method-overriding mocks; execute() also takes the batched download path"] -- cgit v1.3.1