Skip to content

Abilities API: Stop the core abilities tests leaking hooks into later tests - #14054

Closed
jorgefilipecosta wants to merge 1 commit into
WordPress:trunkfrom
jorgefilipecosta:fix/core-abilities-test-hooks-leak
Closed

jorgefilipecosta wants to merge 1 commit into
WordPress:trunkfrom
jorgefilipecosta:fix/core-abilities-test-hooks-leak

Conversation

@jorgefilipecosta

Copy link
Copy Markdown
Member

Tests_Abilities_API_WpRegisterCoreAbilities changes hooks in set_up_before_class() to register the core abilities, and only restores them in tear_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.

  • Restores the hooks in set_up_before_class() as soon as the core abilities are registered, instead of in tear_down_after_class().
  • Found while porting core/content-query in Abilities API: Add a core/content-query ability #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_callback fails with Ability category "site" is not registered. With this PR it passes:

npm run test:php -- --filter 'Tests_Abilities_API_WpRegisterCoreAbilities|::test_get_all_categories$|::test_get_existing_ability_using_callback$' --order-by=reverse

Verify unit tests are passing in random order:

npm run test:php -- --group abilities-api --order-by=random

Trac ticket: to be filed

Use of AI Tools

AI assistance: Yes. Claude Code found the leak while porting core/content-query and 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.

…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.
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jorgefilipecosta.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Trac Ticket Missing

This 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 huzaifaalmesbah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jorgefilipecosta

Copy link
Copy Markdown
Member Author

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 core/content-query test classes landed with the same fix in https://core.trac.wordpress.org/changeset/64388, so this PR is no longer needed. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants