Repository navigation
Abilities API: Stop the core abilities tests leaking hooks into later tests - #14054
jorgefilipecosta wants to merge 1 commit into
Conversation
…egister them `set_up_before_class()` removed the test suite's unhook callbacks and added the core registration callbacks, and only `tear_down_after_class()` put the unhook callbacks back. The first test of a run snapshots the hooks that every test is reset to, so when this class ran first, the changed hooks leaked into the rest of the run: later tests registered the core abilities whenever the registry initialized, and `test_get_existing_ability_using_callback` failed because the `site` category was not registered. The hooks are now restored as soon as the core abilities are registered.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Trac Ticket MissingThis pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook. |
huzaifaalmesbah
left a comment
There was a problem hiding this comment.
Thanks for working on this, @jorgefilipecosta, and for the clear reverse-order reproduction! This same leak was fixed on trunk in r64266 and r64362 under #65893: set_up_before_class() now calls wp_register_core_ability_categories() and wp_register_core_abilities() directly and no longer touches the hooks, which is why this branch now conflicts. Could you check whether this PR is still needed, or whether only the core/content-query test class in #12195 still needs the change?
AI Review: Opus 5.5
|
Hi @huzaifaalmesbah, thank you! You are right, https://core.trac.wordpress.org/changeset/64266 and https://core.trac.wordpress.org/changeset/64362 fixed the leak in this class, and the |
Tests_Abilities_API_WpRegisterCoreAbilitieschanges hooks inset_up_before_class()to register the core abilities, and only restores them intear_down_after_class(). The first test of a run snapshots the hooks that every test is reset to, so when this class runs first, every later test registers the core abilities whenever the abilities registry initializes.set_up_before_class()as soon as the core abilities are registered, instead of intear_down_after_class().core/content-queryin Abilities API: Add acore/content-queryability #12195, whose REST test class copied the pattern and gets the same fix there.Testing Instructions
On trunk, this run puts the class first, and
test_get_existing_ability_using_callbackfails withAbility category "site" is not registered. With this PR it passes:Verify unit tests are passing in random order:
Trac ticket: to be filed
Use of AI Tools
AI assistance: Yes. Claude Code found the leak while porting
core/content-queryand drafted this fix.This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.