From 252e0e7126d3685812922813decd7e82329dc072 Mon Sep 17 00:00:00 2001 From: Kamran Abdul Aziz Date: Fri, 11 Sep 2026 15:56:15 +0530 Subject: [PATCH] Keep the test suite's temp files inside the test directory The generated wp-tests-config.php now defines WP_TEMP_DIR as a wp-temp directory next to the config file and creates it on load. Core's get_temp_dir() checks that constant first, so the test suite stops writing into the shared system temp directory, where fixed file names and setUp cleanup globs let concurrent runs delete or overwrite each other's files. The path is anchored to the config file's location, so it stays correct when the config is copied to a remote test environment, and cleanup removes it together with the test directory. Concurrent runs stay isolated when each run uses its own WPT_TEST_DIR, which the README already recommends; the README now notes that the suite's temp files live inside that directory. --- README.md | 4 +++- prepare.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 73917db..e7eabe1 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,8 @@ export WPT_TEST_DIR=wp-test-runner-$TRAVIS_BUILD_NUMBER export WPT_TABLE_PREFIX=wptests_$TRAVIS_BUILD_NUMBER\_ ``` +The test suite's temporary files are kept in a `wp-temp` directory inside the test directory, so runs with their own `WPT_TEST_DIR` do not share the system temp directory. + Connect to a remote environment over SSH by having the CI job provision the SSH key: ```bash @@ -272,7 +274,7 @@ export WPT_PREPARE_DIR="/tmp/wp-test-runner" **Test directory** -Path to the directory where the WordPress develop checkout can be placed and tests can be run. When running tests in the same environment, set WPT_TEST_DIR to WPT_PREPARE_DIR equally. +Path to the directory where the WordPress develop checkout can be placed and tests can be run. When running tests in the same environment, set WPT_TEST_DIR to WPT_PREPARE_DIR equally. The test suite's temporary files are kept in a `wp-temp` directory inside this path. ``` diff --git a/prepare.php b/prepare.php index 9473ca2..9cf1cc6 100644 --- a/prepare.php +++ b/prepare.php @@ -242,6 +242,34 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve // Replace the placeholders in the wp-tests-config-sample.php file content with actual values. $contents = str_replace( array_keys( $search_replace ), array_values( $search_replace ), $contents ); +/* + * Point the test suite's temporary directory inside the test directory, so + * concurrent runs with their own WPT_TEST_DIR do not share the system temp + * directory. Core's get_temp_dir() checks the WP_TEMP_DIR constant first, + * and several tests write fixed file names into that directory, so two runs + * sharing it can delete or overwrite each other's files mid test. + * + * The path is anchored to the config file's own location, so it stays + * correct after the config is copied to a remote test environment, and the + * directory is removed together with the test directory during cleanup. + */ +$contents .= <<<'WPT_TEMP_DIR_CONFIG' + +if ( ! defined( 'WP_TEMP_DIR' ) ) { + define( 'WP_TEMP_DIR', __DIR__ . '/wp-temp/' ); +} + +if ( ! is_dir( WP_TEMP_DIR ) ) { + mkdir( WP_TEMP_DIR, 0777, true ); +} + +if ( ! is_dir( WP_TEMP_DIR ) || ! is_writable( WP_TEMP_DIR ) ) { + echo 'The temporary directory ' . WP_TEMP_DIR . ' could not be created or is not writable. Fix the permissions on the test directory and run again.' . PHP_EOL; + exit( 1 ); +} + +WPT_TEMP_DIR_CONFIG; + // Write the modified content to the wp-tests-config.php file, which will be used by the test suite. file_put_contents( $runner_vars['WPT_PREPARE_DIR'] . '/wp-tests-config.php', $contents );