From 5e2f7d46450f44257998c1837c6e047e14f00f68 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:38:04 +0000 Subject: [PATCH 1/6] Initial plan From 9b321c671bfe542945bbfd466fa572169277b0b6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:40:31 +0000 Subject: [PATCH 2/6] Add cleanup for temporary files on Windows in background_proc Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Context/FeatureContext.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index eb5270d0..c50c8920 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -1355,6 +1355,9 @@ public function background_proc( $cmd ): void { if ( Utils\is_windows() ) { $stderr = (string) file_get_contents( $stderr_file ); $stderr = $stderr ? ': ' . $stderr : ''; + // Clean up temporary files. + unlink( $stdout_file ); + unlink( $stderr_file ); } else { $stderr = is_resource( $pipes[2] ) ? ( ': ' . stream_get_contents( $pipes[2] ) ) : ''; } From e6ac3266a11ac9c297499e356405df35fcd47156 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:41:03 +0000 Subject: [PATCH 3/6] Use error suppression for unlink calls to handle edge cases Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Context/FeatureContext.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index c50c8920..cc3ba2e0 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -1356,8 +1356,8 @@ public function background_proc( $cmd ): void { $stderr = (string) file_get_contents( $stderr_file ); $stderr = $stderr ? ': ' . $stderr : ''; // Clean up temporary files. - unlink( $stdout_file ); - unlink( $stderr_file ); + @unlink( $stdout_file ); + @unlink( $stderr_file ); } else { $stderr = is_resource( $pipes[2] ) ? ( ': ' . stream_get_contents( $pipes[2] ) ) : ''; } From c486b92a38f4cd864b36bb97125b49bfbc32fc35 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:41:54 +0000 Subject: [PATCH 4/6] Use explicit file_exists checks before cleanup Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Context/FeatureContext.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index cc3ba2e0..fde4d352 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -1356,8 +1356,12 @@ public function background_proc( $cmd ): void { $stderr = (string) file_get_contents( $stderr_file ); $stderr = $stderr ? ': ' . $stderr : ''; // Clean up temporary files. - @unlink( $stdout_file ); - @unlink( $stderr_file ); + if ( file_exists( $stdout_file ) ) { + unlink( $stdout_file ); + } + if ( file_exists( $stderr_file ) ) { + unlink( $stderr_file ); + } } else { $stderr = is_resource( $pipes[2] ) ? ( ': ' . stream_get_contents( $pipes[2] ) ) : ''; } From 2be017bfe547c124e1472b510315ff8a338c2644 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:43:29 +0000 Subject: [PATCH 5/6] Track and cleanup temporary files for all background processes Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Context/FeatureContext.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index fde4d352..e78f868c 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -133,6 +133,13 @@ class FeatureContext implements Context { */ private $running_procs = []; + /** + * Array of temporary file paths created for background processes on Windows. Used to clean them up at the end of the scenario. + * + * @var array + */ + private $temp_files = []; + /** * Array of variables available as {VARIABLE_NAME}. Some are always set: CORE_CONFIG_SETTINGS, DB_USER, DB_PASSWORD, DB_HOST, SRC_DIR, CACHE_DIR, WP_VERSION-version-latest. * Some are step-dependent: RUN_DIR, SUITE_CACHE_DIR, COMPOSER_LOCAL_REPOSITORY, PHAR_PATH. One is set on use: INVOKE_WP_CLI_WITH_PHP_ARGS-args. @@ -767,6 +774,14 @@ public function afterScenario( AfterScenarioScope $scope ): void { self::terminate_proc( $status['pid'] ); } + // Clean up temporary files created for background processes on Windows. + foreach ( $this->temp_files as $temp_file ) { + if ( file_exists( $temp_file ) ) { + unlink( $temp_file ); + } + } + $this->temp_files = []; + if ( self::$log_run_times ) { self::log_run_times_after_scenario( $scope ); } @@ -1369,6 +1384,12 @@ public function background_proc( $cmd ): void { } $this->running_procs[] = $proc; + + // Track temporary files for cleanup at the end of the scenario. + if ( Utils\is_windows() ) { + $this->temp_files[] = $stdout_file; + $this->temp_files[] = $stderr_file; + } } /** From 0b2ca972947cb6d185c160d44327411239660d78 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:45:07 +0000 Subject: [PATCH 6/6] Refactor: Extract cleanup logic into helper method Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Context/FeatureContext.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index e78f868c..fa9caf72 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -775,11 +775,7 @@ public function afterScenario( AfterScenarioScope $scope ): void { } // Clean up temporary files created for background processes on Windows. - foreach ( $this->temp_files as $temp_file ) { - if ( file_exists( $temp_file ) ) { - unlink( $temp_file ); - } - } + $this->cleanup_temp_files( ...$this->temp_files ); $this->temp_files = []; if ( self::$log_run_times ) { @@ -1371,12 +1367,7 @@ public function background_proc( $cmd ): void { $stderr = (string) file_get_contents( $stderr_file ); $stderr = $stderr ? ': ' . $stderr : ''; // Clean up temporary files. - if ( file_exists( $stdout_file ) ) { - unlink( $stdout_file ); - } - if ( file_exists( $stderr_file ) ) { - unlink( $stderr_file ); - } + $this->cleanup_temp_files( $stdout_file, $stderr_file ); } else { $stderr = is_resource( $pipes[2] ) ? ( ': ' . stream_get_contents( $pipes[2] ) ) : ''; } @@ -1392,6 +1383,19 @@ public function background_proc( $cmd ): void { } } + /** + * Clean up temporary files safely. + * + * @param string ...$files File paths to clean up. + */ + private function cleanup_temp_files( ...$files ): void { + foreach ( $files as $file ) { + if ( file_exists( $file ) ) { + unlink( $file ); + } + } + } + /** * @param string $src * @param string $dest