Keep the test suite's temp files inside the test directory - #341
Open
ekamran wants to merge 1 commit into
Open
Conversation
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.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @dankingtech. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #77
The runner never sets
WP_TEMP_DIR, so the WordPress test suite writes its temporary files into the shared system temp directory throughget_temp_dir(). Several tests use fixed file names there, andtests/phpunit/tests/image/functions.phpglob-deleteswordpress-gsoc-flyer*.*insetUp(), so two runs sharing that directory can delete or overwrite each other's files mid test, and files left by one user can break the next user on permissions.This is what #77 reported in 2018, and danielbachhuber suggested the
WP_TEMP_DIRroute in the same thread. The exact file names from the 2018 report have changed in today's suite, but fixed-name writers and the shared directory are still there, and Core'sget_temp_dir()still checksWP_TEMP_DIRfirst.This makes
prepare.phpappend a small block to the generatedwp-tests-config.php: it definesWP_TEMP_DIRas awp-tempdirectory next to the config file, creates it on load, and fails with a clear message if the directory cannot be created or is not writable, instead of silently falling back to the shared system temp. 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 over SSH, and the directory is removed together with the test directory during cleanup. No new environment variable is needed.Concurrent runs are isolated when each run uses its own
WPT_TEST_DIR, which the README's concurrency section already recommends. The README now notes that the suite's temp files live inside that directory.Verification:
wp-tests-config-sample.phppassesphp -l, and including it standalone defines the constant and createswp-tempnext to the config file.get_temp_dir()returns thewp-temppath andwp_tempnam()lands inside it.Tests_Image_Functionsruns green with the redirected temp directory: 100 tests, 4 skipped.mkdir()warning is followed by the clear message and exit code 1. The native warning is kept on purpose, because it carries the exact permission context and WPCS discourages error silencing.php -land PHPCS pass on the touched files.This is independent of #336 and #337 and complements them: force removal, database cleanup, and temp file isolation are three separate cleanup gaps.
Use of AI
AI assistance: Yes
Tool(s): Claude Code and Codex
Used for: Investigation, implementation review, edge-case testing, and PR wording. I reviewed the reasoning and test results, and I take responsibility for the contribution.