From e0ba36807619780ff645efe0117281d32d5ace2a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 25 Jun 2026 18:05:50 +0900 Subject: test: recover binary_installer full-compat port; implement posix_getpwuid The stashed binary_installer port was blocked on posix_getpwuid (reached via Platform::is_virtual_box_guest); implement it via getpwuid(3) extern "C". The 4 install-and-exec tests now pass with the stream I/O and Process cwd fixes. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../tests/installer/binary_installer_test.rs | 144 +++++++++++++++++---- 1 file changed, 122 insertions(+), 22 deletions(-) (limited to 'crates/shirabe/tests') diff --git a/crates/shirabe/tests/installer/binary_installer_test.rs b/crates/shirabe/tests/installer/binary_installer_test.rs index a3e3c24..48a6b6f 100644 --- a/crates/shirabe/tests/installer/binary_installer_test.rs +++ b/crates/shirabe/tests/installer/binary_installer_test.rs @@ -1,33 +1,133 @@ //! ref: composer/tests/Composer/Test/Installer/BinaryInstallerTest.php -/// Creates the root/vendor/bin temp directories and a mocked IO. The temp-dir -/// helpers (`getUniqueTmpDirectory`/`ensureDirectoryExistsAndClear`) and the IO -/// mock are not available here, so this remains a stub. -fn set_up() { - todo!() -} +use std::cell::RefCell; +use std::fs; +use std::rc::Rc; + +use base64::Engine; +use tempfile::TempDir; + +use shirabe::installer::BinaryInstaller; +use shirabe::io::IOInterface; +use shirabe::io::null_io::NullIO; +use shirabe::util::Filesystem; +use shirabe::util::ProcessExecutor; + +use crate::test_case::get_package; -/// Removes the root dir created by `set_up`, which is itself a stub. -fn tear_down() { - todo!() +/// Mirror of setUp(): builds temp root/vendor/bin dirs plus a mocked IO. PHP uses a +/// PHPUnit IOInterface mock with no expectations; a NullIO is the closest analogue. +struct SetUp { + root: TempDir, + vendor_dir: String, + bin_dir: String, + io: Rc>, + fs: Filesystem, } -struct TearDown; +fn set_up() -> SetUp { + let fs = Filesystem::new(None); + + let root = TempDir::new().unwrap(); + let root_dir = fs::canonicalize(root.path()) + .unwrap() + .to_string_lossy() + .into_owned(); + + let vendor_dir = format!("{}/vendor", root_dir); + fs::create_dir_all(&vendor_dir).unwrap(); + + let bin_dir = format!("{}/bin", root_dir); + fs::create_dir_all(&bin_dir).unwrap(); -impl Drop for TearDown { - fn drop(&mut self) { - tear_down(); + let io: Rc> = Rc::new(RefCell::new(NullIO::new())); + + SetUp { + root, + vendor_dir, + bin_dir, + io, + fs, } } -// This installs a PHP binary (via NullIO + Package::__set_binaries + a real tempdir) and then -// executes it through ProcessExecutor, asserting its output. Setup and binary-proxy generation -// all work; the remaining blocker is real subprocess I/O: ProcessExecutor -> symfony Process -// drives its pipe reads through `stream_select`/`stream_set_blocking`, both of which are still -// `todo!()` in shirabe-php-shim (they require select(2)/fcntl(2) over the child pipe fds, which -// the shim does not yet expose). Un-ignore once that pipe-reading layer is implemented. +fn tear_down(setup: &mut SetUp) { + let root = setup.root.path().to_path_buf(); + setup.fs.remove_directory(&root).ok(); +} + +/// ref: BinaryInstallerTest::executableBinaryProvider +fn executable_binary_provider() -> Vec<(&'static str, Vec)> { + vec![ + ( + "simple php file", + b"