Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,12 @@ private static function get_process_env_variables(): array {
$path_separator = Utils\is_windows() ? ';' : ':';
$php_binary_path = dirname( PHP_BINARY );
$env = [
'PATH' => $php_binary_path . $path_separator . $bin_path . $path_separator . getenv( 'PATH' ),
'BEHAT_RUN' => 1,
'HOME' => sys_get_temp_dir() . '/wp-cli-home',
'COMPOSER_HOME' => sys_get_temp_dir() . '/wp-cli-composer-home',
'TEST_RUN_DIR' => self::$behat_run_dir,
'PATH' => $php_binary_path . $path_separator . $bin_path . $path_separator . getenv( 'PATH' ),
'BEHAT_RUN' => 1,
'HOME' => sys_get_temp_dir() . '/wp-cli-home',
'COMPOSER_HOME' => sys_get_temp_dir() . '/wp-cli-composer-home',
'TEST_RUN_DIR' => self::$behat_run_dir,
'WP_CLI_SKIP_PROMPT' => 'no',
];

$env = array_merge( $_ENV, $env );
Expand Down Expand Up @@ -745,8 +746,10 @@ public function beforeScenario( BeforeScenarioScope $scope ): void {
public function afterScenario( AfterScenarioScope $scope ): void {

if ( self::$run_dir ) {
// Remove altered WP install, unless there's an error.
if ( $scope->getTestResult()->getResultCode() <= 10 ) {
// Remove altered WP install, unless there's an error (and we are not on CI).
$is_ci = getenv( 'CI' );
$is_debug = getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' );
if ( $scope->getTestResult()->getResultCode() <= 10 || ( $is_ci && ! $is_debug ) ) {
Comment on lines +750 to +752
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$is_debug here is effectively never truthy during normal test runs because prepare() exits early when WP_CLI_TEST_DEBUG_BEHAT_ENV is set (FeatureContext.php:697-699). That makes the ! $is_debug part misleading/dead in practice. Either remove the debug branch, or change the debug behavior so the suite can run while preserving RUN_DIR for inspection when WP_CLI_TEST_DEBUG_BEHAT_ENV is enabled.

Suggested change
$is_ci = getenv( 'CI' );
$is_debug = getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' );
if ( $scope->getTestResult()->getResultCode() <= 10 || ( $is_ci && ! $is_debug ) ) {
$is_ci = getenv( 'CI' );
if ( $scope->getTestResult()->getResultCode() <= 10 || $is_ci ) {

Copilot uses AI. Check for mistakes.
self::remove_dir( self::$run_dir );
}
self::$run_dir = null;
Expand Down
Loading