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/command/archive_command.rs | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'crates/shirabe/src/command/archive_command.rs') diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs index 9aae885..d593912 100644 --- a/crates/shirabe/src/command/archive_command.rs +++ b/crates/shirabe/src/command/archive_command.rs @@ -36,6 +36,28 @@ use crate::util::r#loop::Loop; #[derive(Debug)] pub struct ArchiveCommand { base_command_data: BaseCommandData, + /// For testing only: partial-mock seam mirroring PHPUnit `onlyMethods(['initialize', 'archive'])`. + test_hooks: RefCell, +} + +/// For testing only: records and stubs for the `ArchiveCommand` partial-mock seam. +#[derive(Debug, Default)] +pub struct ArchiveCommandTestHooks { + skip_initialize: bool, + archive_stub_return: Option, + archive_calls: Vec, +} + +/// For testing only: the scalar arguments captured from a stubbed `archive` call. +#[derive(Debug, Clone)] +pub struct ArchiveCallRecord { + pub package_name: Option, + pub version: Option, + pub format: String, + pub dest: String, + pub file_name: Option, + pub ignore_filters: bool, + pub had_composer: bool, } impl Default for ArchiveCommand { @@ -50,6 +72,7 @@ impl ArchiveCommand { pub fn new() -> Self { let command = ArchiveCommand { base_command_data: BaseCommandData::new(None), + test_hooks: RefCell::new(ArchiveCommandTestHooks::default()), }; command .configure() @@ -188,12 +211,33 @@ impl Command for ArchiveCommand { input: Rc>, output: Rc>, ) -> anyhow::Result<()> { + if self.test_hooks.borrow().skip_initialize { + return Ok(()); + } base_command_initialize(self, input, output) } shirabe_external_packages::delegate_command_trait_impls_to_inner!(base_command_data); } +impl ArchiveCommand { + /// For testing only: makes `initialize` a no-op (PHPUnit `onlyMethods(['initialize'])`). + pub fn __test_skip_initialize(&self) { + self.test_hooks.borrow_mut().skip_initialize = true; + } + + /// For testing only: stubs `archive` to record its arguments and return `return_value` + /// without running (PHPUnit `onlyMethods(['archive'])`). + pub fn __test_stub_archive(&self, return_value: i64) { + self.test_hooks.borrow_mut().archive_stub_return = Some(return_value); + } + + /// For testing only: the arguments captured from stubbed `archive` calls. + pub fn __test_archive_calls(&self) -> Vec { + self.test_hooks.borrow().archive_calls.clone() + } +} + impl BaseCommand for ArchiveCommand { fn command_data( &self, @@ -218,6 +262,23 @@ impl ArchiveCommand { ignore_filters: bool, composer: Option<&PartialComposerHandle>, ) -> Result { + let archive_stub_return = self.test_hooks.borrow().archive_stub_return; + if let Some(return_value) = archive_stub_return { + self.test_hooks + .borrow_mut() + .archive_calls + .push(ArchiveCallRecord { + package_name, + version, + format: format.to_string(), + dest: dest.to_string(), + file_name, + ignore_filters, + had_composer: composer.is_some(), + }); + return Ok(return_value); + } + let composer_guard = composer.map(crate::composer::composer_full); let mut owned_archive_manager; let composer_archive_manager; -- cgit v1.3.1