Skip to content

Tests: Preserve development state during E2E runs - #16262

Open
ArkaPrabhaChowdhury wants to merge 9 commits into
WordPress:trunkfrom
ArkaPrabhaChowdhury:trac-66227-e2e-state
Open

ArkaPrabhaChowdhury wants to merge 9 commits into
WordPress:trunkfrom
ArkaPrabhaChowdhury:trac-66227-e2e-state

Conversation

@ArkaPrabhaChowdhury

@ArkaPrabhaChowdhury ArkaPrabhaChowdhury commented Nov 26, 2026 •

Copy link
Copy Markdown

Summary

  • Route the E2E host and port to a dedicated wp-config-e2e.php, keeping the development site on its original database configuration.
  • Use a dedicated E2E database, uploads directory, and Memcached service/cache salt. A checkout-wide lock prevents overlapping runs, and saved recovery state restores interrupted runs, including the original table prefix.
  • Require WP_E2E_ISOLATED=true for custom targets and use consistent local-target detection for Docker startup and database setup.
  • Increase the WordPress installation E2E timeout to 30 seconds.

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

Checks

  • npm run test:e2e:config -- 5 passed.
  • Full E2E CI matrix (LOCAL_DIR=build) -- all four serial/parallel jobs passed: 123 tests with SCRIPT_DEBUG enabled and 123 with it disabled.
  • npm run lint:jsdoc -- --no-ignore tests/e2e/config/database.js tests/e2e/config/database.test.cjs tests/e2e/playwright.config.js tests/e2e/utils/wp-cli.js tests/e2e/config/global-teardown.js -- passed.
  • wp-scripts lint-js --no-ignore on touched JavaScript -- passed.
  • git diff --check -- passed.
  • PR workflows: PHPUnit (30 jobs), Code Coverage, JavaScript Tests, JavaScript Type Checking, Coding Standards, Performance (15 jobs), Test Build Processes, and Local Docker Environment -- passed.

Use of AI Tools

  • AI assistance: Yes.
  • Tool(s): OpenAI Codex.
  • Model(s): GPT-6.
  • Used for: Researching Trac #66227, reproducing the test setup, implementing and testing the isolation changes, and drafting this PR. Reviewed and tested by me.

This pull request is for code review only. Please keep other discussion in the Trac ticket. Do not merge this pull request on GitHub.

@github-actions

github-actions Bot commented Nov 26, 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.

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

Props arkaprabhachowdhury, lancewillett.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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

Please rebase onto trunk and give E2E its own database. In an isolated checkout the normal run preserved the development post and comment, but it erased a table in the PHPUnit database. Two overlapping runs also restored the development database while the second run was still active. Please make a second run stop before it changes that shared configuration, or isolate each run completely.

Please also use the checkout’s configured port when checking the target. With a custom port in .env, setup rejected the correct URL and accepted the default port. After rebasing, please verify the existing permalink/404 spec against the fresh site and run the E2E jobs against both src and build.

AI review · gpt-6.2-astra

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

E2E setup can destroy concurrent PHPUnit state and leak cached data into the development site, while also mishandling explicit local URLs and the configured WordPress tree.

4 open issues
What changed in this PR

This PR aims to preserve development data during Core E2E runs by temporarily switching database and uploads settings, then restoring the original configuration.

Changes:

  • Adds configuration snapshots, teardown restoration, and recovery after interrupted runs.
  • Requires explicit isolation confirmation for custom targets and adjusts Docker startup behavior.
  • Adds configuration checks and increases the installation-click timeout to 30 seconds.
File Description
tests/​e2e/​specs/​install.test.js Increases the install-button click timeout.
tests/​e2e/​README.md Documents isolation, restoration, and custom-target requirements.
tests/​e2e/​playwright.config.js Registers teardown and conditionally starts Docker.
tests/​e2e/​config/​global-teardown.js Restores development configuration after E2E runs.
tests/​e2e/​config/​global-setup.js Prepares isolated storage and restores configuration on failure.
tests/​e2e/​config/​database.test.cjs Tests explicit isolation confirmation for custom targets.
tests/​e2e/​config/​database.js Implements database switching, configuration snapshots, and restoration.
package.json Adds configuration checks before the E2E suite.
.gitignore Ignores the E2E uploads directory under src.

Review effort: Balanced

Comment thread tests/e2e/config/database.js Resolved
Comment thread tests/e2e/config/database.js Resolved
Comment thread tests/e2e/config/database.js Resolved
Comment thread tests/e2e/playwright.config.js Resolved
@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.

@ArkaPrabhaChowdhury

Copy link
Copy Markdown
Author

Hi @lancewillett,

Thanks a lot for the review. I have addressed the feedback points. Please do check.

Thank you!

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

The dedicated E2E database preserved a table in the PHPUnit database, and a second process was refused before it changed configuration. The custom port worked. On build, all 123 Playwright tests passed. On src, all four cases in the 404/cache-header and installation specs passed. The three config tests passed. I confirmed the current trunk merges cleanly, so the earlier rebase request is addressed.

I’m keeping the change request on 40a4e2a for these findings:

  • The normal development login URL served the E2E site during the run. Please give E2E its own site configuration so the development URL stays attached to its database throughout.
  • I simulated an interruption at the install spec’s table-prefix switch. Recovery restored DB_NAME but left wp_e2e_, and the next run failed because WordPress appeared uninstalled. Restoring only the original prefix made it pass. A stale recovery marker also blocked recovery and left the development URL on the E2E database.
  • With the bundled Memcached drop-in enabled, a development cache key survived across WP-CLI processes before setup and was gone afterward. The installer flushes the Memcached server, which also evicts keys under the development salt. Please isolate the cache along with the database.
  • JSDoc lint fails in the new global-teardown.js because its config parameter is undocumented.

AI review · gpt-6.2-sol

@ArkaPrabhaChowdhury

Copy link
Copy Markdown
Author

Hi @lancewillett, Thanks for the review again. I have addressed the feedback and requested re-review. Thank you!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment on lines +335 to +339
wpCli(
[ 'config', 'set', 'DB_NAME', E2E_DB_NAME, '--type=constant' ],
localDir,
temporaryConfigFile
);
Comment on lines +340 to +343
wpCli(
[ 'config', 'set', 'UPLOADS', E2E_UPLOADS, '--type=constant' ],
localDir,
temporaryConfigFile
Comment on lines +340 to +344
wpCli(
[ 'config', 'set', 'UPLOADS', E2E_UPLOADS, '--type=constant' ],
localDir,
temporaryConfigFile
);
configurationMayBeMutated = false;
}

const localDir = getLocalDir();
Comment thread tests/e2e/utils/wp-cli.js
Comment on lines +26 to +28
const configArgs = isDefaultEnvironment( baseURL )
? [ '--env', 'WP_CONFIG_PATH=/var/www/wp-config-e2e.php' ]
: [];
const temporaryConfigPath = path.join( process.cwd(), temporaryConfigFile );
await copyFile( rootConfigPath, temporaryConfigPath );

try {
local_env_utils.ensure_env_file();

dotenvExpand.expand( dotenv.config() );
process.env.LOCAL_E2E_PORT ||= String( Number( process.env.LOCAL_PORT || 8889 ) + 1 );

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

The default two-port setup kept the development and E2E sites on separate databases. The PHPUnit table and development Memcached key survived. A second process was refused, and recovery discarded the interrupted install prefix and stale recovery marker. Five focused browser cases passed locally on src, and the four build E2E jobs passed in CI. The config tests and JSDoc lint passed.

I’m keeping the change request because development still depends on files the tests change:

  • The existing maintenance test’s file returned HTTP 503 on both ports. Please give E2E a separate document tree or otherwise scope that fixture to E2E.
  • With a valid document-root wp-config.php present, the E2E port served the development site even after the separate database was installed. Global setup would then send its cleanup requests there. Please verify the HTTP target is isolated before cleanup.
  • The copied WP_HOME and WP_SITEURL kept the E2E site on the development URL. The router also made a valid development config with declare(strict_types=1) fail PHP lint and prevented either login page from loading. Please avoid rewriting the development config or preserve its PHP structure and use E2E-specific URL settings.

AI review · gpt-6.2-sol

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.

3 participants