Skip to content

Build/Test Tools: Discard stale roles before reinstalling the test tables - #13286

Closed
ekamran wants to merge 1 commit into
WordPress:trunkfrom
ekamran:fix/test-install-stale-roles
Closed

Build/Test Tools: Discard stale roles before reinstalling the test tables#13286
ekamran wants to merge 1 commit into
WordPress:trunkfrom
ekamran:fix/test-install-stale-roles

Conversation

@ekamran

@ekamran ekamran commented Aug 27, 2026

Copy link
Copy Markdown

The test installer loads wp-settings.php before it drops and recreates the test tables, so the global WP_Roles object is created from the previous run's data. populate_roles() then sees the default roles as already existing on that object and writes the stale capabilities back into the fresh tables. Role data from a previous run therefore survives reinstallation until the database is dropped by hand. This affects the Core test installer only, not production WordPress installs.

This change discards the roles object right after the tables are dropped. wp_roles() recreates it lazily inside populate_roles(), which runs after wp_install() has created the fresh tables, so every run starts from the default roles.

Reproduction steps, the full verification list and the same patch as a diff are on the ticket. Verified on single site and multisite install paths, on repeated runs, and end to end on a fresh clone with a new database. WP_TESTS_SKIP_INSTALL=1 behaviour is unchanged.

Trac ticket: https://core.trac.wordpress.org/ticket/65972

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code, Codex (testing and review)
The investigation, verification and final decisions are mine, and I take responsibility for the change.

…bles.

The test installer loads wp-settings.php before dropping the test
tables, so the WP_Roles object is created from the previous run's data.
populate_roles() then sees the default roles as already existing on
that object and writes the stale capabilities back into the fresh
tables. Discarding the object after the tables are dropped makes
wp_roles() recreate it once the new tables exist, so every run starts
from the default roles.

Stale role data in the test database previously survived reinstallation
and caused failures in the capability tests until the database was
dropped by hand.

See #65972.
@github-actions

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 ekamran.

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

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@ekamran

ekamran commented Sep 10, 2026

Copy link
Copy Markdown
Author

@lancewillett @desrosj @lucatume — tagging you as Build/Test Tools maintainers.

This one is the test installer writing the previous run's role data back
into freshly created tables. Same failure hosts have hit since 2020
(phpunit-test-runner#110). 9-line patch, repro steps and full verification
on the Trac ticket — single site, multisite, repeated runs and a fresh clone.

https://core.trac.wordpress.org/ticket/65972

@lancewillett
lancewillett self-requested a review September 10, 2026 20:27

@lancewillett lancewillett 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.

Ready to land. No review blockers.

I tested with local PHPUnit: 753 single-site and 763 multisite tests passed. Confirmed stale-role failures without the patch and successful cleanup with this change.

wporg-sync pushed a commit that referenced this pull request Sep 10, 2026
Discard the roles object loaded before the test tables are dropped. Let WordPress recreate it from the fresh tables so capabilities from a previous test run do not survive reinstallation.

Developed in: #13286

Props ekamran.
Fixes #65972.


git-svn-id: https://develop.svn.wordpress.org/trunk@63590 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 63590
GitHub commit: f8fb8d0

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Sep 10, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Sep 10, 2026
Discard the roles object loaded before the test tables are dropped. Let WordPress recreate it from the fresh tables so capabilities from a previous test run do not survive reinstallation.

Developed in: WordPress/wordpress-develop#13286

Props ekamran.
Fixes #65972.

Built from https://develop.svn.wordpress.org/trunk@63590


git-svn-id: http://core.svn.wordpress.org/trunk@62766 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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