From bbf33b836026cbe9fb9e7c76291dcb133b7144e2 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 10 Aug 2026 00:57:19 +0900 Subject: feat(xdebug): switch Xdebug off in the PHP worker Composer restarts itself with Xdebug unloaded because Xdebug makes PHP several times slower. Xdebug is never loaded into this process, so what needs dealing with is the PHP worker: it is spawned with `-d xdebug.mode=off` and `XDEBUG_MODE=off` (Xdebug reads the environment variable first and lets it override every ini setting), which makes its module init return before it installs any executor, compile, error or opcode hook. Rewriting the ini files and re-executing, the way xdebug-handler does, would additionally cover Xdebug 2, which hooks unconditionally and has no equivalent setting. That is not worth its machinery here: Xdebug 2 caps out at PHP 7.4, while every PHP version Composer supports can run Xdebug 3. What remains of XdebugHandler is small enough to live beside the worker it governs, so its crate is gone and its callers inline it. isXdebugActive answers false without asking PHP whenever the worker is switched off, so a command that needs no PHP does not spawn one just for the Xdebug warning; diagnose reports what the worker measures instead, which still surfaces an Xdebug that ignores the setting. PlatformRepository has no unloaded extension to restore, since switching the mode off leaves it loaded. COMPOSER_ORIGINAL_INIS is neither written nor read: it exists so a restarted process can name the ini files it replaced, and IniHelper can report the worker's own. IniHelperTest injects through that variable, so none of its cases are ported. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/tests/util/ini_helper_test.rs | 109 ++------------------------- 1 file changed, 6 insertions(+), 103 deletions(-) (limited to 'crates/shirabe/tests') diff --git a/crates/shirabe/tests/util/ini_helper_test.rs b/crates/shirabe/tests/util/ini_helper_test.rs index 90015169..f9ef3219 100644 --- a/crates/shirabe/tests/util/ini_helper_test.rs +++ b/crates/shirabe/tests/util/ini_helper_test.rs @@ -1,104 +1,7 @@ //! ref: composer/tests/Composer/Test/Util/IniHelperTest.php - -use shirabe::util::ini_helper::IniHelper; -use shirabe::util::platform::Platform; -use shirabe_php_shim::{getenv, putenv}; - -#[allow(dead_code)] -fn set_up() -> TearDown { - // Register our name with XdebugHandler. - // The PHP test constructs `new XdebugHandler('composer')` so that - // getAllIniFiles() reads the COMPOSER_ORIGINAL_INIS env var. The Rust - // XdebugHandler is a unit struct with no name-registration API, so this - // step is a no-op here. - // Save current state - let env_original = - getenv("COMPOSER_ORIGINAL_INIS").map(|value| value.to_string_lossy().into_owned()); - TearDown { env_original } -} - -#[allow(dead_code)] -fn tear_down(env_original: &Option) { - // Restore original state - if let Some(env_original) = env_original { - unsafe { putenv("COMPOSER_ORIGINAL_INIS", env_original) }; - } else { - Platform::clear_env("COMPOSER_ORIGINAL_INIS"); - } -} - -#[allow(dead_code)] -struct TearDown { - env_original: Option, -} - -impl Drop for TearDown { - fn drop(&mut self) { - tear_down(&self.env_original); - } -} - -fn set_env(paths: &[&str]) { - unsafe { - putenv( - "COMPOSER_ORIGINAL_INIS", - std::env::join_paths(paths).unwrap(), - ) - }; -} - -#[test] -#[ignore = "XdebugHandler is never constructed with a name (the bin/composer restart-without-Xdebug \ -bootstrap is unported, see TODO(phase-c) in shirabe's main.rs), so IniHelper::get_all() queries \ -the real PHP runtime directly instead of consulting COMPOSER_ORIGINAL_INIS"] -fn test_with_no_ini() { - let paths = [""]; - - set_env(&paths); - assert!(IniHelper::get_message().contains("does not exist")); - assert_eq!( - paths.iter().map(|s| s.to_string()).collect::>(), - IniHelper::get_all() - ); -} - -#[test] -#[ignore = "XdebugHandler is never constructed with a name (the bin/composer restart-without-Xdebug \ -bootstrap is unported, see TODO(phase-c) in shirabe's main.rs), so IniHelper::get_all() queries \ -the real PHP runtime directly instead of consulting COMPOSER_ORIGINAL_INIS"] -fn test_with_loaded_ini_only() { - let paths = ["loaded.ini"]; - - set_env(&paths); - assert!(IniHelper::get_message().contains("loaded.ini")); -} - -#[test] -#[ignore = "XdebugHandler is never constructed with a name (the bin/composer restart-without-Xdebug \ -bootstrap is unported, see TODO(phase-c) in shirabe's main.rs), so IniHelper::get_all() queries \ -the real PHP runtime directly instead of consulting COMPOSER_ORIGINAL_INIS"] -fn test_with_loaded_ini_and_additional() { - let paths = ["loaded.ini", "one.ini", "two.ini"]; - - set_env(&paths); - assert!(IniHelper::get_message().contains("multiple ini files")); - assert_eq!( - paths.iter().map(|s| s.to_string()).collect::>(), - IniHelper::get_all() - ); -} - -#[test] -#[ignore = "XdebugHandler is never constructed with a name (the bin/composer restart-without-Xdebug \ -bootstrap is unported, see TODO(phase-c) in shirabe's main.rs), so IniHelper::get_all() queries \ -the real PHP runtime directly instead of consulting COMPOSER_ORIGINAL_INIS"] -fn test_without_loaded_ini_and_additional() { - let paths = ["", "one.ini", "two.ini"]; - - set_env(&paths); - assert!(IniHelper::get_message().contains("multiple ini files")); - assert_eq!( - paths.iter().map(|s| s.to_string()).collect::>(), - IniHelper::get_all() - ); -} +//! +//! All four cases of this test feed IniHelper made-up ini paths through COMPOSER_ORIGINAL_INIS. +//! That variable exists so a process restarted without Xdebug can name the ini files it replaced; +//! nothing here restarts PHP, so IniHelper::get_all() reports the ini files the PHP worker loaded +//! and never reads it (see docs/dev/xdebug.md). With no way to feed the helper, none of the cases +//! are ported. -- cgit v1.3.1-4-g156e