From e98823e599eb375b30037cc714710e3309d927d1 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 27 Jun 2026 17:21:00 +0900 Subject: test: port Composer tests unblocked by mockall, add seams Port 11 categories of previously-ignored Composer tests now reachable with the mockall crate: DownloadManager, VCS/Perforce/File downloaders, VersionSelector, PlatformRepository, Auditor, installer/FilesystemRepository, RootPackageLoader, util auth/http, commands, and Cache. Extract test seams additively on concrete structs as *Interface traits (Runtime, HhvmDetector, VersionGuesser, RepositorySet, Perforce, BinaryInstaller) plus mock-field seams (Cache, Filesystem); consumers take trait objects. Mocks are defined locally in the test crates via mockall::mock!, since automock-generated mocks are cfg(test)-gated and invisible across the integration-test boundary. dataProviders are ported in full; tests blocked by unported shims stay #[ignore] with documented reasons rather than reduced or weakened. Fix product bugs surfaced by the ports: - util/github: use the exception code, not the HTTP status, for 401/403 - advisory: serialize empty audit maps as [] to match PHP json_encode - repository/filesystem and downloader/file: fix RefCell double-borrow panics Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/util/perforce.rs | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'crates/shirabe/src/util/perforce.rs') diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs index 4d4ddef..d8cd39d 100644 --- a/crates/shirabe/src/util/perforce.rs +++ b/crates/shirabe/src/util/perforce.rs @@ -838,3 +838,85 @@ impl Perforce { .clone() } } + +/// Seam over `Perforce` so consumers can be exercised with a mock in tests. +pub trait PerforceInterface: std::fmt::Debug { + fn initialize_path(&mut self, path: &str); + fn set_stream(&mut self, stream: &str); + fn p4_login(&mut self) -> Result<()>; + fn check_stream(&mut self) -> bool; + fn write_p4_client_spec(&mut self) -> Result<()>; + fn connect_client(&mut self) -> Result<()>; + fn sync_code_base(&mut self, source_reference: Option) -> Result<()>; + fn cleanup_client_spec(&mut self); + fn get_commit_logs(&mut self, from_reference: &str, to_reference: &str) -> Option; + fn get_file_content(&mut self, file: &str, identifier: &str) -> Option; + fn get_branches(&mut self) -> IndexMap; + fn get_tags(&mut self) -> IndexMap; + fn get_user(&self) -> Option; + fn get_composer_information( + &mut self, + identifier: &str, + ) -> Result>>; +} + +impl PerforceInterface for Perforce { + fn initialize_path(&mut self, path: &str) { + Perforce::initialize_path(self, path) + } + + fn set_stream(&mut self, stream: &str) { + Perforce::set_stream(self, stream) + } + + fn p4_login(&mut self) -> Result<()> { + Perforce::p4_login(self) + } + + fn check_stream(&mut self) -> bool { + Perforce::check_stream(self) + } + + fn write_p4_client_spec(&mut self) -> Result<()> { + Perforce::write_p4_client_spec(self) + } + + fn connect_client(&mut self) -> Result<()> { + Perforce::connect_client(self) + } + + fn sync_code_base(&mut self, source_reference: Option) -> Result<()> { + Perforce::sync_code_base(self, source_reference.as_deref()) + } + + fn cleanup_client_spec(&mut self) { + Perforce::cleanup_client_spec(self) + } + + fn get_commit_logs(&mut self, from_reference: &str, to_reference: &str) -> Option { + Perforce::get_commit_logs(self, from_reference, to_reference) + } + + fn get_file_content(&mut self, file: &str, identifier: &str) -> Option { + Perforce::get_file_content(self, file, identifier) + } + + fn get_branches(&mut self) -> IndexMap { + Perforce::get_branches(self) + } + + fn get_tags(&mut self) -> IndexMap { + Perforce::get_tags(self) + } + + fn get_user(&self) -> Option { + Perforce::get_user(self) + } + + fn get_composer_information( + &mut self, + identifier: &str, + ) -> Result>> { + Perforce::get_composer_information(self, identifier) + } +} -- cgit v1.3.1