fix(checker): clean up runtime on failure - #1416
Open
faisalahammad wants to merge 5 commits into
Open
Conversation
- Run the cleanup cascade in Abstract_Check_Runner::run() from a finally block so runtime tables and the object-cache drop-in are removed even when a check throws. - Add Runtime_Environment_Setup::cleanup_if_set_up() helper. - Clean up leftover runtime state on plugin deactivation. - Add uninstall.php to clean up runtime state on plugin deletion. Fixes WordPress#183
|
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 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. |
- Register 'empty-check' slug used by Abstract_Check_Runner_Tests_Runner via the wp_plugin_check_checks filter, so Default_Check_Repository does not throw Invalid_Check_Slug_Exception when Abstract_Check_Runner::run() calls get_checks_to_run(). - Run Uninstall_Tests::test_uninstall_drops_runtime_tables_and_drop_in and test_uninstall_no_op_when_runtime_not_set_up in separate processes, since WP_PLUGIN_CHECK_OBJECT_CACHE_DROPIN_VERSION defined by other test classes in the same PHPUnit process (e.g. Runtime_Environment_Setup_Tests) leaked into these tests and caused Runtime_Environment_Setup::set_up() to bail out early.
…ontext Abstract_Check_Runner::run() calls set_ai_analysis()/set_ai_stats() on the value returned by get_checks_instance()->run_checks(). The default stub in Abstract_Check_Runner_Tests_Runner returned the raw Check_Context argument, which has no such methods, causing a fatal error on PHP 8.1+ where undefined method calls are not silently ignored in certain error handling paths used by PHPUnit.
…s can override it; fix PHPCS FQN violation get_shared_preparations() was declared private on Abstract_Check_Runner, so the override in Abstract_Check_Runner_Tests_Runner (a subclass) was never actually invoked by run() — PHP resolves private method calls statically to the declaring class, not polymorphically. This caused the test's synthetic cleanup cascade to never run, making assertions like 'cleanup fires after successful run' fail with 0 !== 1. No other code depends on this method being private; all sibling hook methods on this abstract class (allow_runtime_checks, initialize_runtime, should_use_ai, etc.) are already protected. Also switch the Check_Result reference in the test runner stub to a use statement to satisfy SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName.
Production run() only isolates failures between top-level shared- preparation entries (each prepare() closure gets its own try/catch in the finally cleanup cascade). The test harness previously bundled all recorded cleanups into a single preparation whose closure iterated them in an inner foreach with no isolation, so the 'second cleanup ran despite first throwing' assertion in test_cleanup_cascade_continues_when_cleanup_throws was not actually exercising the production isolation behavior and failed intermittently depending on unrelated shared state. Register one preparation per recorded cleanup instead.
davidperezgar
requested review from
ernilambar,
frantorres and
mukeshpanchal27
August 23, 2026 15:30
Member
|
See #183 (comment) |
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.
What?
Closes #183
Why?
Runtime checks install a parallel WordPress database (pc_-prefixed tables) and an object-cache.php drop-in. Cleanup only ran on the happy path, so any check that threw or any request that orphaned state left those tables behind.
How?
Testing Instructions
See TESTING_INSTRUCTIONS.md in the PR diff for manual scenarios (happy path, interrupted AJAX, uninstall, CLI exception). Automated tests in tests/phpunit/tests/Checker/ and tests/phpunit/tests/Installer/.
Screenshots or screencast