diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-25 12:16:25 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-25 12:16:25 +0900 |
| commit | 42b5f9e321c918cef542c120ad21ba8a7339eb29 (patch) | |
| tree | 39f2b5a3cb856de9068f72fb670d170c09a2438f /crates/shirabe/tests | |
| parent | f93d9b49382c8f79fcea4f03361d50bda534bcc4 (diff) | |
| download | php-shirabe-42b5f9e321c918cef542c120ad21ba8a7339eb29.tar.gz php-shirabe-42b5f9e321c918cef542c120ad21ba8a7339eb29.tar.zst php-shirabe-42b5f9e321c918cef542c120ad21ba8a7339eb29.zip | |
refactor(operation): replace OperationInterface with AnyOperation enum
Operations are only ever constructed by the dependency resolver, so a
plugin has no way to inject an implementation of its own and the set is
closed. Modelling it as an enum, like AnyPackage, removes the
OperationInterface trait together with its two parallel downcast
mechanisms (as_any() + downcast_ref, and as_*_operation()) and the
get_package() default method that panicked on UpdateOperation.
The PHP idiom `$op instanceof UpdateOperation ? getTargetPackage() :
getPackage()`, written out at six call sites, becomes
AnyOperation::get_target_package(). InstallationManager's three blocks
that matched on the type string and then recovered the type with
expect() collapse into exhaustive matches.
SolverOperation keeps only its TYPE constant; the shared
getOperationType()/__toString() implementations move to AnyOperation,
which also drops the five Self::TYPE.to_string() allocations.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests')
3 files changed, 13 insertions, 12 deletions
diff --git a/crates/shirabe/tests/dependency_resolver/solver_test.rs b/crates/shirabe/tests/dependency_resolver/solver_test.rs index 7a507da3..be8df4db 100644 --- a/crates/shirabe/tests/dependency_resolver/solver_test.rs +++ b/crates/shirabe/tests/dependency_resolver/solver_test.rs @@ -4,6 +4,7 @@ use crate::test_case::{get_alias_package, get_package, get_version_constraint}; use indexmap::IndexMap; use shirabe::dependency_resolver::PolicyInterface; use shirabe::dependency_resolver::default_policy::DefaultPolicy; +use shirabe::dependency_resolver::operation::AnyOperation; use shirabe::dependency_resolver::pool::Pool; use shirabe::dependency_resolver::request::Request; use shirabe::dependency_resolver::solver_problems_exception::SolverProblemsException; @@ -140,7 +141,7 @@ fn check_solver_result_repo_set( let mut result_readable: Vec<(String, String)> = Vec::new(); let mut result_ids: Vec<(String, Vec<usize>)> = Vec::new(); for operation in transaction.get_operations() { - if let Some(update) = operation.as_update_operation() { + if let AnyOperation::Update(update) = operation { let from = update.get_initial_package(); let to = update.get_target_package(); result_readable.push(( @@ -149,15 +150,14 @@ fn check_solver_result_repo_set( )); result_ids.push(("update".to_string(), vec![from.ptr_id(), to.ptr_id()])); } else { - let op_type = operation.get_operation_type(); - let job = match op_type.as_str() { + let job = match operation.get_operation_type() { "markAliasInstalled" => "markAliasInstalled", "markAliasUninstalled" => "markAliasUninstalled", "uninstall" => "remove", "install" => "install", other => panic!("Unexpected operation: {}", other), }; - let package = operation.get_package(); + let package = operation.get_target_package(); result_readable.push((job.to_string(), package.get_unique_name())); result_ids.push((job.to_string(), vec![package.ptr_id()])); } @@ -2521,7 +2521,7 @@ fn test_learn_positive_literal() { ]; let mut result: Vec<(String, String)> = Vec::new(); for operation in transaction.get_operations() { - if let Some(update) = operation.as_update_operation() { + if let AnyOperation::Update(update) = operation { result.push(( "update".to_string(), format!( @@ -2535,9 +2535,9 @@ fn test_learn_positive_literal() { let job = if op_type == "uninstall" { "remove".to_string() } else { - op_type + op_type.to_string() }; - result.push((job, operation.get_package().get_unique_name())); + result.push((job, operation.get_target_package().get_unique_name())); } } assert_eq!(expected, result); diff --git a/crates/shirabe/tests/dependency_resolver/transaction_test.rs b/crates/shirabe/tests/dependency_resolver/transaction_test.rs index 99f31c38..3b1006ea 100644 --- a/crates/shirabe/tests/dependency_resolver/transaction_test.rs +++ b/crates/shirabe/tests/dependency_resolver/transaction_test.rs @@ -2,6 +2,7 @@ use crate::test_case::{get_alias_package, get_package, get_version_constraint}; use indexmap::IndexMap; +use shirabe::dependency_resolver::operation::AnyOperation; use shirabe::dependency_resolver::transaction::Transaction; use shirabe::package::Link; use shirabe::package::handle::PackageInterfaceHandle; @@ -62,15 +63,15 @@ impl PartialEq for OperationEntry { fn check_transaction_operations(transaction: &Transaction, expected: Vec<OperationEntry>) { let mut result: Vec<OperationEntry> = vec![]; for operation in transaction.get_operations() { - if let Some(update) = operation.as_update_operation() { + if let AnyOperation::Update(update) = operation { result.push(OperationEntry::Update { from: update.get_initial_package(), to: update.get_target_package(), }); } else { result.push(OperationEntry::Job { - job: operation.get_operation_type(), - package: operation.get_package(), + job: operation.get_operation_type().to_string(), + package: operation.get_target_package(), }); } } diff --git a/crates/shirabe/tests/repository/filesystem_repository_test.rs b/crates/shirabe/tests/repository/filesystem_repository_test.rs index f2cdb670..054a6d7c 100644 --- a/crates/shirabe/tests/repository/filesystem_repository_test.rs +++ b/crates/shirabe/tests/repository/filesystem_repository_test.rs @@ -3,7 +3,7 @@ use crate::test_case::{get_alias_package, get_package}; use indexmap::IndexMap; use serial_test::serial; -use shirabe::dependency_resolver::operation::OperationInterface; +use shirabe::dependency_resolver::operation::AnyOperation; use shirabe::installed_versions::InstalledVersions; use shirabe::installer::{InstallationManagerInterface, InstallerInterface}; use shirabe::io::IOInterface; @@ -106,7 +106,7 @@ mockall::mock! { fn execute( &mut self, repo: &mut dyn InstalledRepositoryInterface, - operations: Vec<std::rc::Rc<dyn OperationInterface>>, + operations: Vec<AnyOperation>, dev_mode: bool, run_scripts: bool, download_only: bool, |
