From 17e444536ed4c540e3308a042fb037833e45c28c Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 11 Nov 2026 13:17:59 -0600 Subject: [PATCH 01/34] Admin shell e2e: Run the regression suite in CI Add a matrix entry that runs the suite on PRs touching admin-ui, My Jetpack, Forms or the suite itself, against the e2e Docker site with the shell on and then off. Build admin-ui for the jetpack-core e2e group, since the shell client never loads without it. --- .github/files/e2e-tests/e2e-matrix.js | 8 +++++ .github/workflows/e2e-tests.yml | 3 +- .../jetpack/changelog/add-admin-shell-e2e-ci | 5 +++ projects/plugins/jetpack/tests/e2e/README.md | 2 ++ .../jetpack/tests/e2e/bin/admin-shell-ci.sh | 31 +++++++++++++++++++ .../plugins/jetpack/tests/e2e/package.json | 3 +- .../e2e/playwright.admin-shell.config.ts | 8 +++-- .../tests/e2e/plugins/e2e-admin-shell.php | 14 +++++++++ tools/cli/commands/dependencies.js | 2 ++ .../docker/jetpack-docker-config-default.yml | 1 + 10 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/add-admin-shell-e2e-ci create mode 100755 projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh create mode 100644 projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index b2dd5eee0af6..5276c1167a21 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -37,6 +37,14 @@ const projects = [ targets: [ 'plugins/jetpack', 'packages/comments' ], buildGroup: 'jetpack-core', }, + { + project: 'Jetpack admin shell', + path: 'projects/plugins/jetpack/tests/e2e', + testScript: 'test:admin-shell:ci', + testArgs: [], + targets: [ 'packages/admin-ui', 'packages/my-jetpack', 'packages/forms' ], + buildGroup: 'jetpack-core', + }, { project: 'Jetpack sync', path: 'projects/plugins/jetpack/tests/e2e', diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 993221c01ca3..cc26d909a96c 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -263,9 +263,10 @@ jobs: working-directory: ${{ matrix.path }} env: JSON_ARGS: ${{ toJSON(matrix.testArgs) }} + TEST_SCRIPT: ${{ matrix.testScript || 'test:run' }} run: | mapfile -t TEST_ARGS < <(jq -r '.[]' <<<"$JSON_ARGS") - pnpm run test:run "${TEST_ARGS[@]}" + pnpm run "$TEST_SCRIPT" "${TEST_ARGS[@]}" - name: Test environment tear-down if: ${{ always() }} diff --git a/projects/plugins/jetpack/changelog/add-admin-shell-e2e-ci b/projects/plugins/jetpack/changelog/add-admin-shell-e2e-ci new file mode 100644 index 000000000000..34d942df6017 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-admin-shell-e2e-ci @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Run the admin shell e2e suite in CI. + + diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index fc9e0f8bacbe..b6d1b918a5b5 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -159,6 +159,8 @@ pnpm test:admin-shell Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. +In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch `admin-ui`, My Jetpack, Forms or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`: with the `e2e-admin-shell` plugin active for the shell-on projects, then deactivated for the shell-off smoke. The standalone projects don't run in CI. + Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. ## CI Configuration diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh new file mode 100755 index 000000000000..9897292f2540 --- /dev/null +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# Runs the admin shell suite against the e2e Docker site from `pnpm env:up`: shell on, then shell off. +# Extra arguments go to both Playwright runs. + +set -uo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." || exit 1 + +WP=( pnpm jetpack docker --type e2e --name t1 wp -- ) + +ADMIN_SHELL_USER=$( node -p 'require( "./config/local.cjs" ).testSites.default.username' ) || exit 1 +ADMIN_SHELL_PASSWORD=$( node -p 'require( "./config/local.cjs" ).testSites.default.password' ) || exit 1 +export ADMIN_SHELL_URL=http://localhost:8889 ADMIN_SHELL_USER ADMIN_SHELL_PASSWORD + +playwright install --with-deps chromium firefox webkit || exit 1 + +STATUS=0 + +echo "::group::Shell on" +"${WP[@]}" plugin activate e2e-admin-shell || exit 1 +ADMIN_SHELL_RUN=shell-on playwright test -c playwright.admin-shell.config.ts --project='shell on: *' "$@" || STATUS=1 +echo "::endgroup::" + +echo "::group::Shell off" +"${WP[@]}" plugin deactivate e2e-admin-shell || exit 1 +ADMIN_SHELL_RUN=shell-off ADMIN_SHELL_OFF_URL="$ADMIN_SHELL_URL" \ + ADMIN_SHELL_OFF_USER="$ADMIN_SHELL_USER" ADMIN_SHELL_OFF_PASSWORD="$ADMIN_SHELL_PASSWORD" \ + playwright test -c playwright.admin-shell.config.ts --project='shell off: *' "$@" || STATUS=1 +echo "::endgroup::" + +exit $STATUS diff --git a/projects/plugins/jetpack/tests/e2e/package.json b/projects/plugins/jetpack/tests/e2e/package.json index ab245c4862d9..ee16729d49cb 100644 --- a/projects/plugins/jetpack/tests/e2e/package.json +++ b/projects/plugins/jetpack/tests/e2e/package.json @@ -2,7 +2,7 @@ "private": true, "type": "module", "scripts": { - "build": "pnpm jetpack build packages/my-jetpack js-packages/social-logos js-packages/boost-score-api js-packages/components js-packages/number-formatters js-packages/charts js-packages/social-previews packages/wp-build-polyfills packages/forms packages/comments packages/assets packages/connection packages/publicize packages/blaze js-packages/ai-client plugins/jetpack -v --no-pnpm-install --production", + "build": "pnpm jetpack build packages/my-jetpack js-packages/social-logos js-packages/boost-score-api js-packages/components js-packages/number-formatters js-packages/charts js-packages/social-previews packages/admin-ui packages/wp-build-polyfills packages/forms packages/comments packages/assets packages/connection packages/publicize packages/blaze js-packages/ai-client plugins/jetpack -v --no-pnpm-install --production", "clean": "rm -rf output", "config:decrypt": "pnpm test-decrypt-default-config && pnpm test-decrypt-config", "distclean": "rm -rf node_modules", @@ -12,6 +12,7 @@ "env:reset": "e2e-env reset", "env:up": "e2e-env start", "test:admin-shell": "playwright install chromium firefox webkit && playwright test -c playwright.admin-shell.config.ts", + "test:admin-shell:ci": "pnpm run clean && bin/admin-shell-ci.sh", "pretest:run": "pnpm run clean", "test:run": "playwright install chromium && NODE_CONFIG_DIR='./config' NODE_PATH=\"$PWD/node_modules\" playwright test", "test-decrypt-all-config": "pnpm test-decrypt-default-config && pnpm test-decrypt-config", diff --git a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts index 9feb36387d58..022e45423f28 100644 --- a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts +++ b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts @@ -9,6 +9,10 @@ const onUrl = process.env.ADMIN_SHELL_URL ?? 'http://localhost:8889'; const offUrl = process.env.ADMIN_SHELL_OFF_URL; const standaloneUrl = process.env.ADMIN_SHELL_STANDALONE_URL; const stateDir = 'output/admin-shell'; +// Separate runs against one site (shell on, then off) each need their own results. +const runDir = process.env.ADMIN_SHELL_RUN + ? `${ stateDir }/${ process.env.ADMIN_SHELL_RUN }` + : stateDir; const browsers = [ { name: 'chromium', use: devices[ 'Desktop Chrome' ] }, @@ -18,13 +22,13 @@ const browsers = [ export default defineConfig( { testDir: './specs/admin-shell', - outputDir: `${ stateDir }/results`, + outputDir: `${ runDir }/results`, timeout: 180000, expect: { timeout: 20000 }, // Only login and tests wrapped in intermittentSpikeBug() retry; any other flake fails the run. retries: 0, workers: Number( process.env.PLAYWRIGHT_WORKERS ) || 2, - reporter: [ [ 'list' ], [ 'json', { outputFile: `${ stateDir }/summary.json` } ] ], + reporter: [ [ 'list' ], [ 'json', { outputFile: `${ runDir }/summary.json` } ] ], use: { viewport: { width: 1280, height: 1600 }, ignoreHTTPSErrors: true, diff --git a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php new file mode 100644 index 000000000000..e0f24a672e7c --- /dev/null +++ b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php @@ -0,0 +1,14 @@ + [projects...]'; diff --git a/tools/docker/jetpack-docker-config-default.yml b/tools/docker/jetpack-docker-config-default.yml index 3cb77ea5d8ca..1e4032538938 100644 --- a/tools/docker/jetpack-docker-config-default.yml +++ b/tools/docker/jetpack-docker-config-default.yml @@ -76,6 +76,7 @@ e2e: projects/plugins/boost/tests/e2e/plugins/e2e-critical-css-force-errors.php: /var/www/html/wp-content/plugins/e2e-critical-css-force-errors.php projects/plugins/boost/tests/e2e/plugins/e2e-dashboard-modernization.php: /var/www/html/wp-content/plugins/e2e-dashboard-modernization.php projects/plugins/boost/tests/e2e/plugins/e2e-dashboard-jitm.php: /var/www/html/wp-content/plugins/e2e-dashboard-jitm.php + projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php: /var/www/html/wp-content/plugins/e2e-admin-shell.php projects/plugins/paypal-payment-buttons/tests/e2e/plugins/e2e-paypal-feature-flag.php: /var/www/html/wp-content/plugins/e2e-paypal-feature-flag.php projects/plugins/premium-analytics/tests/e2e/plugins/e2e-premium-analytics-helper/: /var/www/html/wp-content/plugins/e2e-premium-analytics-helper/ tools/e2e-commons/plugins/e2e-search-test-helper.php: /var/www/html/wp-content/plugins/e2e-search-test-helper.php From f3aa11000d7e421f3a49315f007fa59bddeaa68c Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 11 Nov 2026 13:31:12 -0600 Subject: [PATCH 02/34] Admin shell e2e: Trigger on suite paths and activate Forms in CI Spec-only PRs now select the admin shell entry by changed path instead of mapping suite files to admin-ui, which every e2e plugin depends on and so ran the whole matrix. The runner activates the contact-form module, since the unconnected CI site never auto-activates it, and the README names the decrypted-config prerequisite. --- .github/files/e2e-tests/e2e-matrix.js | 28 ++++++++++++++++++- projects/plugins/jetpack/tests/e2e/README.md | 2 +- .../jetpack/tests/e2e/bin/admin-shell-ci.sh | 3 ++ tools/cli/commands/dependencies.js | 2 -- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index 5276c1167a21..20537ed31e87 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -1,4 +1,4 @@ -const { execSync } = require( 'child_process' ); +const { execFileSync, execSync } = require( 'child_process' ); const fs = require( 'fs' ); const projects = [ @@ -43,6 +43,8 @@ const projects = [ testScript: 'test:admin-shell:ci', testArgs: [], targets: [ 'packages/admin-ui', 'packages/my-jetpack', 'packages/forms' ], + // Also run when a PR changes the suite itself, without fanning out to everything that depends on admin-ui. + paths: [ /^projects\/plugins\/jetpack\/tests\/e2e\/.*admin-shell/ ], buildGroup: 'jetpack-core', }, { @@ -180,6 +182,24 @@ function minWpVersion() { return match[ 1 ]; } +/** + * Files the pull request changes. + * + * @return {string[]} Paths, or an empty list outside a pull request. + */ +function prChangedFiles() { + if ( process.env.GITHUB_EVENT_NAME !== 'pull_request' ) { + return []; + } + const { base, head } = JSON.parse( + fs.readFileSync( process.env.GITHUB_EVENT_PATH, 'utf8' ) + ).pull_request; + return execFileSync( 'git', [ 'diff', '--name-only', `${ base.sha }...${ head.sha }` ] ) + .toString() + .split( '\n' ) + .filter( Boolean ); +} + const matrix = []; /** @@ -204,8 +224,14 @@ switch ( process.env.GITHUB_EVENT_NAME ) { ); const dependencyCache = new Map(); + const changedFiles = prChangedFiles(); for ( const project of projects ) { + if ( project.paths?.some( re => changedFiles.some( f => re.test( f ) ) ) ) { + pushBothVersions( project ); + continue; + } + if ( ! project.targets ) { // If no targets are defined, run the tests pushBothVersions( project ); diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index b6d1b918a5b5..35c4d817a966 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -159,7 +159,7 @@ pnpm test:admin-shell Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. -In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch `admin-ui`, My Jetpack, Forms or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`: with the `e2e-admin-shell` plugin active for the shell-on projects, then deactivated for the shell-off smoke. The standalone projects don't run in CI. +In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch `admin-ui`, My Jetpack, Forms or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`): with the `e2e-admin-shell` plugin active for the shell-on projects, then deactivated for the shell-off smoke. The standalone projects don't run in CI. Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index 9897292f2540..cf9c65fcccad 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -14,6 +14,9 @@ export ADMIN_SHELL_URL=http://localhost:8889 ADMIN_SHELL_USER ADMIN_SHELL_PASSWO playwright install --with-deps chromium firefox webkit || exit 1 +# The site is never connected, so default modules (including the Forms member) aren't auto-activated. +"${WP[@]}" jetpack module activate contact-form || exit 1 + STATUS=0 echo "::group::Shell on" diff --git a/tools/cli/commands/dependencies.js b/tools/cli/commands/dependencies.js index 7032fc8cb26b..bc451bd59d4a 100644 --- a/tools/cli/commands/dependencies.js +++ b/tools/cli/commands/dependencies.js @@ -60,8 +60,6 @@ const extraFileSets = {}; extraFileSets.base = {}; extraFileSets.e2e = { '^projects/plugins/jetpack/tests/e2e/specs/sync/': [ 'packages/sync' ], - '^projects/plugins/jetpack/tests/e2e/(specs/admin-shell/|helpers/admin-shell-helper|bin/admin-shell-ci|plugins/e2e-admin-shell|playwright\\.admin-shell\\.)': - [ 'packages/admin-ui' ], }; export const command = 'dependencies [projects...]'; From 9c7cdeb8ccd4d53a30310718fe07b5f78b0a5b8b Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 11 Nov 2026 13:35:21 -0600 Subject: [PATCH 03/34] Admin shell e2e: Send CI results to the CTRF report and annotate PRs In CI the admin shell config adds the CTRF and github reporters the other e2e suites use, writing each run's CTRF file to its own folder. The runner no longer exports the site URL for the shell-on run and leaves that to the config default. --- .../jetpack/tests/e2e/bin/admin-shell-ci.sh | 6 +++-- .../e2e/playwright.admin-shell.config.ts | 26 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index cf9c65fcccad..07ffeccf3665 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -10,7 +10,9 @@ WP=( pnpm jetpack docker --type e2e --name t1 wp -- ) ADMIN_SHELL_USER=$( node -p 'require( "./config/local.cjs" ).testSites.default.username' ) || exit 1 ADMIN_SHELL_PASSWORD=$( node -p 'require( "./config/local.cjs" ).testSites.default.password' ) || exit 1 -export ADMIN_SHELL_URL=http://localhost:8889 ADMIN_SHELL_USER ADMIN_SHELL_PASSWORD +export ADMIN_SHELL_USER ADMIN_SHELL_PASSWORD +# The shell-off run points ADMIN_SHELL_OFF_URL at the same site; this matches the config's default. +SITE_URL=${ADMIN_SHELL_URL:-http://localhost:8889} playwright install --with-deps chromium firefox webkit || exit 1 @@ -26,7 +28,7 @@ echo "::endgroup::" echo "::group::Shell off" "${WP[@]}" plugin deactivate e2e-admin-shell || exit 1 -ADMIN_SHELL_RUN=shell-off ADMIN_SHELL_OFF_URL="$ADMIN_SHELL_URL" \ +ADMIN_SHELL_RUN=shell-off ADMIN_SHELL_OFF_URL="$SITE_URL" \ ADMIN_SHELL_OFF_USER="$ADMIN_SHELL_USER" ADMIN_SHELL_OFF_PASSWORD="$ADMIN_SHELL_PASSWORD" \ playwright test -c playwright.admin-shell.config.ts --project='shell off: *' "$@" || STATUS=1 echo "::endgroup::" diff --git a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts index 022e45423f28..6611e0c6e3ee 100644 --- a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts +++ b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts @@ -1,4 +1,4 @@ -import { defineConfig, devices } from '@playwright/test'; +import { defineConfig, devices, type ReporterDescription } from '@playwright/test'; import { STATE_OFF, STATE_ON, STATE_STANDALONE } from './helpers/admin-shell-helper'; /* @@ -14,6 +14,28 @@ const runDir = process.env.ADMIN_SHELL_RUN ? `${ stateDir }/${ process.env.ADMIN_SHELL_RUN }` : stateDir; +const reporter: ReporterDescription[] = [ + [ 'list' ], + [ 'json', { outputFile: `${ runDir }/summary.json` } ], +]; +// Same CI reporters as tools/e2e-commons/playwright.config.default.ts: the shared CTRF report and PR annotations. +if ( process.env.CI ) { + reporter.push( + [ + 'playwright-ctrf-json-reporter', + { + outputDir: runDir, + outputFile: `ctrf-report-${ Date.now() }.json`, + branchName: process.env.GITHUB_REF_NAME || '', + commit: process.env.GITHUB_SHA || '', + appName: 'jetpack', + repositoryName: process.env.GITHUB_REPOSITORY || '', + }, + ], + [ 'github' ] + ); +} + const browsers = [ { name: 'chromium', use: devices[ 'Desktop Chrome' ] }, { name: 'firefox', use: devices[ 'Desktop Firefox' ] }, @@ -28,7 +50,7 @@ export default defineConfig( { // Only login and tests wrapped in intermittentSpikeBug() retry; any other flake fails the run. retries: 0, workers: Number( process.env.PLAYWRIGHT_WORKERS ) || 2, - reporter: [ [ 'list' ], [ 'json', { outputFile: `${ runDir }/summary.json` } ] ], + reporter, use: { viewport: { width: 1280, height: 1600 }, ignoreHTTPSErrors: true, From a61984a132be6e87134e39209a215af39ee85a72 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 11 Nov 2026 13:59:43 -0600 Subject: [PATCH 04/34] Admin shell e2e: Cover Jetpack AI, Settings and Podcast, and the stale nonce loop Add the members from PR 54768 that register on the unconnected CI site to the suite, each paired with My Jetpack as host and guest. Activate the Podcast module and build its package in CI. Add a regression for JETPACK-3673: after My Jetpack, Settings and Jetpack AI, a stale REST nonce refreshes once and the request succeeds. Activity Log, Newsletter, Protect and VideoPress need a WordPress.com connection, which the CI site doesn't have. --- .github/files/e2e-tests/e2e-matrix.js | 8 +- projects/plugins/jetpack/tests/e2e/README.md | 2 +- .../jetpack/tests/e2e/bin/admin-shell-ci.sh | 6 +- .../tests/e2e/helpers/admin-shell-helper.ts | 29 ++++++- .../plugins/jetpack/tests/e2e/package.json | 2 +- .../admin-shell/navigation-matrix.test.ts | 9 ++- .../tests/e2e/specs/admin-shell/nonce.test.ts | 76 +++++++++++++++++++ .../e2e/specs/admin-shell/tracks.test.ts | 7 +- 8 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index 20537ed31e87..2d983a5bb8d5 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -42,7 +42,13 @@ const projects = [ path: 'projects/plugins/jetpack/tests/e2e', testScript: 'test:admin-shell:ci', testArgs: [], - targets: [ 'packages/admin-ui', 'packages/my-jetpack', 'packages/forms' ], + targets: [ + 'packages/admin-ui', + 'packages/my-jetpack', + 'packages/forms', + 'packages/podcast', + 'plugins/jetpack', + ], // Also run when a PR changes the suite itself, without fanning out to everything that depends on admin-ui. paths: [ /^projects\/plugins\/jetpack\/tests\/e2e\/.*admin-shell/ ], buildGroup: 'jetpack-core', diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index 35c4d817a966..5671f6d88fbd 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -159,7 +159,7 @@ pnpm test:admin-shell Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. -In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch `admin-ui`, My Jetpack, Forms or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`): with the `e2e-admin-shell` plugin active for the shell-on projects, then deactivated for the shell-off smoke. The standalone projects don't run in CI. +In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch `admin-ui`, My Jetpack, Forms, Podcast, the Jetpack plugin or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then runs the suite with the `e2e-admin-shell` plugin active for the shell-on projects, then deactivated for the shell-off smoke. The standalone projects don't run in CI. Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index 07ffeccf3665..9fba3dd66410 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -16,8 +16,10 @@ SITE_URL=${ADMIN_SHELL_URL:-http://localhost:8889} playwright install --with-deps chromium firefox webkit || exit 1 -# The site is never connected, so default modules (including the Forms member) aren't auto-activated. -"${WP[@]}" jetpack module activate contact-form || exit 1 +# The site is never connected, so default modules (including the Forms and Podcast members) aren't auto-activated. +for module in contact-form podcast; do + "${WP[@]}" jetpack module activate "$module" || exit 1 +done STATUS=0 diff --git a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts index 4e4e9ab63869..61cdaa1bfcfc 100644 --- a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts +++ b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts @@ -20,8 +20,8 @@ export interface Member { mountId: string; /** `document.title` up to ` ‹`, as a full page load sets it. */ title: string; - /** Visible header text that proves the app rendered. */ - heading: string; + /** Visible header text that proves the app rendered: exact as a string, a match as a RegExp. */ + heading: string | RegExp; /** `search + hash` a fresh load lands on with the shell off. */ landing: RegExp; } @@ -42,6 +42,29 @@ export const MEMBERS: Member[] = [ heading: 'Forms', landing: /^\?page=jetpack-forms-responses-wp-admin&p=%2Fforms$/, }, + { + slug: 'jetpack-ai', + mountId: 'jetpack-ai-hub-wp-admin-app', + title: 'Jetpack AI', + heading: /Jetpack AI/, + landing: /^\?page=jetpack-ai(&p=%2F[^#&]*)?$/, + }, + { + slug: 'jetpack-settings', + mountId: 'jetpack-settings-dashboard-wp-admin-app', + title: 'Settings', + heading: /Settings/, + landing: /^\?page=jetpack-settings(&p=%2F[^#&]*)?$/, + }, + { + slug: 'jetpack-podcast', + mountId: 'jetpack-podcast-dashboard-wp-admin-app', + title: 'Podcast', + heading: /Podcast/, + landing: /^\?page=jetpack-podcast(&p=%2F[^#&]*)?$/, + }, + /* Activity Log, Newsletter, Protect and VideoPress are members too, but each needs a WordPress.com + * connection (their modules don't load in offline mode), and the test site has none. */ ]; export const member = ( slug: string ): Member => { @@ -405,7 +428,7 @@ export async function expectShown( expect( new URL( page.url() ).searchParams.get( 'page' ) ).toBe( slug ); await expect( page - .getByRole( 'heading', { name: m.heading, exact: true } ) + .getByRole( 'heading', { name: m.heading, exact: typeof m.heading === 'string' } ) .filter( { visible: true } ) .first() ).toBeVisible(); diff --git a/projects/plugins/jetpack/tests/e2e/package.json b/projects/plugins/jetpack/tests/e2e/package.json index ee16729d49cb..505a0f854789 100644 --- a/projects/plugins/jetpack/tests/e2e/package.json +++ b/projects/plugins/jetpack/tests/e2e/package.json @@ -2,7 +2,7 @@ "private": true, "type": "module", "scripts": { - "build": "pnpm jetpack build packages/my-jetpack js-packages/social-logos js-packages/boost-score-api js-packages/components js-packages/number-formatters js-packages/charts js-packages/social-previews packages/admin-ui packages/wp-build-polyfills packages/forms packages/comments packages/assets packages/connection packages/publicize packages/blaze js-packages/ai-client plugins/jetpack -v --no-pnpm-install --production", + "build": "pnpm jetpack build packages/my-jetpack js-packages/social-logos js-packages/boost-score-api js-packages/components js-packages/number-formatters js-packages/charts js-packages/social-previews packages/admin-ui packages/wp-build-polyfills packages/forms packages/podcast packages/comments packages/assets packages/connection packages/publicize packages/blaze js-packages/ai-client plugins/jetpack -v --no-pnpm-install --production", "clean": "rm -rf output", "config:decrypt": "pnpm test-decrypt-default-config && pnpm test-decrypt-config", "distclean": "rm -rf node_modules", diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/navigation-matrix.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/navigation-matrix.test.ts index 07f38a72479d..fb2010811e31 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/navigation-matrix.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/navigation-matrix.test.ts @@ -3,14 +3,19 @@ import { MEMBERS, expectShown, installShellProbe, + member, menuLink, openMember, switchTo, where, } from '../../helpers/admin-shell-helper'; -/* Every ordered pair, so each member is tested as the host and as a guest. */ -const pairs = MEMBERS.flatMap( a => MEMBERS.filter( b => b !== a ).map( b => [ a, b ] as const ) ); +/* Each member against My Jetpack, as the host and as a guest; every pair would grow quadratically. */ +const hub = member( 'my-jetpack' ); +const pairs = MEMBERS.filter( m => m !== hub ).flatMap( m => [ + [ hub, m ] as const, + [ m, hub ] as const, +] ); test.describe( 'Admin shell: navigation matrix', () => { test.beforeEach( async ( { page } ) => { diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts new file mode 100644 index 000000000000..9aa118c8f20e --- /dev/null +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts @@ -0,0 +1,76 @@ +import { test, expect, type Page } from '@playwright/test'; +import { + expectShown, + installShellProbe, + openMember, + switchTo, +} from '../../helpers/admin-shell-helper'; + +/** + * Log in again in a second tab, which leaves the first tab's REST nonce stale. + * + * @param page - Page under test; its context gets the new session. + */ +async function logInAgain( page: Page ): Promise< void > { + const tab = await page.context().newPage(); + await tab.goto( '/wp-login.php' ); + const toggle = tab.getByText( 'Log in with username and password' ); + if ( await toggle.isVisible().catch( () => false ) ) { + await toggle.click(); + } + // wp-login.php focuses and selects the username field on a timer, which can clobber the fill. + await expect( async () => { + await tab.locator( '#user_login' ).fill( process.env.ADMIN_SHELL_USER ?? 'admin' ); + await tab.locator( '#user_pass' ).fill( process.env.ADMIN_SHELL_PASSWORD ?? 'password' ); + await expect( tab.locator( '#user_login' ) ).not.toHaveValue( '', { timeout: 1000 } ); + } ).toPass( { timeout: 15000 } ); + await tab.locator( '#wp-submit' ).click(); + await expect( tab.locator( '#wpadminbar' ) ).toBeVisible( { timeout: 60000 } ); + await tab.close(); +} + +/* JETPACK-3673: guests that print wp-api-fetch's inline script used to stack nonce middlewares. */ +test.describe( 'Admin shell: stale REST nonce', () => { + test.beforeEach( async ( { page } ) => { + await installShellProbe( page ); + } ); + + test( 'after My Jetpack → Settings → Jetpack AI, a stale nonce refreshes once', async ( { + page, + } ) => { + await openMember( page, 'my-jetpack' ); + await switchTo( page, 'jetpack-settings' ); + await switchTo( page, 'jetpack-ai' ); + await expectShown( page, 'jetpack-ai' ); + + await logInAgain( page ); + + let refreshes = 0; + page.on( 'request', request => { + if ( /admin-ajax\.php\?(.*&)?action=rest-nonce/.test( request.url() ) ) { + refreshes++; + } + } ); + const result = await page.evaluate( async () => { + const { apiFetch } = ( + window as unknown as { + wp: { apiFetch: ( o: { path: string } ) => Promise< { id: number } > }; + } + ).wp; + // A loop never settles, so give up well before the test timeout. + const timeout = new Promise< string >( resolve => + setTimeout( () => resolve( 'still retrying after 15 s' ), 15000 ) + ); + return Promise.race( [ + apiFetch( { path: '/wp/v2/users/me' } ).then( + user => `user ${ user.id }`, + ( error: { code?: string } ) => `failed: ${ error.code }` + ), + timeout, + ] ); + } ); + + expect( result, 'the request succeeds after the refresh' ).toMatch( /^user \d+$/ ); + expect( refreshes, 'nonce refreshes' ).toBe( 1 ); + } ); +} ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts index 459cb8fabd19..5eafb36655c2 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts @@ -11,6 +11,9 @@ import { const FORMS = 'jetpack-forms-responses-wp-admin'; +/* The other members may record no views on the unconnected test site, which would pass vacuously. */ +const TRACKED = MEMBERS.filter( m => [ 'my-jetpack', FORMS ].includes( m.slug ) ); + /* Tracks calls go out after render, so give each arrival a moment before reading. */ const SETTLE = 5000; @@ -60,8 +63,8 @@ test.describe( 'Admin shell: Tracks page views', () => { await installShellProbe( page ); } ); - for ( const m of MEMBERS ) { - const other = MEMBERS.find( x => x !== m )!.slug; + for ( const m of TRACKED ) { + const other = TRACKED.find( x => x !== m )!.slug; test( `the first switch to ${ m.slug } records the page view a full load does`, async ( { page, From 3ff5c13719bc0db99dc5bf4a601eca1a5fe3c3d6 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 11 Nov 2026 14:26:18 -0600 Subject: [PATCH 05/34] Admin shell e2e: Report why the shell isn't running on a member --- .../tests/e2e/helpers/admin-shell-helper.ts | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts index 61cdaa1bfcfc..32a84c6cd04f 100644 --- a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts +++ b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts @@ -218,12 +218,22 @@ function shellProbe( mountIds: Record< string, string > ) { }; } +const pageErrors = new WeakMap< Page, string[] >(); + /** * Install the shell probe. Call before the first navigation. * * @param page - Page under test. */ export async function installShellProbe( page: Page ): Promise< void > { + const errors: string[] = []; + pageErrors.set( page, errors ); + page.on( 'pageerror', error => errors.push( error.message ) ); + page.on( 'console', message => { + if ( message.type() === 'error' ) { + errors.push( message.text() ); + } + } ); await page.addInitScript( shellProbe, Object.fromEntries( MEMBERS.map( m => [ m.slug, m.mountId ] ) ) @@ -276,7 +286,28 @@ export async function waitForShown( page: Page, slug: string ): Promise< void > export async function openMember( page: Page, slug: string, suffix = '' ): Promise< void > { await page.goto( `/wp-admin/admin.php?page=${ slug }${ suffix }` ); await waitForShown( page, slug ); - await expect.poll( () => isShellActive( page ), 'the shell runs on this document' ).toBe( true ); + const active = await expect + .poll( () => isShellActive( page ) ) + .toBe( true ) + .then( + () => true, + () => false + ); + if ( ! active ) { + // Say why, since every shell-on test fails here alike. + const assets = await page.evaluate( () => ( { + config: !! document.getElementById( 'wp-script-module-data-@automattic/jetpack-admin-shell' ), + client: + document.querySelector< HTMLScriptElement >( 'script[type="module"][src*="admin-shell"]' ) + ?.src ?? null, + } ) ); + throw new Error( + `The shell doesn't run on ${ slug }: ${ JSON.stringify( { + ...assets, + errors: pageErrors.get( page ) ?? [], + } ) }` + ); + } } /** From 2e26e0fc77de7396b98787116bc6720db1f97ae8 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 11 Nov 2026 15:09:59 -0600 Subject: [PATCH 06/34] Admin shell e2e: Take the CI site out of offline mode for the shell-on run The e2e site is on localhost, so Jetpack runs in offline mode, where My Jetpack skips registering as a shell member and the shell never turns on. --- projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php index e0f24a672e7c..f775ed6c8b0d 100644 --- a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php +++ b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php @@ -12,3 +12,6 @@ */ add_filter( 'jetpack_feature_flag_enabled_jetpack-admin-shell', '__return_true' ); + +// The CI site is on localhost, and in offline mode My Jetpack never registers as a shell member. +add_filter( 'jetpack_offline_mode', '__return_false' ); From a53da27163c72f733310c3b397059c921d4acc8a Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 11 Nov 2026 15:28:47 -0600 Subject: [PATCH 07/34] Admin shell e2e: Stub a connection for the CI site Taking the unconnected localhost site out of offline mode alone left only Podcast registered: Forms, Jetpack AI and Settings need a connection or offline mode, and My Jetpack redirects to onboarding. The helper plugin now stubs a connection on activation and fails WordPress.com requests at once, and the shell-off run toggles the flag by option so the two runs differ only by the flag. --- projects/plugins/jetpack/tests/e2e/README.md | 2 +- .../jetpack/tests/e2e/bin/admin-shell-ci.sh | 4 +- .../tests/e2e/plugins/e2e-admin-shell.php | 56 +++++++++++++++++-- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index 5671f6d88fbd..1cba72259614 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -159,7 +159,7 @@ pnpm test:admin-shell Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. -In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch `admin-ui`, My Jetpack, Forms, Podcast, the Jetpack plugin or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then runs the suite with the `e2e-admin-shell` plugin active for the shell-on projects, then deactivated for the shell-off smoke. The standalone projects don't run in CI. +In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch `admin-ui`, My Jetpack, Forms, Podcast, the Jetpack plugin or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then activates the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once. It runs the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index 9fba3dd66410..e4365ec5cf40 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -17,6 +17,7 @@ SITE_URL=${ADMIN_SHELL_URL:-http://localhost:8889} playwright install --with-deps chromium firefox webkit || exit 1 # The site is never connected, so default modules (including the Forms and Podcast members) aren't auto-activated. +# Do this before e2e-admin-shell takes the site out of offline mode, where an unconnected site refuses activation. for module in contact-form podcast; do "${WP[@]}" jetpack module activate "$module" || exit 1 done @@ -25,11 +26,12 @@ STATUS=0 echo "::group::Shell on" "${WP[@]}" plugin activate e2e-admin-shell || exit 1 +"${WP[@]}" option delete e2e_admin_shell_off >/dev/null 2>&1 ADMIN_SHELL_RUN=shell-on playwright test -c playwright.admin-shell.config.ts --project='shell on: *' "$@" || STATUS=1 echo "::endgroup::" echo "::group::Shell off" -"${WP[@]}" plugin deactivate e2e-admin-shell || exit 1 +"${WP[@]}" option update e2e_admin_shell_off 1 || exit 1 ADMIN_SHELL_RUN=shell-off ADMIN_SHELL_OFF_URL="$SITE_URL" \ ADMIN_SHELL_OFF_USER="$ADMIN_SHELL_USER" ADMIN_SHELL_OFF_PASSWORD="$ADMIN_SHELL_PASSWORD" \ playwright test -c playwright.admin-shell.config.ts --project='shell off: *' "$@" || STATUS=1 diff --git a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php index f775ed6c8b0d..e7c1f871b298 100644 --- a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php +++ b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php @@ -6,12 +6,60 @@ * Version: 1.0.0 * Text Domain: jetpack * - * Turns on the admin shell flag for the admin shell suite. Only that suite activates it. + * Sets up the unconnected e2e site for the admin shell suite. Only that suite activates it. * * @package automattic/jetpack */ -add_filter( 'jetpack_feature_flag_enabled_jetpack-admin-shell', '__return_true' ); +// The shell-off run sets this option, so the two runs differ only by the flag. +if ( ! get_option( 'e2e_admin_shell_off' ) ) { + add_filter( 'jetpack_feature_flag_enabled_jetpack-admin-shell', '__return_true' ); +} -// The CI site is on localhost, and in offline mode My Jetpack never registers as a shell member. -add_filter( 'jetpack_offline_mode', '__return_false' ); +// Most members need a connection: keep Jetpack out of localhost's offline mode and stub one on activation. +add_filter( 'jetpack_offline_mode', '__return_false', 99 ); + +register_activation_hook( + __FILE__, + function () { + $admins = get_users( + array( + 'role' => 'administrator', + 'orderby' => 'ID', + 'number' => 1, + 'fields' => 'ID', + ) + ); + $owner = (int) reset( $admins ); + Jetpack_Options::update_options( + array( + 'id' => 123456789, + 'blog_token' => 'e2e.blog', + 'user_tokens' => array( $owner => "e2e.user.$owner" ), + 'master_user' => $owner, + ) + ); + } +); + +register_deactivation_hook( + __FILE__, + function () { + Jetpack_Options::delete_option( array( 'id', 'blog_token', 'user_tokens', 'master_user' ) ); + delete_option( 'e2e_admin_shell_off' ); + } +); + +// The stubbed tokens can't sign requests, so fail WordPress.com calls at once instead of waiting on them. +add_filter( + 'pre_http_request', + function ( $response, $args, $url ) { + $host = (string) wp_parse_url( $url, PHP_URL_HOST ); + if ( preg_match( '/(^|\.)(wordpress|wp)\.com$/', $host ) ) { // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText -- Hostname pattern. + return new WP_Error( 'e2e_admin_shell_offline', 'WordPress.com is unreachable from the admin shell e2e site.' ); + } + return $response; + }, + 10, + 3 +); From 567f6fd06f0a88d5f81cb282973f549a01cee9e3 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 11 Nov 2026 16:12:39 -0600 Subject: [PATCH 08/34] Admin shell e2e: Fix the CI failures from the first run with the shell on - Park the mouse off the admin bar before the first load. It starts on the WordPress logo, whose hover menu covered the Jetpack submenu and timed out sidebar clicks in every browser. - Activate the ai module once the connection is stubbed, so Jetpack AI has its sidebar item. - Expect Settings to land on its HashRouter route. - Mark the Back-with-a-modal announcement test as failing in Firefox and WebKit, where no announcement of My Jetpack is heard. - Share one login helper between the setup and the nonce test, and print the recorded frames when too few were recorded. --- projects/plugins/jetpack/tests/e2e/README.md | 2 +- .../jetpack/tests/e2e/bin/admin-shell-ci.sh | 2 ++ .../tests/e2e/helpers/admin-shell-helper.ts | 31 ++++++++++++++++++- .../specs/admin-shell/accessibility.test.ts | 5 +++ .../tests/e2e/specs/admin-shell/auth.setup.ts | 26 +++++----------- .../e2e/specs/admin-shell/frames.test.ts | 4 ++- .../e2e/specs/admin-shell/kept-state.test.ts | 1 + .../tests/e2e/specs/admin-shell/nonce.test.ts | 19 ++++-------- 8 files changed, 56 insertions(+), 34 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index 1cba72259614..f1e0abe8d7ef 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -159,7 +159,7 @@ pnpm test:admin-shell Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. -In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch `admin-ui`, My Jetpack, Forms, Podcast, the Jetpack plugin or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then activates the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once. It runs the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. +In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index e4365ec5cf40..197481a0e44a 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -26,6 +26,8 @@ STATUS=0 echo "::group::Shell on" "${WP[@]}" plugin activate e2e-admin-shell || exit 1 +# Jetpack AI's sidebar item shows only with the ai module on, and it needs the stubbed connection to activate. +"${WP[@]}" jetpack module activate ai || exit 1 "${WP[@]}" option delete e2e_admin_shell_off >/dev/null 2>&1 ADMIN_SHELL_RUN=shell-on playwright test -c playwright.admin-shell.config.ts --project='shell on: *' "$@" || STATUS=1 echo "::endgroup::" diff --git a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts index 32a84c6cd04f..880e4fa52780 100644 --- a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts +++ b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts @@ -54,7 +54,8 @@ export const MEMBERS: Member[] = [ mountId: 'jetpack-settings-dashboard-wp-admin-app', title: 'Settings', heading: /Settings/, - landing: /^\?page=jetpack-settings(&p=%2F[^#&]*)?$/, + // Settings routes with a HashRouter. + landing: /^\?page=jetpack-settings(#\/[\w-]*)?$/, }, { slug: 'jetpack-podcast', @@ -218,6 +219,31 @@ function shellProbe( mountIds: Record< string, string > ) { }; } +/** + * Log in through the wp-login.php of `page`'s base URL. + * + * @param page - Page to log in with. + * @param user - Username. + * @param password - Password. + */ +export async function submitLogin( page: Page, user: string, password: string ): Promise< void > { + await page.goto( '/wp-login.php' ); + // Jetpack SSO can put the WordPress.com button first. + const toggle = page.getByText( 'Log in with username and password' ); + if ( await toggle.isVisible().catch( () => false ) ) { + await toggle.click(); + } + // wp-login.php focuses and selects the username field on a timer, which can clobber the fill. + await expect( async () => { + await page.locator( '#user_login' ).fill( user ); + await page.locator( '#user_pass' ).fill( password ); + await expect( page.locator( '#user_login' ) ).toHaveValue( user, { timeout: 1000 } ); + await expect( page.locator( '#user_pass' ) ).toHaveValue( password, { timeout: 1000 } ); + } ).toPass( { timeout: 15000 } ); + await page.locator( '#wp-submit' ).click(); + await expect( page.locator( '#wpadminbar' ) ).toBeVisible( { timeout: 60000 } ); +} + const pageErrors = new WeakMap< Page, string[] >(); /** @@ -238,6 +264,9 @@ export async function installShellProbe( page: Page ): Promise< void > { shellProbe, Object.fromEntries( MEMBERS.map( m => [ m.slug, m.mountId ] ) ) ); + // The mouse starts at 0,0 on the admin bar's WordPress logo, whose hover menu then covers the Jetpack submenu. + const { width, height } = page.viewportSize() ?? { width: 1280, height: 720 }; + await page.mouse.move( width - 20, height - 20 ); } /** diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts index 3e1136dfc14b..bcfa052bb6d9 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts @@ -280,7 +280,12 @@ test.describe( 'Admin shell: accessibility of in-shell navigation', () => { test( 'going Back with a modal open leaves the shown page in the accessibility tree', async ( { page, + browserName, } ) => { + test.fail( + browserName !== 'chromium', + 'Firefox and WebKit: no announcement of My Jetpack is heard after Back closes the Forms modal' + ); await keyboardPass( page, { afterBack: async () => { // The modal gives the document back once its closing animation ends. diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/auth.setup.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/auth.setup.ts index 6c769e4e3999..398b85f65a15 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/auth.setup.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/auth.setup.ts @@ -1,6 +1,11 @@ import fs from 'fs'; import { test as setup, expect, type Browser } from '@playwright/test'; -import { STATE_OFF, STATE_ON, STATE_STANDALONE } from '../../helpers/admin-shell-helper'; +import { + STATE_OFF, + STATE_ON, + STATE_STANDALONE, + submitLogin, +} from '../../helpers/admin-shell-helper'; /** * Log in through wp-login.php and save the session. @@ -18,23 +23,8 @@ async function logIn( password: string, path: string ) { - const context = await browser.newContext( { ignoreHTTPSErrors: true } ); - const page = await context.newPage(); - await page.goto( new URL( '/wp-login.php', url ).href ); - // Jetpack SSO can put the WordPress.com button first. - const toggle = page.getByText( 'Log in with username and password' ); - if ( await toggle.isVisible().catch( () => false ) ) { - await toggle.click(); - } - // wp-login.php focuses and selects the username field on a timer, which can clobber the fill. - await expect( async () => { - await page.locator( '#user_login' ).fill( user ); - await page.locator( '#user_pass' ).fill( password ); - await expect( page.locator( '#user_login' ) ).toHaveValue( user, { timeout: 1000 } ); - await expect( page.locator( '#user_pass' ) ).toHaveValue( password, { timeout: 1000 } ); - } ).toPass( { timeout: 15000 } ); - await page.locator( '#wp-submit' ).click(); - await expect( page.locator( '#wpadminbar' ) ).toBeVisible( { timeout: 60000 } ); + const context = await browser.newContext( { ignoreHTTPSErrors: true, baseURL: url } ); + await submitLogin( await context.newPage(), user, password ); await context.storageState( { path } ); await context.close(); } diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/frames.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/frames.test.ts index 1c8d51302a0c..dc493b3d15c4 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/frames.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/frames.test.ts @@ -69,7 +69,9 @@ test.describe( 'Admin shell: frame by frame', () => { } ) => { await arrive( page, from, to, visit ); const frames = await recordSwitch( page, to ); - expect( frames.length, 'frames were recorded' ).toBeGreaterThan( 10 ); + expect( frames.length, `frames were recorded:\n${ summary( frames ) }` ).toBeGreaterThan( + 10 + ); const notFound = frames.filter( f => f.notFound ); expect.soft( notFound, `"not found" frames:\n${ summary( notFound ) }` ).toHaveLength( 0 ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts index cc5898022e70..d15f074ae820 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts @@ -65,6 +65,7 @@ test.describe( 'Admin shell: state survives a round trip', () => { scrolled < 100, 'My Jetpack cannot scroll far enough here with the Forms link in view' ); + await page.mouse.move( 640, 400 ); await page.mouse.wheel( 0, scrolled ); // The wheel can scroll smoothly: wait for it to land. await expect.poll( () => page.evaluate( () => Math.round( scrollY ) ) ).toBe( scrolled ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts index 9aa118c8f20e..5e4c1a5f0ac7 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts @@ -3,6 +3,7 @@ import { expectShown, installShellProbe, openMember, + submitLogin, switchTo, } from '../../helpers/admin-shell-helper'; @@ -13,19 +14,11 @@ import { */ async function logInAgain( page: Page ): Promise< void > { const tab = await page.context().newPage(); - await tab.goto( '/wp-login.php' ); - const toggle = tab.getByText( 'Log in with username and password' ); - if ( await toggle.isVisible().catch( () => false ) ) { - await toggle.click(); - } - // wp-login.php focuses and selects the username field on a timer, which can clobber the fill. - await expect( async () => { - await tab.locator( '#user_login' ).fill( process.env.ADMIN_SHELL_USER ?? 'admin' ); - await tab.locator( '#user_pass' ).fill( process.env.ADMIN_SHELL_PASSWORD ?? 'password' ); - await expect( tab.locator( '#user_login' ) ).not.toHaveValue( '', { timeout: 1000 } ); - } ).toPass( { timeout: 15000 } ); - await tab.locator( '#wp-submit' ).click(); - await expect( tab.locator( '#wpadminbar' ) ).toBeVisible( { timeout: 60000 } ); + await submitLogin( + tab, + process.env.ADMIN_SHELL_USER ?? 'admin', + process.env.ADMIN_SHELL_PASSWORD ?? 'password' + ); await tab.close(); } From 5c237322f6c6ee703faaf43509ee31e4671fbc63 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 11 Nov 2026 16:48:16 -0600 Subject: [PATCH 09/34] Admin shell e2e: Fix the remaining browser-specific CI failures - Hide admin bar hover menus in test documents. Parking the mouse wasn't enough: the WordPress logo menu still opened over the Jetpack submenu in Chromium on WP 7.0 and swallowed sidebar clicks. - Scroll the document directly in the scroll round-trip test. In Firefox and WebKit the wheel landed on an inner scroller and left scrollY at 0. - Check that the frame recording saw the switch, instead of counting frames: headless WebKit only runs animation frames while it paints. - Treat the Back-with-a-modal announcement as an intermittent spike bug. It passed in Firefox and WebKit on one WordPress version and failed on the other. --- .../tests/e2e/helpers/admin-shell-helper.ts | 11 ++-- .../specs/admin-shell/accessibility.test.ts | 51 ++++++++++--------- .../e2e/specs/admin-shell/frames.test.ts | 9 ++-- .../e2e/specs/admin-shell/kept-state.test.ts | 5 +- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts index 880e4fa52780..c318ea09c24b 100644 --- a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts +++ b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts @@ -264,9 +264,14 @@ export async function installShellProbe( page: Page ): Promise< void > { shellProbe, Object.fromEntries( MEMBERS.map( m => [ m.slug, m.mountId ] ) ) ); - // The mouse starts at 0,0 on the admin bar's WordPress logo, whose hover menu then covers the Jetpack submenu. - const { width, height } = page.viewportSize() ?? { width: 1280, height: 720 }; - await page.mouse.move( width - 20, height - 20 ); + // Admin bar hover menus can open over the Jetpack submenu and swallow sidebar clicks; they aren't under test. + await page.addInitScript( () => { + document.addEventListener( 'DOMContentLoaded', () => { + const style = document.createElement( 'style' ); + style.textContent = '#wpadminbar .ab-sub-wrapper { display: none !important; }'; + document.head.append( style ); + } ); + } ); } /** diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts index bcfa052bb6d9..17c818273e21 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts @@ -14,6 +14,7 @@ import { resetA11yProbe, } from '../../helpers/admin-shell-a11y-helper'; import { + intermittentSpikeBug, installShellProbe, isShellActive, member, @@ -278,29 +279,29 @@ test.describe( 'Admin shell: accessibility of in-shell navigation', () => { } ); } ); - test( 'going Back with a modal open leaves the shown page in the accessibility tree', async ( { - page, - browserName, - } ) => { - test.fail( - browserName !== 'chromium', - 'Firefox and WebKit: no announcement of My Jetpack is heard after Back closes the Forms modal' - ); - await keyboardPass( page, { - afterBack: async () => { - // The modal gives the document back once its closing animation ends. - await expect - .poll( () => ariaHiddenAncestors( page, MJ ), 'aria-hidden around the shown app' ) - .toEqual( [] ); - // The probe skips live regions that are aria-hidden when they change. - await expect - .poll( () => announcements( page ), 'announcement for the page Back showed' ) - .toContainEqual( - expect.objectContaining( { text: expect.stringContaining( member( MJ ).title ) } ) - ); - await expect( mainHeading( page, MJ ) ).toBeFocused(); - await expect( mainHeading( page, MJ ) ).toBeVisible(); - }, - } ); - } ); + intermittentSpikeBug( + 'Firefox and WebKit sometimes hear no announcement of My Jetpack after Back closes the Forms modal', + () => { + test( 'going Back with a modal open leaves the shown page in the accessibility tree', async ( { + page, + } ) => { + await keyboardPass( page, { + afterBack: async () => { + // The modal gives the document back once its closing animation ends. + await expect + .poll( () => ariaHiddenAncestors( page, MJ ), 'aria-hidden around the shown app' ) + .toEqual( [] ); + // The probe skips live regions that are aria-hidden when they change. + await expect + .poll( () => announcements( page ), 'announcement for the page Back showed' ) + .toContainEqual( + expect.objectContaining( { text: expect.stringContaining( member( MJ ).title ) } ) + ); + await expect( mainHeading( page, MJ ) ).toBeFocused(); + await expect( mainHeading( page, MJ ) ).toBeVisible(); + }, + } ); + } ); + } + ); } ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/frames.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/frames.test.ts index dc493b3d15c4..37ccd1314b3a 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/frames.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/frames.test.ts @@ -69,9 +69,12 @@ test.describe( 'Admin shell: frame by frame', () => { } ) => { await arrive( page, from, to, visit ); const frames = await recordSwitch( page, to ); - expect( frames.length, `frames were recorded:\n${ summary( frames ) }` ).toBeGreaterThan( - 10 - ); + // WebKit only runs animation frames while something paints, so count frames that show the switch. + expect( + frames.some( f => f.owner === to ), + `frames were recorded through the switch: +${ summary( frames ) }` + ).toBe( true ); const notFound = frames.filter( f => f.notFound ); expect.soft( notFound, `"not found" frames:\n${ summary( notFound ) }` ).toHaveLength( 0 ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts index d15f074ae820..311c6ab649f8 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts @@ -65,9 +65,8 @@ test.describe( 'Admin shell: state survives a round trip', () => { scrolled < 100, 'My Jetpack cannot scroll far enough here with the Forms link in view' ); - await page.mouse.move( 640, 400 ); - await page.mouse.wheel( 0, scrolled ); - // The wheel can scroll smoothly: wait for it to land. + // A wheel can land on an inner scroller and leave the document where it was. + await page.evaluate( y => window.scrollTo( { top: y, behavior: 'instant' } ), scrolled ); await expect.poll( () => page.evaluate( () => Math.round( scrollY ) ) ).toBe( scrolled ); await page.evaluate( () => document.addEventListener( From d495db4821c46ee22578d5a95b5c1a429f29cfa5 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 11 Nov 2026 17:23:06 -0600 Subject: [PATCH 10/34] Admin shell e2e: Count nonce refreshes from the second login on In Firefox a background request hit the stale nonce first and refreshed it before the test started counting, so the probe succeeded with no refresh seen. --- .../plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts index 5e4c1a5f0ac7..686190876d2e 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts @@ -36,14 +36,14 @@ test.describe( 'Admin shell: stale REST nonce', () => { await switchTo( page, 'jetpack-ai' ); await expectShown( page, 'jetpack-ai' ); - await logInAgain( page ); - + // Count from the new login on: a background request can hit the stale nonce before the probe does. let refreshes = 0; page.on( 'request', request => { if ( /admin-ajax\.php\?(.*&)?action=rest-nonce/.test( request.url() ) ) { refreshes++; } } ); + await logInAgain( page ); const result = await page.evaluate( async () => { const { apiFetch } = ( window as unknown as { From 08e803326e67664777ff1ca1538fd92c8372203b Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 12 Nov 2026 08:21:26 -0600 Subject: [PATCH 11/34] Admin shell: Announce only after a closed modal gives the page back A modal hides the rest of the document with aria-hidden and only restores it in an effect cleanup, which can run after the modal has left the document. The shell waited only for the dialog to disconnect, so after Back it could focus the heading and speak while #wpwrap and the live regions were still aria-hidden, and the announcement went unheard in Firefox and WebKit. Also wait until #wpwrap and the live regions are no longer hidden. --- .../fix-admin-shell-announce-after-modal | 4 ++++ .../admin-ui/src/admin-shell/overlays.js | 8 +++++++- .../tests/js/admin-shell/overlays.test.js | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 projects/packages/admin-ui/changelog/fix-admin-shell-announce-after-modal diff --git a/projects/packages/admin-ui/changelog/fix-admin-shell-announce-after-modal b/projects/packages/admin-ui/changelog/fix-admin-shell-announce-after-modal new file mode 100644 index 000000000000..4e9c4d27fe79 --- /dev/null +++ b/projects/packages/admin-ui/changelog/fix-admin-shell-announce-after-modal @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Admin shell: Wait for a closed modal to give the page back before announcing the next page. diff --git a/projects/packages/admin-ui/src/admin-shell/overlays.js b/projects/packages/admin-ui/src/admin-shell/overlays.js index 144a88f06a81..d19edc3e3ec3 100644 --- a/projects/packages/admin-ui/src/admin-shell/overlays.js +++ b/projects/packages/admin-ui/src/admin-shell/overlays.js @@ -120,9 +120,15 @@ export async function closeDialogsOf( slug ) { .flatMap( el => [ el, ...el.querySelectorAll( DIALOGS ) ] ) .filter( el => el.matches( DIALOGS ) ); dialogs.filter( d => ! escaped.has( d ) ).forEach( pressEscape ); + // A modal gives the document back in an effect cleanup, which can run after it has left it. + const documentHidden = () => + [ ...document.querySelectorAll( '#wpwrap, .a11y-speak-region' ) ].some( el => + el.closest( '[aria-hidden="true"]' ) + ); + const open = () => dialogs.some( d => d.isConnected ) || ( dialogs.length && documentHidden() ); const start = performance.now(); // Timers, not frames: a Back in a background tab gets no animation frames. - while ( dialogs.some( d => d.isConnected ) && performance.now() - start < CLOSE_TIMEOUT ) { + while ( open() && performance.now() - start < CLOSE_TIMEOUT ) { await new Promise( resolve => setTimeout( resolve, 16 ) ); } // One that stayed open, such as behind a confirm, gets Escape again the next time. diff --git a/projects/packages/admin-ui/tests/js/admin-shell/overlays.test.js b/projects/packages/admin-ui/tests/js/admin-shell/overlays.test.js index dd34dc0b90eb..5959b8a91ffb 100644 --- a/projects/packages/admin-ui/tests/js/admin-shell/overlays.test.js +++ b/projects/packages/admin-ui/tests/js/admin-shell/overlays.test.js @@ -98,6 +98,22 @@ describe( 'overlays', () => { expect( otherModal ).toBeInTheDocument(); } ); + it( 'waits for a closed modal to give the document back', async () => { + const wrap = await addToBody( '' ); + wrap.id = 'wpwrap'; + wrap.setAttribute( 'aria-hidden', 'true' ); + const modal = await addToBody( '
' ); + modal.addEventListener( 'keydown', () => { + setTimeout( () => modal.remove(), 50 ); + // unmodalize() runs in an effect cleanup, after React has removed the modal. + setTimeout( () => wrap.removeAttribute( 'aria-hidden' ), 120 ); + } ); + + await closeDialogsOf( 'my-jetpack' ); + + expect( wrap ).not.toHaveAttribute( 'aria-hidden' ); + } ); + it( 'does not press Escape again on a dialog a link already closed', async () => { const modal = await addToBody( '' ); // Still in the document while it animates out, as when the switch reaches it. From 0d5da3ad7c1b6727a80cadf7532fcb252865d8af Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 12 Nov 2026 08:21:31 -0600 Subject: [PATCH 12/34] Admin shell e2e: Run the Back-with-a-modal test as a normal test again The shell now waits for a closed modal to give the page back before it announces, so the test no longer needs the intermittent-bug wrapper. --- .../specs/admin-shell/accessibility.test.ts | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts index 17c818273e21..3e1136dfc14b 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts @@ -14,7 +14,6 @@ import { resetA11yProbe, } from '../../helpers/admin-shell-a11y-helper'; import { - intermittentSpikeBug, installShellProbe, isShellActive, member, @@ -279,29 +278,24 @@ test.describe( 'Admin shell: accessibility of in-shell navigation', () => { } ); } ); - intermittentSpikeBug( - 'Firefox and WebKit sometimes hear no announcement of My Jetpack after Back closes the Forms modal', - () => { - test( 'going Back with a modal open leaves the shown page in the accessibility tree', async ( { - page, - } ) => { - await keyboardPass( page, { - afterBack: async () => { - // The modal gives the document back once its closing animation ends. - await expect - .poll( () => ariaHiddenAncestors( page, MJ ), 'aria-hidden around the shown app' ) - .toEqual( [] ); - // The probe skips live regions that are aria-hidden when they change. - await expect - .poll( () => announcements( page ), 'announcement for the page Back showed' ) - .toContainEqual( - expect.objectContaining( { text: expect.stringContaining( member( MJ ).title ) } ) - ); - await expect( mainHeading( page, MJ ) ).toBeFocused(); - await expect( mainHeading( page, MJ ) ).toBeVisible(); - }, - } ); - } ); - } - ); + test( 'going Back with a modal open leaves the shown page in the accessibility tree', async ( { + page, + } ) => { + await keyboardPass( page, { + afterBack: async () => { + // The modal gives the document back once its closing animation ends. + await expect + .poll( () => ariaHiddenAncestors( page, MJ ), 'aria-hidden around the shown app' ) + .toEqual( [] ); + // The probe skips live regions that are aria-hidden when they change. + await expect + .poll( () => announcements( page ), 'announcement for the page Back showed' ) + .toContainEqual( + expect.objectContaining( { text: expect.stringContaining( member( MJ ).title ) } ) + ); + await expect( mainHeading( page, MJ ) ).toBeFocused(); + await expect( mainHeading( page, MJ ) ).toBeVisible(); + }, + } ); + } ); } ); From 9d81f1e2d82c4de0fe928bb7cd8eda5805cb4a75 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 12 Nov 2026 11:35:12 -0600 Subject: [PATCH 13/34] Admin shell e2e: Fill the login form only after wp-login.php's autofocus runs On a second login in an already logged-in context, wp-login.php prefills the username and its autofocus timer empties the password field 200 ms after load. Chromium and WebKit filled and checked both fields inside that window, so the timer cleared the password before the click, and the required field blocked the submit. The stale nonce test then waited out the admin bar. Wait for the timer to focus a field before filling. --- .../jetpack/tests/e2e/helpers/admin-shell-helper.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts index c318ea09c24b..6322d00519d9 100644 --- a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts +++ b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts @@ -233,7 +233,15 @@ export async function submitLogin( page: Page, user: string, password: string ): if ( await toggle.isVisible().catch( () => false ) ) { await toggle.click(); } - // wp-login.php focuses and selects the username field on a timer, which can clobber the fill. + /* wp-login.php focuses a field 200 ms after load, and empties the password first when the username + * comes prefilled, as it does for a context that is already logged in. Fill only after that runs. */ + await page + .waitForFunction( + () => !! document.querySelector( '#user_login:focus, #user_pass:focus' ), + null, + { timeout: 5000 } + ) + .catch( () => undefined ); await expect( async () => { await page.locator( '#user_login' ).fill( user ); await page.locator( '#user_pass' ).fill( password ); From af0a3427c9384eaed98c79d59b651228d310dc72 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 12 Nov 2026 11:40:58 -0600 Subject: [PATCH 14/34] E2E matrix: Drop the admin shell paths trigger Any change under projects/plugins/jetpack/, the suite included, already marks plugins/jetpack as changed, and plugins/jetpack is one of the suite's targets. --- .github/files/e2e-tests/e2e-matrix.js | 28 +-------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index 2d983a5bb8d5..63bc7b34a020 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -1,4 +1,4 @@ -const { execFileSync, execSync } = require( 'child_process' ); +const { execSync } = require( 'child_process' ); const fs = require( 'fs' ); const projects = [ @@ -49,8 +49,6 @@ const projects = [ 'packages/podcast', 'plugins/jetpack', ], - // Also run when a PR changes the suite itself, without fanning out to everything that depends on admin-ui. - paths: [ /^projects\/plugins\/jetpack\/tests\/e2e\/.*admin-shell/ ], buildGroup: 'jetpack-core', }, { @@ -188,24 +186,6 @@ function minWpVersion() { return match[ 1 ]; } -/** - * Files the pull request changes. - * - * @return {string[]} Paths, or an empty list outside a pull request. - */ -function prChangedFiles() { - if ( process.env.GITHUB_EVENT_NAME !== 'pull_request' ) { - return []; - } - const { base, head } = JSON.parse( - fs.readFileSync( process.env.GITHUB_EVENT_PATH, 'utf8' ) - ).pull_request; - return execFileSync( 'git', [ 'diff', '--name-only', `${ base.sha }...${ head.sha }` ] ) - .toString() - .split( '\n' ) - .filter( Boolean ); -} - const matrix = []; /** @@ -230,14 +210,8 @@ switch ( process.env.GITHUB_EVENT_NAME ) { ); const dependencyCache = new Map(); - const changedFiles = prChangedFiles(); for ( const project of projects ) { - if ( project.paths?.some( re => changedFiles.some( f => re.test( f ) ) ) ) { - pushBothVersions( project ); - continue; - } - if ( ! project.targets ) { // If no targets are defined, run the tests pushBothVersions( project ); From 54865c78613862c4328b86828d69ae5342383a15 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 12 Nov 2026 12:15:46 -0600 Subject: [PATCH 15/34] Admin shell e2e: Wait for the page to go quiet before each axe scan The axe test slept a fixed 8 s before each of its four scans. Wait instead until the page has gone a second with no DOM change and no request in flight, still capped at 8 s, so a page that settles early is scanned early. --- .../tests/e2e/helpers/admin-shell-helper.ts | 50 +++++++++++++++++++ .../specs/admin-shell/accessibility.test.ts | 10 ++-- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts index 6322d00519d9..10f0a51b1ecd 100644 --- a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts +++ b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts @@ -467,6 +467,56 @@ export async function settle( page: Page, ms: number ): Promise< void > { await page.waitForTimeout( ms ); } +/** + * Wait until the page has gone `quietMs` with no DOM change and no request in flight, or `maxMs` passes. + * + * @param page - Page under test. + * @param maxMs - Longest wait, as a fixed settle would use. + * @param quietMs - Quiet time that counts as settled. + */ +export async function waitForQuiet( page: Page, maxMs: number, quietMs = 1000 ): Promise< void > { + const inFlight = new Set< Request >(); + let lastNetwork = Date.now(); + const started = ( request: Request ) => { + inFlight.add( request ); + lastNetwork = Date.now(); + }; + const ended = ( request: Request ) => { + inFlight.delete( request ); + lastNetwork = Date.now(); + }; + page.on( 'request', started ); + page.on( 'requestfinished', ended ); + page.on( 'requestfailed', ended ); + try { + await page.evaluate( () => { + const w = window as unknown as { __jpLastMutation?: number }; + w.__jpLastMutation = Date.now(); + new MutationObserver( () => ( w.__jpLastMutation = Date.now() ) ).observe( document, { + subtree: true, + childList: true, + attributes: true, + characterData: true, + } ); + } ); + const deadline = Date.now() + maxMs; + while ( Date.now() < deadline ) { + const lastMutation = await page.evaluate( + () => ( window as unknown as { __jpLastMutation: number } ).__jpLastMutation + ); + const now = Date.now(); + if ( ! inFlight.size && now - lastNetwork >= quietMs && now - lastMutation >= quietMs ) { + return; + } + await settle( page, 250 ); + } + } finally { + page.off( 'request', started ); + page.off( 'requestfinished', ended ); + page.off( 'requestfailed', ended ); + } +} + /** * `search + hash` of the current URL. * diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts index 3e1136dfc14b..105615d614c1 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts @@ -19,7 +19,7 @@ import { member, openMember, readShell, - settle, + waitForQuiet, switchTo, waitForShown, withinDocument, @@ -29,7 +29,7 @@ import { const MJ = 'my-jetpack'; const FORMS = 'jetpack-forms-responses-wp-admin'; -// Widgets such as My Jetpack's stats cards render well after the heading. +// Widgets such as My Jetpack's stats cards render well after the heading; wait at most this long. const AXE_SETTLE_MS = 8000; const back = ( page: Page, slug: string ) => @@ -232,7 +232,7 @@ test.describe( 'Admin shell: accessibility of in-shell navigation', () => { const baseline: Record< string, Record< string, string[] > > = {}; for ( const slug of [ FORMS, MJ ] ) { await openMember( page, slug ); - await settle( page, AXE_SETTLE_MS ); + await waitForQuiet( page, AXE_SETTLE_MS ); baseline[ slug ] = await axeViolations( page ); test.info().annotations.push( { type: 'axe on full load', @@ -240,13 +240,13 @@ test.describe( 'Admin shell: accessibility of in-shell navigation', () => { } ); } await switchTo( page, FORMS ); - await settle( page, AXE_SETTLE_MS ); + await waitForQuiet( page, AXE_SETTLE_MS ); expect( await newViolations( page, baseline[ FORMS ] ), 'new after switching to Forms' ).toEqual( {} ); await switchTo( page, MJ ); - await settle( page, AXE_SETTLE_MS ); + await waitForQuiet( page, AXE_SETTLE_MS ); expect( await newViolations( page, baseline[ MJ ] ), 'new after switching back' ).toEqual( {} ); } ); From e4cce17f4064a4885652a7b7172b3810481b47c9 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 12 Nov 2026 12:15:53 -0600 Subject: [PATCH 16/34] Admin shell e2e: Run the CI suite on three workers Playwright kept both workers busy for nearly the whole run, so wall time tracked total test time over two. The specs only read site state. --- projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index 197481a0e44a..36ca3785d282 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -11,6 +11,8 @@ WP=( pnpm jetpack docker --type e2e --name t1 wp -- ) ADMIN_SHELL_USER=$( node -p 'require( "./config/local.cjs" ).testSites.default.username' ) || exit 1 ADMIN_SHELL_PASSWORD=$( node -p 'require( "./config/local.cjs" ).testSites.default.password' ) || exit 1 export ADMIN_SHELL_USER ADMIN_SHELL_PASSWORD +# The specs only read site state, so a third worker is safe; the 4-vCPU runner still has a core for the site. +export PLAYWRIGHT_WORKERS=${PLAYWRIGHT_WORKERS:-3} # The shell-off run points ADMIN_SHELL_OFF_URL at the same site; this matches the config's default. SITE_URL=${ADMIN_SHELL_URL:-http://localhost:8889} From f5347615d9009c0dd2db533e51eba01e4a2507c0 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 12 Nov 2026 12:43:58 -0600 Subject: [PATCH 17/34] Admin shell e2e: Go back to two CI workers With three workers the runner's CPU saturated: each test ran 45-90% slower, so the Playwright run only went from about 850 s to 785 s, and the timing-sensitive specs got less headroom. Keep two until the jobs get a bigger runner. --- projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index 36ca3785d282..197481a0e44a 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -11,8 +11,6 @@ WP=( pnpm jetpack docker --type e2e --name t1 wp -- ) ADMIN_SHELL_USER=$( node -p 'require( "./config/local.cjs" ).testSites.default.username' ) || exit 1 ADMIN_SHELL_PASSWORD=$( node -p 'require( "./config/local.cjs" ).testSites.default.password' ) || exit 1 export ADMIN_SHELL_USER ADMIN_SHELL_PASSWORD -# The specs only read site state, so a third worker is safe; the 4-vCPU runner still has a core for the site. -export PLAYWRIGHT_WORKERS=${PLAYWRIGHT_WORKERS:-3} # The shell-off run points ADMIN_SHELL_OFF_URL at the same site; this matches the config's default. SITE_URL=${ADMIN_SHELL_URL:-http://localhost:8889} From 8dbe31b8e5d2e4b65a7818baa75185820b948cfc Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 13 Nov 2026 10:10:00 -0600 Subject: [PATCH 18/34] Admin shell e2e: Attach an a11y timeline when Back with a modal fails The test fails intermittently in WebKit and Firefox in CI: the shell focuses My Jetpack's heading, but the probe never hears its title. Record what the probe skipped as unheard, when #wpwrap's aria-hidden changes, when the dialog leaves and when Back starts, so a failure shows whether the title was spoken while the document was still hidden. --- .../e2e/helpers/admin-shell-a11y-helper.ts | 62 ++++++++++++++++++- .../specs/admin-shell/accessibility.test.ts | 44 ++++++++----- 2 files changed, 87 insertions(+), 19 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts index 6558e9681410..28ec577a4e44 100644 --- a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts +++ b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts @@ -13,10 +13,17 @@ export interface PlaceholderSighting { ariaHidden: boolean; } +/** A live-region change or `#wpwrap` `aria-hidden` change, in ms since the document started. */ +export interface A11yEvent { + at: number; + what: string; +} + /** What the accessibility probe exposes on `window.__jpShellA11y`. */ interface A11yProbe { announcements: Announcement[]; placeholders: PlaceholderSighting[]; + timeline: A11yEvent[]; } type ProbeWindow = { __jpShellA11y: A11yProbe; @@ -34,6 +41,7 @@ function a11yProbe() { const LIVE = '[aria-live], [role="status"], [role="alert"], [role="log"]'; const said: Announcement[] = []; const placeholders: PlaceholderSighting[] = []; + const timeline: A11yEvent[] = []; const seen = new WeakSet< Element >(); const politeness = ( el: Element ) => @@ -43,6 +51,21 @@ function a11yProbe() { const observer = new MutationObserver( records => { const touched = new Set< Element >(); for ( const record of records ) { + if ( record.attributeName === 'aria-hidden' ) { + if ( ( record.target as Element ).id === 'wpwrap' ) { + const value = ( record.target as Element ).getAttribute( 'aria-hidden' ); + timeline.push( { + at: Math.round( performance.now() ), + what: `#wpwrap aria-hidden=${ value }`, + } ); + } + continue; + } + record.removedNodes.forEach( node => { + if ( node instanceof Element && node.querySelector( '[role="dialog"]' ) ) { + timeline.push( { at: Math.round( performance.now() ), what: 'dialog removed' } ); + } + } ); const target = record.target instanceof Element ? record.target : record.target.parentElement; const live = target?.closest( LIVE ); if ( live ) { @@ -61,8 +84,14 @@ function a11yProbe() { const text = live.textContent?.trim(); // Screen readers don't speak regions in hidden apps or the inert header stand-in. const silent = !! live.closest( '[aria-hidden="true"], [inert]' ) || ! live.checkVisibility(); - if ( text && ! silent && politeness( live ) !== 'off' ) { - said.push( { politeness: politeness( live ), text } ); + if ( text && politeness( live ) !== 'off' ) { + timeline.push( { + at: Math.round( performance.now() ), + what: `${ silent ? 'unheard' : 'heard' }: ${ text }`, + } ); + if ( ! silent ) { + said.push( { politeness: politeness( live ), text } ); + } } } for ( const el of document.querySelectorAll< HTMLElement >( '[data-shell-header]' ) ) { @@ -80,12 +109,13 @@ function a11yProbe() { childList: true, characterData: true, attributes: true, - attributeFilter: [ 'style', 'class', 'hidden' ], + attributeFilter: [ 'style', 'class', 'hidden', 'aria-hidden' ], } ); ( window as unknown as Record< string, unknown > ).__jpShellA11y = { announcements: said, placeholders, + timeline, }; } @@ -108,6 +138,7 @@ export async function resetA11yProbe( page: Page ): Promise< void > { const probe = ( window as unknown as ProbeWindow ).__jpShellA11y; probe.announcements.length = 0; probe.placeholders.length = 0; + probe.timeline.length = 0; } ); } @@ -215,6 +246,31 @@ export function focusOwner( page: Page ): Promise< string > { } ); } +/** + * Live-region changes, heard or not, and `#wpwrap` `aria-hidden` changes since the last reset. + * + * @param page - Page under test. + * @return Events in order. + */ +export function a11yTimeline( page: Page ): Promise< A11yEvent[] > { + return page.evaluate( () => [ ...( window as unknown as ProbeWindow ).__jpShellA11y.timeline ] ); +} + +/** + * Add a step of the test to the probe's timeline. + * + * @param page - Page under test. + * @param what - The step. + */ +export async function markA11yTimeline( page: Page, what: string ): Promise< void > { + await page.evaluate( w => { + ( window as unknown as ProbeWindow ).__jpShellA11y.timeline.push( { + at: Math.round( performance.now() ), + what: w, + } ); + }, what ); +} + /** * The app container for `slug` and its ancestors that are `aria-hidden`, as `#id` or tag name. * diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts index 105615d614c1..277f88fb4277 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts @@ -1,5 +1,6 @@ import { test, expect, type Page } from '@playwright/test'; import { + a11yTimeline, announcements, ariaHiddenAncestors, axeViolations, @@ -8,6 +9,7 @@ import { hiddenApps, installA11yProbe, keyboardSwitchTo, + markA11yTimeline, mainHeading, newViolations, placeholderSightings, @@ -147,6 +149,7 @@ async function keyboardPass( await expectSwitched( page, FORMS, MJ ); await afterSwitch?.(); const dialog = await openCreateForm( page ); + await markA11yTimeline( page, 'Back' ); await back( page, MJ ); await expectSwitched( page, MJ, FORMS ); await expect( dialog ).toBeHidden(); @@ -281,21 +284,30 @@ test.describe( 'Admin shell: accessibility of in-shell navigation', () => { test( 'going Back with a modal open leaves the shown page in the accessibility tree', async ( { page, } ) => { - await keyboardPass( page, { - afterBack: async () => { - // The modal gives the document back once its closing animation ends. - await expect - .poll( () => ariaHiddenAncestors( page, MJ ), 'aria-hidden around the shown app' ) - .toEqual( [] ); - // The probe skips live regions that are aria-hidden when they change. - await expect - .poll( () => announcements( page ), 'announcement for the page Back showed' ) - .toContainEqual( - expect.objectContaining( { text: expect.stringContaining( member( MJ ).title ) } ) - ); - await expect( mainHeading( page, MJ ) ).toBeFocused(); - await expect( mainHeading( page, MJ ) ).toBeVisible(); - }, - } ); + try { + await keyboardPass( page, { + afterBack: async () => { + // The modal gives the document back once its closing animation ends. + await expect + .poll( () => ariaHiddenAncestors( page, MJ ), 'aria-hidden around the shown app' ) + .toEqual( [] ); + // The probe skips live regions that are aria-hidden when they change. + await expect + .poll( () => announcements( page ), 'announcement for the page Back showed' ) + .toContainEqual( + expect.objectContaining( { text: expect.stringContaining( member( MJ ).title ) } ) + ); + await expect( mainHeading( page, MJ ) ).toBeFocused(); + await expect( mainHeading( page, MJ ) ).toBeVisible(); + }, + } ); + } catch ( error ) { + // Shows whether the title was spoken while #wpwrap was still aria-hidden. + await test.info().attach( 'a11y timeline', { + body: JSON.stringify( await a11yTimeline( page ).catch( () => [] ), null, '\t' ), + contentType: 'application/json', + } ); + throw error; + } } ); } ); From 36b34ba355333872d9b5e506b5db93a7e33bb7cc Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 13 Nov 2026 10:10:09 -0600 Subject: [PATCH 19/34] Admin shell e2e: Say why the members list skips four members CI does stub a WordPress.com connection now; the members are left out because their modules stay off and the stub can't fetch their data. --- .../plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts index 3b1b88407165..32158064e8bc 100644 --- a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts +++ b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-helper.ts @@ -75,8 +75,8 @@ export const MEMBERS: Member[] = [ // Needs the `seo-admin-ui` plan feature or the `rsm_jetpack_seo` filter, and the seo-tools module on. optional: true, }, - /* Activity Log, Newsletter, Protect and VideoPress are members too, but each needs a WordPress.com - * connection (their modules don't load in offline mode), and the test site has none. */ + /* Activity Log, Newsletter, Protect and VideoPress are members too, but CI leaves their modules off, + * and its stubbed WordPress.com connection can't fetch the data their pages show. */ ]; export const member = ( slug: string ): Member => { From 65680c589746c824937663a80bed08d8d90f5770 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 13 Nov 2026 10:10:19 -0600 Subject: [PATCH 20/34] E2E matrix: Target only plugins/jetpack for the admin shell suite The matrix expands targets with their dependencies, and plugins/jetpack requires admin-ui, my-jetpack, forms and podcast directly. --- .github/files/e2e-tests/e2e-matrix.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index 0911f78b2ddc..6faf4fbe3f67 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -42,13 +42,7 @@ const projects = [ path: 'projects/plugins/jetpack/tests/e2e', testScript: 'test:admin-shell:ci', testArgs: [], - targets: [ - 'packages/admin-ui', - 'packages/my-jetpack', - 'packages/forms', - 'packages/podcast', - 'plugins/jetpack', - ], + targets: [ 'plugins/jetpack' ], buildGroup: 'jetpack-core', }, { From 5886dedbd88887b6bf47f0ba33f7e4339ac0e055 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 13 Nov 2026 10:10:26 -0600 Subject: [PATCH 21/34] Admin shell e2e: Wait for Tracks views instead of sleeping Poll for the expected view events and stop after a second without new ones. Only the check that no foreign view arrives keeps the fixed wait. --- .../e2e/specs/admin-shell/tracks.test.ts | 64 ++++++++++++++----- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts index e7ea87248841..f19f2f6269af 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts @@ -15,8 +15,9 @@ const FORMS = 'jetpack-forms-responses-wp-admin'; /* The other members may record no views on the unconnected test site, which would pass vacuously. */ const TRACKED = MEMBERS.filter( m => [ 'my-jetpack', FORMS ].includes( m.slug ) ); -/* Tracks calls go out after render, so give each arrival a moment before reading. */ +/* Tracks calls go out after render: the longest to wait for one, and the quiet spell that ends a wait. */ const SETTLE = 5000; +const QUIET = 1000; /** * View events recorded since `from` events had been seen. @@ -29,6 +30,38 @@ async function viewsSince( page: Page, from: number ): Promise< string[] > { return ( await tracksEvents( page ) ).slice( from ).filter( name => VIEW_EVENT.test( name ) ); } +/** + * Wait until `done` holds for the view events since `from` and no event has arrived for `QUIET`, or `SETTLE` passes. + * + * @param page - Page under test. + * @param from - Count of events already seen. + * @param done - Whether the views recorded so far are what the caller waits for. + * @return New view event names. + */ +async function waitForViews( + page: Page, + from: number, + done: ( views: string[] ) => boolean = () => true +): Promise< string[] > { + const deadline = Date.now() + SETTLE; + let count = -1; + let lastArrival = Date.now(); + for (;;) { + const events = await tracksEvents( page ); + if ( events.length !== count ) { + count = events.length; + lastArrival = Date.now(); + } + const views = events.slice( from ).filter( name => VIEW_EVENT.test( name ) ); + if ( ( done( views ) && Date.now() - lastArrival >= QUIET ) || Date.now() >= deadline ) { + return views; + } + await settle( page, 250 ); + } +} + +const any = ( views: string[] ) => views.length > 0; + /** * View events a full load of `slug` records, skipping the test when there are none. * @@ -38,8 +71,7 @@ async function viewsSince( page: Page, from: number ): Promise< string[] > { */ async function fullLoadViews( page: Page, slug: string ): Promise< string[] > { await openMember( page, slug ); - await settle( page, SETTLE ); - const views = [ ...new Set( await viewsSince( page, 0 ) ) ]; + const views = [ ...new Set( await waitForViews( page, 0, any ) ) ]; test.skip( ! views.length, `${ slug } records no page view on a full load either` ); return views; } @@ -47,16 +79,16 @@ async function fullLoadViews( page: Page, slug: string ): Promise< string[] > { /** * Let earlier Tracks calls land, switch to `slug`, and return the view events recorded on arrival. * - * @param page - Page under test. - * @param slug - Member page slug. + * @param page - Page under test. + * @param slug - Member page slug. + * @param expected - View events to wait for. * @return New view event names. */ -async function viewsOnSwitch( page: Page, slug: string ): Promise< string[] > { - await settle( page, SETTLE ); +async function viewsOnSwitch( page: Page, slug: string, expected: string[] ): Promise< string[] > { + await waitForViews( page, 0 ); const seen = ( await tracksEvents( page ) ).length; await switchTo( page, slug ); - await settle( page, SETTLE ); - return viewsSince( page, seen ); + return waitForViews( page, seen, views => expected.every( name => views.includes( name ) ) ); } test.describe( 'Admin shell: Tracks page views', () => { @@ -73,7 +105,9 @@ test.describe( 'Admin shell: Tracks page views', () => { await skipUnlessOnSite( page, m.slug ); const expected = await fullLoadViews( page, m.slug ); await openMember( page, other ); - expect( await viewsOnSwitch( page, m.slug ) ).toEqual( expect.arrayContaining( expected ) ); + expect( await viewsOnSwitch( page, m.slug, expected ) ).toEqual( + expect.arrayContaining( expected ) + ); } ); test( `a return switch to ${ m.slug } records the page view again`, async ( { page } ) => { @@ -82,7 +116,7 @@ test.describe( 'Admin shell: Tracks page views', () => { await openMember( page, other ); await switchTo( page, m.slug ); await switchTo( page, other ); - const views = await viewsOnSwitch( page, m.slug ); + const views = await viewsOnSwitch( page, m.slug, expected ); // Called here, so a failed switch above is still a real failure. test.fail( true, 'Known gap: a kept-alive app records no page view when shown again.' ); expect( views ).toEqual( expect.arrayContaining( expected ) ); @@ -91,11 +125,9 @@ test.describe( 'Admin shell: Tracks page views', () => { test( 'hidden apps record no page views while another is shown', async ( { page } ) => { await openMember( page, FORMS ); - await settle( page, SETTLE ); - const formsViews = new Set( await viewsSince( page, 0 ) ); + const formsViews = new Set( await waitForViews( page, 0, any ) ); await openMember( page, 'my-jetpack' ); - await settle( page, SETTLE ); - const own = new Set( await viewsSince( page, 0 ) ); + const own = new Set( await waitForViews( page, 0, any ) ); expect( own.size, 'the probe sees My Jetpack’s own page view' ).toBeGreaterThan( 0 ); test.skip( [ ...formsViews ].every( name => own.has( name ) ), @@ -105,7 +137,7 @@ test.describe( 'Admin shell: Tracks page views', () => { // Forms' router stays mounted while hidden; My Jetpack's URL writes must not reach it. await switchTo( page, FORMS ); await switchTo( page, 'my-jetpack' ); - await settle( page, SETTLE ); + await waitForViews( page, 0 ); const seen = ( await tracksEvents( page ) ).length; await page.getByRole( 'tab', { name: 'Features' } ).filter( { visible: true } ).click(); await settle( page, SETTLE ); From 46b8814888b4a477ca91aefa57e6fa6b7b028421 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 13 Nov 2026 10:11:02 -0600 Subject: [PATCH 22/34] Admin shell e2e: Pick the browsers with ADMIN_SHELL_BROWSERS Install and run only the comma-separated browsers it lists. The default stays chromium, firefox and webkit. --- projects/plugins/jetpack/tests/e2e/README.md | 1 + projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh | 4 +++- projects/plugins/jetpack/tests/e2e/package.json | 2 +- .../jetpack/tests/e2e/playwright.admin-shell.config.ts | 4 +++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index b66e0b84e867..fb5a85034779 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -155,6 +155,7 @@ pnpm test:admin-shell - `ADMIN_SHELL_URL` (default `http://localhost:8889`) must have `jetpack_admin_shell_enabled` on. Members marked `optional` in `helpers/admin-shell-helper.ts` need site setup, noted on each entry, and tests that use one skip where the site's admin menu lacks it. SEO, for example, shows only with the `seo-admin-ui` plan feature or the `rsm_jetpack_seo` filter, and with the `seo-tools` module on. - `ADMIN_SHELL_OFF_URL` is optional: a site with the shell off, for the `shell off` smoke projects. Without it they are skipped. - `ADMIN_SHELL_STANDALONE_URL` (with `ADMIN_SHELL_STANDALONE_USER` / `ADMIN_SHELL_STANDALONE_PASSWORD`) is optional: a site with the shell on and only standalone plugins, such as Backup, Social and VideoPress, without the Jetpack plugin (JETPACK-3419). It adds the `standalone` projects; without it there are none. Run it again after installing standalone plugins built against different Admin UI versions. +- `ADMIN_SHELL_BROWSERS` (default `chromium,firefox,webkit`) is a comma-separated list of the browsers to install and run. - Add `--project='shell on: chromium'` to run one browser. Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index 197481a0e44a..6935f0b5a547 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -14,7 +14,9 @@ export ADMIN_SHELL_USER ADMIN_SHELL_PASSWORD # The shell-off run points ADMIN_SHELL_OFF_URL at the same site; this matches the config's default. SITE_URL=${ADMIN_SHELL_URL:-http://localhost:8889} -playwright install --with-deps chromium firefox webkit || exit 1 +# Comma-separated; playwright.admin-shell.config.ts runs the same list. +IFS=, read -ra BROWSERS <<<"${ADMIN_SHELL_BROWSERS:-chromium,firefox,webkit}" +playwright install --with-deps "${BROWSERS[@]}" || exit 1 # The site is never connected, so default modules (including the Forms and Podcast members) aren't auto-activated. # Do this before e2e-admin-shell takes the site out of offline mode, where an unconnected site refuses activation. diff --git a/projects/plugins/jetpack/tests/e2e/package.json b/projects/plugins/jetpack/tests/e2e/package.json index 505a0f854789..1dcc8fb055fa 100644 --- a/projects/plugins/jetpack/tests/e2e/package.json +++ b/projects/plugins/jetpack/tests/e2e/package.json @@ -11,7 +11,7 @@ "env:new": "e2e-env new", "env:reset": "e2e-env reset", "env:up": "e2e-env start", - "test:admin-shell": "playwright install chromium firefox webkit && playwright test -c playwright.admin-shell.config.ts", + "test:admin-shell": "playwright install $(echo \"${ADMIN_SHELL_BROWSERS:-chromium,firefox,webkit}\" | tr , ' ') && playwright test -c playwright.admin-shell.config.ts", "test:admin-shell:ci": "pnpm run clean && bin/admin-shell-ci.sh", "pretest:run": "pnpm run clean", "test:run": "playwright install chromium && NODE_CONFIG_DIR='./config' NODE_PATH=\"$PWD/node_modules\" playwright test", diff --git a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts index 6611e0c6e3ee..bfa31f5f0104 100644 --- a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts +++ b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts @@ -36,11 +36,13 @@ if ( process.env.CI ) { ); } +// ADMIN_SHELL_BROWSERS (comma-separated) picks the browsers; bin/admin-shell-ci.sh installs the same list. +const browserNames = ( process.env.ADMIN_SHELL_BROWSERS || 'chromium,firefox,webkit' ).split( ',' ); const browsers = [ { name: 'chromium', use: devices[ 'Desktop Chrome' ] }, { name: 'firefox', use: devices[ 'Desktop Firefox' ] }, { name: 'webkit', use: devices[ 'Desktop Safari' ] }, -]; +].filter( browser => browserNames.includes( browser.name ) ); export default defineConfig( { testDir: './specs/admin-shell', From 19bcc883ea27a90dbbd821c866581100246e575a Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 13 Nov 2026 10:12:24 -0600 Subject: [PATCH 23/34] Admin shell e2e: Run only Chromium on pull requests Post-merge runs against the jetpack-production mirror and manual runs keep all three browsers. --- .github/workflows/e2e-tests.yml | 2 ++ projects/plugins/jetpack/tests/e2e/README.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index ba8456b99af1..cbf1705bded5 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -268,6 +268,8 @@ jobs: env: JSON_ARGS: ${{ toJSON(matrix.testArgs) }} TEST_SCRIPT: ${{ matrix.testScript || 'test:run' }} + # Admin shell suite: Chromium on pull requests, every browser after merge and on manual runs. + ADMIN_SHELL_BROWSERS: ${{ case( github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch', 'chromium,firefox,webkit', 'chromium' ) }} run: | mapfile -t TEST_ARGS < <(jq -r '.[]' <<<"$JSON_ARGS") pnpm run "$TEST_SCRIPT" "${TEST_ARGS[@]}" diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index fb5a85034779..2cf51f45d638 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -160,7 +160,7 @@ pnpm test:admin-shell Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. -In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. +In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. Pull requests run it in Chromium only; the post-merge runs against the `jetpack-production` mirror and manual runs use all three browsers. The standalone projects don't run in CI. Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. From 999c8d22d5969f65d58f65b88ddd475bea9943fb Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 13 Nov 2026 10:18:12 -0600 Subject: [PATCH 24/34] Revert "Admin shell e2e: Attach an a11y timeline when Back with a modal fails" This reverts commit 8dbe31b8e5d2e4b65a7818baa75185820b948cfc. --- .../e2e/helpers/admin-shell-a11y-helper.ts | 62 +------------------ .../specs/admin-shell/accessibility.test.ts | 44 +++++-------- 2 files changed, 19 insertions(+), 87 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts index 28ec577a4e44..6558e9681410 100644 --- a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts +++ b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts @@ -13,17 +13,10 @@ export interface PlaceholderSighting { ariaHidden: boolean; } -/** A live-region change or `#wpwrap` `aria-hidden` change, in ms since the document started. */ -export interface A11yEvent { - at: number; - what: string; -} - /** What the accessibility probe exposes on `window.__jpShellA11y`. */ interface A11yProbe { announcements: Announcement[]; placeholders: PlaceholderSighting[]; - timeline: A11yEvent[]; } type ProbeWindow = { __jpShellA11y: A11yProbe; @@ -41,7 +34,6 @@ function a11yProbe() { const LIVE = '[aria-live], [role="status"], [role="alert"], [role="log"]'; const said: Announcement[] = []; const placeholders: PlaceholderSighting[] = []; - const timeline: A11yEvent[] = []; const seen = new WeakSet< Element >(); const politeness = ( el: Element ) => @@ -51,21 +43,6 @@ function a11yProbe() { const observer = new MutationObserver( records => { const touched = new Set< Element >(); for ( const record of records ) { - if ( record.attributeName === 'aria-hidden' ) { - if ( ( record.target as Element ).id === 'wpwrap' ) { - const value = ( record.target as Element ).getAttribute( 'aria-hidden' ); - timeline.push( { - at: Math.round( performance.now() ), - what: `#wpwrap aria-hidden=${ value }`, - } ); - } - continue; - } - record.removedNodes.forEach( node => { - if ( node instanceof Element && node.querySelector( '[role="dialog"]' ) ) { - timeline.push( { at: Math.round( performance.now() ), what: 'dialog removed' } ); - } - } ); const target = record.target instanceof Element ? record.target : record.target.parentElement; const live = target?.closest( LIVE ); if ( live ) { @@ -84,14 +61,8 @@ function a11yProbe() { const text = live.textContent?.trim(); // Screen readers don't speak regions in hidden apps or the inert header stand-in. const silent = !! live.closest( '[aria-hidden="true"], [inert]' ) || ! live.checkVisibility(); - if ( text && politeness( live ) !== 'off' ) { - timeline.push( { - at: Math.round( performance.now() ), - what: `${ silent ? 'unheard' : 'heard' }: ${ text }`, - } ); - if ( ! silent ) { - said.push( { politeness: politeness( live ), text } ); - } + if ( text && ! silent && politeness( live ) !== 'off' ) { + said.push( { politeness: politeness( live ), text } ); } } for ( const el of document.querySelectorAll< HTMLElement >( '[data-shell-header]' ) ) { @@ -109,13 +80,12 @@ function a11yProbe() { childList: true, characterData: true, attributes: true, - attributeFilter: [ 'style', 'class', 'hidden', 'aria-hidden' ], + attributeFilter: [ 'style', 'class', 'hidden' ], } ); ( window as unknown as Record< string, unknown > ).__jpShellA11y = { announcements: said, placeholders, - timeline, }; } @@ -138,7 +108,6 @@ export async function resetA11yProbe( page: Page ): Promise< void > { const probe = ( window as unknown as ProbeWindow ).__jpShellA11y; probe.announcements.length = 0; probe.placeholders.length = 0; - probe.timeline.length = 0; } ); } @@ -246,31 +215,6 @@ export function focusOwner( page: Page ): Promise< string > { } ); } -/** - * Live-region changes, heard or not, and `#wpwrap` `aria-hidden` changes since the last reset. - * - * @param page - Page under test. - * @return Events in order. - */ -export function a11yTimeline( page: Page ): Promise< A11yEvent[] > { - return page.evaluate( () => [ ...( window as unknown as ProbeWindow ).__jpShellA11y.timeline ] ); -} - -/** - * Add a step of the test to the probe's timeline. - * - * @param page - Page under test. - * @param what - The step. - */ -export async function markA11yTimeline( page: Page, what: string ): Promise< void > { - await page.evaluate( w => { - ( window as unknown as ProbeWindow ).__jpShellA11y.timeline.push( { - at: Math.round( performance.now() ), - what: w, - } ); - }, what ); -} - /** * The app container for `slug` and its ancestors that are `aria-hidden`, as `#id` or tag name. * diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts index 277f88fb4277..105615d614c1 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts @@ -1,6 +1,5 @@ import { test, expect, type Page } from '@playwright/test'; import { - a11yTimeline, announcements, ariaHiddenAncestors, axeViolations, @@ -9,7 +8,6 @@ import { hiddenApps, installA11yProbe, keyboardSwitchTo, - markA11yTimeline, mainHeading, newViolations, placeholderSightings, @@ -149,7 +147,6 @@ async function keyboardPass( await expectSwitched( page, FORMS, MJ ); await afterSwitch?.(); const dialog = await openCreateForm( page ); - await markA11yTimeline( page, 'Back' ); await back( page, MJ ); await expectSwitched( page, MJ, FORMS ); await expect( dialog ).toBeHidden(); @@ -284,30 +281,21 @@ test.describe( 'Admin shell: accessibility of in-shell navigation', () => { test( 'going Back with a modal open leaves the shown page in the accessibility tree', async ( { page, } ) => { - try { - await keyboardPass( page, { - afterBack: async () => { - // The modal gives the document back once its closing animation ends. - await expect - .poll( () => ariaHiddenAncestors( page, MJ ), 'aria-hidden around the shown app' ) - .toEqual( [] ); - // The probe skips live regions that are aria-hidden when they change. - await expect - .poll( () => announcements( page ), 'announcement for the page Back showed' ) - .toContainEqual( - expect.objectContaining( { text: expect.stringContaining( member( MJ ).title ) } ) - ); - await expect( mainHeading( page, MJ ) ).toBeFocused(); - await expect( mainHeading( page, MJ ) ).toBeVisible(); - }, - } ); - } catch ( error ) { - // Shows whether the title was spoken while #wpwrap was still aria-hidden. - await test.info().attach( 'a11y timeline', { - body: JSON.stringify( await a11yTimeline( page ).catch( () => [] ), null, '\t' ), - contentType: 'application/json', - } ); - throw error; - } + await keyboardPass( page, { + afterBack: async () => { + // The modal gives the document back once its closing animation ends. + await expect + .poll( () => ariaHiddenAncestors( page, MJ ), 'aria-hidden around the shown app' ) + .toEqual( [] ); + // The probe skips live regions that are aria-hidden when they change. + await expect + .poll( () => announcements( page ), 'announcement for the page Back showed' ) + .toContainEqual( + expect.objectContaining( { text: expect.stringContaining( member( MJ ).title ) } ) + ); + await expect( mainHeading( page, MJ ) ).toBeFocused(); + await expect( mainHeading( page, MJ ) ).toBeVisible(); + }, + } ); } ); } ); From 5df26002fbb5ea1b7a73b3015697921fab62e7da Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 13 Nov 2026 10:41:53 -0600 Subject: [PATCH 25/34] Admin shell e2e: Count the nonce probe's own tries, not every refresh A background request that hits the stale nonce at the same time refreshes it too, so CI saw two refreshes. Check that a refresh happened and that the probe request was sent at most twice; a middleware loop still fails both that and the 15 s timeout. --- .../jetpack/tests/e2e/specs/admin-shell/nonce.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts index 686190876d2e..4df1beb30bb0 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/nonce.test.ts @@ -36,11 +36,15 @@ test.describe( 'Admin shell: stale REST nonce', () => { await switchTo( page, 'jetpack-ai' ); await expectShown( page, 'jetpack-ai' ); - // Count from the new login on: a background request can hit the stale nonce before the probe does. + /* Count from the new login on. Background requests can hit the stale nonce too, each refreshing it + * once, so count the probe's own tries: a stale one and one retry, not a loop. */ let refreshes = 0; + let probeTries = 0; page.on( 'request', request => { if ( /admin-ajax\.php\?(.*&)?action=rest-nonce/.test( request.url() ) ) { refreshes++; + } else if ( request.url().includes( 'e2e_nonce_probe' ) ) { + probeTries++; } } ); await logInAgain( page ); @@ -55,7 +59,7 @@ test.describe( 'Admin shell: stale REST nonce', () => { setTimeout( () => resolve( 'still retrying after 15 s' ), 15000 ) ); return Promise.race( [ - apiFetch( { path: '/wp/v2/users/me' } ).then( + apiFetch( { path: '/wp/v2/users/me?e2e_nonce_probe=1' } ).then( user => `user ${ user.id }`, ( error: { code?: string } ) => `failed: ${ error.code }` ), @@ -64,6 +68,7 @@ test.describe( 'Admin shell: stale REST nonce', () => { } ); expect( result, 'the request succeeds after the refresh' ).toMatch( /^user \d+$/ ); - expect( refreshes, 'nonce refreshes' ).toBe( 1 ); + expect( refreshes, 'nonce refreshes' ).toBeGreaterThan( 0 ); + expect( probeTries, 'tries of the probe request' ).toBeLessThanOrEqual( 2 ); } ); } ); From 8f9e3a9e8089628c7d95c7f9b6a37e1b63053baa Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 18 Nov 2026 09:08:07 -0600 Subject: [PATCH 26/34] Admin shell e2e: Run a smoke set on most PRs, and trim the suite On pull requests the suite now runs against WordPress latest only. It runs in full when the PR changes admin-ui, my-jetpack, jitm or a dashboard package, and only the tests tagged @smoke otherwise. Post-merge and manual runs are unchanged. - Drop tests that never ran in CI (leave-guard, the Forms Tracks rows, hidden-apps Tracks) and rows that repeat other specs (history full loads, per-member fallback rows, per-step focus and announce rows). - Point the memory spec at members the CI site has, so it runs there. - Add a hover side-effects test: the e2e plugin logs option and user meta writes made while serving the shell's guest request, and hovering must make none. - Run with four workers and fullyParallel, the shell-off logins with one. - Cache Playwright browsers, and skip system packages for a Chromium-only run. --- .github/files/e2e-tests/e2e-matrix.js | 50 ++++++++++- .github/workflows/e2e-tests.yml | 14 ++- .../jetpack/changelog/add-admin-shell-e2e-ci | 2 +- projects/plugins/jetpack/tests/e2e/README.md | 6 +- .../jetpack/tests/e2e/bin/admin-shell-ci.sh | 20 ++++- .../e2e/playwright.admin-shell.config.ts | 25 +++++- .../tests/e2e/plugins/e2e-admin-shell.php | 79 ++++++++++++++++ .../specs/admin-shell/accessibility.test.ts | 55 ++++-------- .../specs/admin-shell/api-fetch-nonce.test.ts | 59 ++++++------ .../e2e/specs/admin-shell/contract.test.ts | 60 +++++++------ .../e2e/specs/admin-shell/fallback.test.ts | 52 ++++++----- .../e2e/specs/admin-shell/history.test.ts | 11 --- .../admin-shell/hover-side-effects.test.ts | 54 +++++++++++ .../e2e/specs/admin-shell/kept-state.test.ts | 3 + .../e2e/specs/admin-shell/leave-guard.test.ts | 90 ------------------- .../e2e/specs/admin-shell/memory.test.ts | 20 ++--- .../admin-shell/navigation-matrix.test.ts | 5 +- .../e2e/specs/admin-shell/shell-off.test.ts | 2 +- .../e2e/specs/admin-shell/tracks.test.ts | 73 ++++----------- 19 files changed, 382 insertions(+), 298 deletions(-) create mode 100644 projects/plugins/jetpack/tests/e2e/specs/admin-shell/hover-side-effects.test.ts delete mode 100644 projects/plugins/jetpack/tests/e2e/specs/admin-shell/leave-guard.test.ts diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index 6faf4fbe3f67..0eacd33277df 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -44,6 +44,26 @@ const projects = [ testArgs: [], targets: [ 'plugins/jetpack' ], buildGroup: 'jetpack-core', + // On pull requests: WordPress latest only, and only the @smoke tests unless the PR itself changes one of these. + pullRequest: { + wpVersions: [ 'latest' ], + fullSuiteFor: [ + 'packages/admin-ui', + 'packages/my-jetpack', + 'packages/jitm', + 'packages/forms', + 'packages/podcast', + 'packages/protect', + 'packages/search', + 'packages/backup', + 'packages/activity-log', + 'packages/publicize', + 'packages/newsletter', + 'packages/seo', + 'packages/videopress', + 'plugins/boost', + ], + }, }, { project: 'Jetpack sync', @@ -182,6 +202,22 @@ function minWpVersion() { const matrix = []; +/** + * Projects the pull request changes itself, without the projects that only depend on them. + * + * @return {Set} Project slugs, e.g. 'packages/admin-ui'. + */ +function directlyChangedProjects() { + const event = JSON.parse( fs.readFileSync( process.env.GITHUB_EVENT_PATH, 'utf8' ) ); + const diff = `${ event.pull_request.base.sha }...${ event.pull_request.head.sha }`; + return new Set( + execSync( `pnpm jetpack dependencies list --git-changed=${ diff }` ) + .toString() + .split( '\n' ) + .filter( Boolean ) + ); +} + /** * Queue a project against both the latest WordPress release and the oldest one we still support, * so a change that only breaks the minimum version is caught while it's still in review. @@ -218,8 +254,17 @@ switch ( process.env.GITHUB_EVENT_NAME ) { } const targets = dependencyCache.get( command ); - if ( Object.keys( changedProjects ).some( target => targets.includes( target ) ) ) { + if ( ! Object.keys( changedProjects ).some( target => targets.includes( target ) ) ) { + continue; + } + if ( ! project.pullRequest || process.env.GITHUB_EVENT_NAME !== 'pull_request' ) { pushBothVersions( project ); + continue; + } + const direct = directlyChangedProjects(); + const smoke = ! project.pullRequest.fullSuiteFor.some( slug => direct.has( slug ) ); + for ( const wpVersion of project.pullRequest.wpVersions ) { + matrix.push( { ...project, wpVersion, smoke } ); } } break; @@ -268,4 +313,5 @@ switch ( process.env.GITHUB_EVENT_NAME ) { console.error( `Unsupported GITHUB_EVENT_NAME ${ process.env.GITHUB_EVENT_NAME }.` ); } -console.log( JSON.stringify( matrix ) ); +// `pullRequest` is input for this script, not for the workflow. +console.log( JSON.stringify( matrix.map( ( { pullRequest, ...entry } ) => entry ) ) ); diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index cbf1705bded5..c1a121caf77f 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -165,6 +165,8 @@ jobs: # Used in tests for enhanced reporting of global projects. The WordPress version is part of the # name so the two runs of a project are distinguishable in the report. PROJECT_NAME: '${{ matrix.project }} WP ${{ matrix.wpVersion }}' + # Admin shell suite: Chromium on pull requests, every browser after merge and on manual runs. + ADMIN_SHELL_BROWSERS: ${{ case( github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch', 'chromium,firefox,webkit', 'chromium' ) }} strategy: fail-fast: false matrix: @@ -263,13 +265,21 @@ jobs: nohup pnpm run tunnel:up "$HOME/tunnel.log" echo "::endgroup::" + - name: Cache Playwright browsers + if: matrix.testScript == 'test:admin-shell:ci' + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.cache/ms-playwright + # The Playwright version is pinned in package.json. + key: playwright-${{ runner.os }}-${{ hashFiles( format( '{0}/package.json', matrix.path ) ) }}-${{ env.ADMIN_SHELL_BROWSERS }} + - name: Run ${{ matrix.project }} tests working-directory: ${{ matrix.path }} env: JSON_ARGS: ${{ toJSON(matrix.testArgs) }} TEST_SCRIPT: ${{ matrix.testScript || 'test:run' }} - # Admin shell suite: Chromium on pull requests, every browser after merge and on manual runs. - ADMIN_SHELL_BROWSERS: ${{ case( github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch', 'chromium,firefox,webkit', 'chromium' ) }} + # Set by e2e-matrix.js on pull requests that don't change the admin shell or a dashboard it switches to. + ADMIN_SHELL_SMOKE: ${{ case( matrix.smoke, '1', '' ) }} run: | mapfile -t TEST_ARGS < <(jq -r '.[]' <<<"$JSON_ARGS") pnpm run "$TEST_SCRIPT" "${TEST_ARGS[@]}" diff --git a/projects/plugins/jetpack/changelog/add-admin-shell-e2e-ci b/projects/plugins/jetpack/changelog/add-admin-shell-e2e-ci index 34d942df6017..f8207af1c918 100644 --- a/projects/plugins/jetpack/changelog/add-admin-shell-e2e-ci +++ b/projects/plugins/jetpack/changelog/add-admin-shell-e2e-ci @@ -1,5 +1,5 @@ Significance: patch Type: other -Comment: Run the admin shell e2e suite in CI. +Comment: Run the admin shell e2e suite in CI: a smoke set on most pull requests, the full suite when the shell or a dashboard changes. diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index 2cf51f45d638..b2f28a5edb20 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -156,11 +156,15 @@ pnpm test:admin-shell - `ADMIN_SHELL_OFF_URL` is optional: a site with the shell off, for the `shell off` smoke projects. Without it they are skipped. - `ADMIN_SHELL_STANDALONE_URL` (with `ADMIN_SHELL_STANDALONE_USER` / `ADMIN_SHELL_STANDALONE_PASSWORD`) is optional: a site with the shell on and only standalone plugins, such as Backup, Social and VideoPress, without the Jetpack plugin (JETPACK-3419). It adds the `standalone` projects; without it there are none. Run it again after installing standalone plugins built against different Admin UI versions. - `ADMIN_SHELL_BROWSERS` (default `chromium,firefox,webkit`) is a comma-separated list of the browsers to install and run. +- `ADMIN_SHELL_SMOKE=1` runs only the tests tagged `@smoke`. +- The `hover side effects` project needs `plugins/e2e-admin-shell.php` on the site, and skips without it. - Add `--project='shell on: chromium'` to run one browser. Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. -In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. Pull requests run it in Chromium only; the post-merge runs against the `jetpack-production` mirror and manual runs use all three browsers. The standalone projects don't run in CI. +In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the `hover side effects` project alone first, then the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. + +Pull requests run it in Chromium, against WordPress latest only. A pull request that changes `admin-ui`, `my-jetpack`, `jitm` or a dashboard package (the `fullSuiteFor` list in `e2e-matrix.js`) runs the whole suite; any other pull request that reaches the Jetpack plugin runs only the tests tagged `@smoke` (`ADMIN_SHELL_SMOKE=1`). The post-merge runs against the `jetpack-production` mirror, and manual runs, use all three browsers and the whole suite. Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index 6935f0b5a547..eec4f674752f 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -# Runs the admin shell suite against the e2e Docker site from `pnpm env:up`: shell on, then shell off. -# Extra arguments go to both Playwright runs. +# Runs the admin shell suite against the e2e Docker site from `pnpm env:up`: hover side effects, shell on, then shell off. +# Extra arguments go to every Playwright run. ADMIN_SHELL_SMOKE=1 runs only the @smoke tests. set -uo pipefail cd "$(dirname "${BASH_SOURCE[0]}")/.." || exit 1 @@ -16,7 +16,12 @@ SITE_URL=${ADMIN_SHELL_URL:-http://localhost:8889} # Comma-separated; playwright.admin-shell.config.ts runs the same list. IFS=, read -ra BROWSERS <<<"${ADMIN_SHELL_BROWSERS:-chromium,firefox,webkit}" -playwright install --with-deps "${BROWSERS[@]}" || exit 1 +# The runner image already has what Chromium needs; Firefox and WebKit need system packages. +if [[ "${BROWSERS[*]}" == chromium ]]; then + playwright install chromium || exit 1 +else + playwright install --with-deps "${BROWSERS[@]}" || exit 1 +fi # The site is never connected, so default modules (including the Forms and Podcast members) aren't auto-activated. # Do this before e2e-admin-shell takes the site out of offline mode, where an unconnected site refuses activation. @@ -25,18 +30,25 @@ for module in contact-form podcast; do done STATUS=0 +# A 4-core runner: the browsers and the site share it. +export PLAYWRIGHT_WORKERS=${PLAYWRIGHT_WORKERS:-4} echo "::group::Shell on" "${WP[@]}" plugin activate e2e-admin-shell || exit 1 # Jetpack AI's sidebar item shows only with the ai module on, and it needs the stubbed connection to activate. "${WP[@]}" jetpack module activate ai || exit 1 "${WP[@]}" option delete e2e_admin_shell_off >/dev/null 2>&1 +# Alone and first, so no other test saves what it checks that hovering does not. +if [[ "${ADMIN_SHELL_SMOKE:-}" != 1 ]]; then + ADMIN_SHELL_RUN=hover playwright test -c playwright.admin-shell.config.ts --project='hover side effects' "$@" || STATUS=1 +fi ADMIN_SHELL_RUN=shell-on playwright test -c playwright.admin-shell.config.ts --project='shell on: *' "$@" || STATUS=1 echo "::endgroup::" echo "::group::Shell off" "${WP[@]}" option update e2e_admin_shell_off 1 || exit 1 -ADMIN_SHELL_RUN=shell-off ADMIN_SHELL_OFF_URL="$SITE_URL" \ +# One worker: both logins run here, and two at once on one site can stall each other. +ADMIN_SHELL_RUN=shell-off PLAYWRIGHT_WORKERS=1 ADMIN_SHELL_OFF_URL="$SITE_URL" \ ADMIN_SHELL_OFF_USER="$ADMIN_SHELL_USER" ADMIN_SHELL_OFF_PASSWORD="$ADMIN_SHELL_PASSWORD" \ playwright test -c playwright.admin-shell.config.ts --project='shell off: *' "$@" || STATUS=1 echo "::endgroup::" diff --git a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts index bfa31f5f0104..c3e7cf71389f 100644 --- a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts +++ b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts @@ -44,6 +44,9 @@ const browsers = [ { name: 'webkit', use: devices[ 'Desktop Safari' ] }, ].filter( browser => browserNames.includes( browser.name ) ); +// ADMIN_SHELL_SMOKE=1 runs only the tests tagged @smoke; the login setup always runs. +const smoke = process.env.ADMIN_SHELL_SMOKE === '1' ? { grep: /@smoke/ } : {}; + export default defineConfig( { testDir: './specs/admin-shell', outputDir: `${ runDir }/results`, @@ -51,6 +54,7 @@ export default defineConfig( { expect: { timeout: 20000 }, // Only login and tests wrapped in intermittentSpikeBug() retry; any other flake fails the run. retries: 0, + fullyParallel: true, workers: Number( process.env.PLAYWRIGHT_WORKERS ) || 2, reporter, use: { @@ -79,8 +83,14 @@ export default defineConfig( { }, ...browsers.map( browser => ( { name: `shell on: ${ browser.name }`, - testIgnore: [ 'auth.setup.ts', 'shell-off.test.ts', 'standalone.test.ts' ], + testIgnore: [ + 'auth.setup.ts', + 'shell-off.test.ts', + 'standalone.test.ts', + 'hover-side-effects.test.ts', + ], dependencies: [ 'admin shell login' ], + ...smoke, use: { ...browser.use, viewport: { width: 1280, height: 1600 }, @@ -88,10 +98,23 @@ export default defineConfig( { storageState: STATE_ON, }, } ) ), + // Chromium only. bin/admin-shell-ci.sh runs it alone, first, so no other test saves what it checks for. + { + name: 'hover side effects', + testMatch: 'hover-side-effects.test.ts', + dependencies: [ 'admin shell login' ], + use: { + ...devices[ 'Desktop Chrome' ], + viewport: { width: 1280, height: 1600 }, + baseURL: onUrl, + storageState: STATE_ON, + }, + }, ...browsers.map( browser => ( { name: `shell off: ${ browser.name }`, testMatch: 'shell-off.test.ts', dependencies: [ 'admin shell login' ], + ...smoke, use: { ...browser.use, viewport: { width: 1280, height: 1600 }, diff --git a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php index e7c1f871b298..4d7d83fb5447 100644 --- a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php +++ b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php @@ -63,3 +63,82 @@ function ( $response, $args, $url ) { 10, 3 ); + +/* + * A menu hover fetches the hovered dashboard's guest data, which must save nothing: the dashboard's own + * page load does that. Log every option and user meta write made while serving that request. + */ +const E2E_ADMIN_SHELL_GUEST_WRITES = 'e2e_admin_shell_guest_writes_'; + +// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Compared only; the shell checks the nonce. +if ( wp_doing_ajax() && isset( $_GET['action'] ) && 'jetpack_admin_shell_guest' === wp_unslash( $_GET['action'] ) ) { + $e2e_admin_shell_writes = array(); + $e2e_admin_shell_log = static function ( $key ) use ( &$e2e_admin_shell_writes ) { + // Transients are caches that expire on their own; `cron` is rescheduled by whichever request spawns cron. + if ( ! preg_match( '/^option:(_site)?_transient_/', $key ) && 'option:cron' !== $key ) { + $e2e_admin_shell_writes[] = $key; + } + }; + foreach ( array( 'added_option', 'updated_option', 'deleted_option' ) as $e2e_admin_shell_hook ) { + add_action( + $e2e_admin_shell_hook, + static function ( $option ) use ( $e2e_admin_shell_log ) { + $e2e_admin_shell_log( "option:$option" ); + } + ); + } + foreach ( array( 'added_user_meta', 'updated_user_meta', 'deleted_user_meta' ) as $e2e_admin_shell_hook ) { + add_action( + $e2e_admin_shell_hook, + static function ( $meta_id, $user_id, $meta_key ) use ( $e2e_admin_shell_log ) { + $e2e_admin_shell_log( "user_meta:$meta_key" ); + }, + 10, + 3 + ); + } + add_action( + 'shutdown', + static function () use ( &$e2e_admin_shell_writes ) { + if ( ! $e2e_admin_shell_writes ) { + return; + } + // One row per request, so parallel hovers can't overwrite each other's log. + add_option( + E2E_ADMIN_SHELL_GUEST_WRITES . wp_generate_uuid4(), + array( + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Logged only. + 'member' => isset( $_GET['member'] ) ? sanitize_key( wp_unslash( $_GET['member'] ) ) : '', + 'writes' => array_values( array_unique( $e2e_admin_shell_writes ) ), + ), + '', + false + ); + }, + 0 + ); +} + +/* + * The hover test reads that log here. With `reset=1` it also clears the log and the values earlier hover + * bugs saved, so a rerun on the same site can catch them again. + */ +add_action( + 'wp_ajax_e2e_admin_shell_guest_writes', + static function () { + global $wpdb; + if ( ! current_user_can( 'manage_options' ) ) { + wp_send_json_error( null, 403, JSON_UNESCAPED_SLASHES ); + } + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Test-only lookup by prefix. + $names = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s", $wpdb->esc_like( E2E_ADMIN_SHELL_GUEST_WRITES ) . '%' ) ); + $log = array_map( 'get_option', $names ); + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Test-only, admins only. + if ( ! empty( $_GET['reset'] ) ) { + array_map( 'delete_option', $names ); + // What the Forms hover bug saved. Settings' hover writes need WordPress.com answers this site never gets. + delete_option( 'jetpack_forms_classic_state' ); + } + wp_send_json_success( $log, null, JSON_UNESCAPED_SLASHES ); + } +); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts index 105615d614c1..85fb81071858 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/accessibility.test.ts @@ -88,22 +88,6 @@ const ROUND_TRIP: [ string, string, Go ][] = [ ]; const STEP_NAMES = [ 'switching to Forms', 'switching back to My Jetpack', 'going Back to Forms' ]; -/** - * Walk the round trip up to step `i` and run `check` only after that step. - * - * @param page - Page under test. - * @param i - Index into `ROUND_TRIP`. - * @param check - Assertion for the last step. - * @param reset - Runs before the last step. - */ -async function walkTo( page: Page, i: number, check: Go, reset?: Go ): Promise< void > { - let step = 0; - await walk( page, ROUND_TRIP.slice( 0, i + 1 ), { - before: ( p, slug ) => ( step === i && reset ? reset( p, slug ) : Promise.resolve() ), - after: ( p, slug ) => ( step++ === i ? check( p, slug ) : Promise.resolve() ), - } ); -} - /** * Open My Jetpack, then take `steps`, checking each landed in the shell before `after` runs. * @@ -159,10 +143,13 @@ test.describe( 'Admin shell: accessibility of in-shell navigation', () => { await installA11yProbe( page ); } ); - // One test per step, so a failure names the step that lost focus. - STEP_NAMES.forEach( ( name, i ) => { - test( `focus moves to the shown page’s heading after ${ name }`, async ( { page } ) => { - await walkTo( page, i, ( p, slug ) => expect( mainHeading( p, slug ) ).toBeFocused() ); + test( 'focus moves to the shown page’s heading after each step of a round trip', async ( { + page, + } ) => { + let step = 0; + await walk( page, ROUND_TRIP, { + after: ( p, slug ) => + expect( mainHeading( p, slug ), `focus after ${ STEP_NAMES[ step++ ] }` ).toBeFocused(), } ); } ); @@ -180,22 +167,18 @@ test.describe( 'Admin shell: accessibility of in-shell navigation', () => { .toContainEqual( { politeness: 'polite', text: 'Probe check' } ); } ); - STEP_NAMES.slice( 0, 2 ).forEach( ( name, i ) => { - test( `the new page title is announced politely after ${ name }`, async ( { page } ) => { - await walkTo( - page, - i, - ( p, slug ) => - expect - .poll( () => announcements( p ), `announcement for ${ slug }` ) - .toContainEqual( - expect.objectContaining( { - politeness: 'polite', - text: expect.stringContaining( member( slug ).title ), - } ) - ), - resetA11yProbe - ); + test( 'the new page title is announced politely after each switch', async ( { page } ) => { + await walk( page, ROUND_TRIP.slice( 0, 2 ), { + before: resetA11yProbe, + after: ( p, slug ) => + expect + .poll( () => announcements( p ), `announcement for ${ slug }` ) + .toContainEqual( + expect.objectContaining( { + politeness: 'polite', + text: expect.stringContaining( member( slug ).title ), + } ) + ), } ); } ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/api-fetch-nonce.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/api-fetch-nonce.test.ts index c00b1b5e8216..de3a4c24cdb2 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/api-fetch-nonce.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/api-fetch-nonce.test.ts @@ -64,32 +64,39 @@ test.describe( 'Admin shell: a stale REST nonce', () => { await installShellProbe( page ); } ); - for ( const [ first, ...switches ] of TOURS ) { - test( `refreshes once after ${ [ first, ...switches ].join( ' → ' ) }`, async ( { page } ) => { - await openMember( page, first ); - for ( const slug of switches ) { - await switchTo( page, slug ); - } - const refreshes = await routeStaleNonce( page ); + TOURS.forEach( ( [ first, ...switches ], i ) => { + // The first switch is where a guest could add a second nonce middleware. + const details = i === 1 ? { tag: '@smoke' } : {}; + + test( + `refreshes once after ${ [ first, ...switches ].join( ' → ' ) }`, + details, + async ( { page } ) => { + await openMember( page, first ); + for ( const slug of switches ) { + await switchTo( page, slug ); + } + const refreshes = await routeStaleNonce( page ); - const outcome = await page.evaluate( - ( { probe } ) => - Promise.race( [ - ( window as unknown as ApiFetchWindow ).wp - .apiFetch( { path: `/wp/v2/users/me?${ probe }=1` } ) - .then( - () => 'ok', - ( error: { code?: string } ) => `error: ${ error.code }` - ), - // Long enough for a looping page to refresh many times. - new Promise( resolve => setTimeout( () => resolve( 'timed out' ), 10000 ) ), - ] ), - { probe: PROBE } - ); - await page.unrouteAll( { behavior: 'ignoreErrors' } ); + const outcome = await page.evaluate( + ( { probe } ) => + Promise.race( [ + ( window as unknown as ApiFetchWindow ).wp + .apiFetch( { path: `/wp/v2/users/me?${ probe }=1` } ) + .then( + () => 'ok', + ( error: { code?: string } ) => `error: ${ error.code }` + ), + // Long enough for a looping page to refresh many times. + new Promise( resolve => setTimeout( () => resolve( 'timed out' ), 10000 ) ), + ] ), + { probe: PROBE } + ); + await page.unrouteAll( { behavior: 'ignoreErrors' } ); - expect( outcome, 'the retry succeeds' ).toBe( 'ok' ); - expect( refreshes(), 'nonce refreshes' ).toBe( 1 ); - } ); - } + expect( outcome, 'the retry succeeds' ).toBe( 'ok' ); + expect( refreshes(), 'nonce refreshes' ).toBe( 1 ); + } + ); + } ); } ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/contract.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/contract.test.ts index fca1901069fd..b8310ff73f79 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/contract.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/contract.test.ts @@ -15,32 +15,38 @@ test.describe( 'Admin shell: contract hooks and events', () => { await installShellProbe( page ); } ); - test( 'each app container carries data-shell-page and data-shell-state', async ( { page } ) => { - await openMember( page, 'my-jetpack' ); - await switchTo( page, FORMS ); - const state = await readShell( page ); - expect( state.source ).toBe( 'hooks' ); - expect( state.apps ).toEqual( { 'my-jetpack': 'hidden', [ FORMS ]: 'visible' } ); - } ); + test( + 'each app container carries data-shell-page and data-shell-state', + { tag: '@smoke' }, + async ( { page } ) => { + await openMember( page, 'my-jetpack' ); + await switchTo( page, FORMS ); + const state = await readShell( page ); + expect( state.source ).toBe( 'hooks' ); + expect( state.apps ).toEqual( { 'my-jetpack': 'hidden', [ FORMS ]: 'visible' } ); + } + ); - test( 'page-shown fires on a full load and on every switch, page-hidden on leaving', async ( { - page, - } ) => { - await openMember( page, 'my-jetpack' ); - await switchTo( page, FORMS ); - await switchTo( page, 'my-jetpack' ); - const events = await shellEvents( page ); - const shown = events - .filter( e => e.type === 'jetpack-admin-shell:page-shown' ) - .map( e => [ e.detail.page, e.detail.previous ?? null, e.detail.firstShow ] ); - expect( shown ).toEqual( [ - [ 'my-jetpack', null, true ], - [ FORMS, 'my-jetpack', true ], - [ 'my-jetpack', FORMS, false ], - ] ); - const hidden = events - .filter( e => e.type === 'jetpack-admin-shell:page-hidden' ) - .map( e => e.detail.page ); - expect( hidden ).toEqual( [ 'my-jetpack', FORMS ] ); - } ); + test( + 'page-shown fires on a full load and on every switch, page-hidden on leaving', + { tag: '@smoke' }, + async ( { page } ) => { + await openMember( page, 'my-jetpack' ); + await switchTo( page, FORMS ); + await switchTo( page, 'my-jetpack' ); + const events = await shellEvents( page ); + const shown = events + .filter( e => e.type === 'jetpack-admin-shell:page-shown' ) + .map( e => [ e.detail.page, e.detail.previous ?? null, e.detail.firstShow ] ); + expect( shown ).toEqual( [ + [ 'my-jetpack', null, true ], + [ FORMS, 'my-jetpack', true ], + [ 'my-jetpack', FORMS, false ], + ] ); + const hidden = events + .filter( e => e.type === 'jetpack-admin-shell:page-hidden' ) + .map( e => e.detail.page ); + expect( hidden ).toEqual( [ 'my-jetpack', FORMS ] ); + } + ); } ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/fallback.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/fallback.test.ts index 3a3a057e56ad..79b62bb93a01 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/fallback.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/fallback.test.ts @@ -1,13 +1,11 @@ import { test, expect } from '@playwright/test'; import { - MEMBERS, expectShown, installShellProbe, isShellActive, markDocument, menuLink, openMember, - skipUnlessOnSite, sameDocument, waitForShown, } from '../../helpers/admin-shell-helper'; @@ -19,32 +17,32 @@ test.describe( 'Admin shell: fallback', () => { await installShellProbe( page ); } ); - for ( const m of MEMBERS.filter( x => x.slug !== 'my-jetpack' ) ) { - test( `with ?jetpack_admin_shell=0, clicking ${ m.slug } is a full page load`, async ( { - page, - } ) => { - await skipUnlessOnSite( page, m.slug ); - await page.goto( '/wp-admin/admin.php?page=my-jetpack&jetpack_admin_shell=0' ); - await waitForShown( page, 'my-jetpack' ); - expect( await isShellActive( page ), 'shell is off for this request' ).toBe( false ); - await markDocument( page ); - await menuLink( page, m.slug ).click(); - await waitForShown( page, m.slug ); - expect( await sameDocument( page ), 'a new document loaded' ).toBe( false ); - } ); - } - - test( 'a failing guest endpoint still gets the user to the page', async ( { page } ) => { - let aborted = 0; - await page.route( /admin-ajax\.php\?.*action=jetpack_admin_shell_guest/, route => { - aborted++; - return route.abort(); - } ); - await openMember( page, 'my-jetpack' ); + // The shell never starts for the request, so every member link is a plain link; one is enough. + test( 'with ?jetpack_admin_shell=0, clicking Forms is a full page load', async ( { page } ) => { + await page.goto( '/wp-admin/admin.php?page=my-jetpack&jetpack_admin_shell=0' ); + await waitForShown( page, 'my-jetpack' ); + expect( await isShellActive( page ), 'shell is off for this request' ).toBe( false ); + await markDocument( page ); await menuLink( page, FORMS ).click(); await waitForShown( page, FORMS ); - expect( aborted, 'the guest endpoint was called and failed' ).toBeGreaterThan( 0 ); - await expectShown( page, FORMS ); - expect( new URL( page.url() ).searchParams.get( 'page' ) ).toBe( FORMS ); + expect( await sameDocument( page ), 'a new document loaded' ).toBe( false ); } ); + + test( + 'a failing guest endpoint still gets the user to the page', + { tag: '@smoke' }, + async ( { page } ) => { + let aborted = 0; + await page.route( /admin-ajax\.php\?.*action=jetpack_admin_shell_guest/, route => { + aborted++; + return route.abort(); + } ); + await openMember( page, 'my-jetpack' ); + await menuLink( page, FORMS ).click(); + await waitForShown( page, FORMS ); + expect( aborted, 'the guest endpoint was called and failed' ).toBeGreaterThan( 0 ); + await expectShown( page, FORMS ); + expect( new URL( page.url() ).searchParams.get( 'page' ) ).toBe( FORMS ); + } + ); } ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/history.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/history.test.ts index 41c0acdad048..584d08f50234 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/history.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/history.test.ts @@ -1,11 +1,9 @@ import { test, expect, type Page } from '@playwright/test'; import { - MEMBERS, expectShown, installShellProbe, menuLink, openMember, - skipUnlessOnSite, switchTo, waitForShown, where, @@ -89,15 +87,6 @@ test.describe( 'Admin shell: history', () => { } ); } - for ( const m of MEMBERS ) { - test( `full load of ${ m.slug } renders with the shell on`, async ( { page } ) => { - await skipUnlessOnSite( page, m.slug ); - await openMember( page, m.slug ); - await expectShown( page, m.slug ); - expect( await where( page ) ).toMatch( m.landing ); - } ); - } - test( 'reload keeps the member that was switched to', async ( { page } ) => { await openMember( page, 'my-jetpack' ); await switchTo( page, FORMS ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/hover-side-effects.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/hover-side-effects.test.ts new file mode 100644 index 000000000000..c0f403248ed2 --- /dev/null +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/hover-side-effects.test.ts @@ -0,0 +1,54 @@ +import { test, expect, type Page } from '@playwright/test'; +import { MEMBERS, installShellProbe, menuLink, openMember } from '../../helpers/admin-shell-helper'; + +/* Hovering Forms used to save its classic forms state; plugins/e2e-admin-shell.php logs such writes. + * The optional members aren't on the CI site. */ +const GUESTS = MEMBERS.filter( m => m.slug !== 'my-jetpack' && ! m.optional ).map( m => m.slug ); +const LOG = '/wp-admin/admin-ajax.php?action=e2e_admin_shell_guest_writes'; + +type GuestWrites = { member: string; writes: string[] }[]; + +/** + * Option and user meta writes the shell's guest requests made, as the e2e plugin logged them. + * + * @param page - Page under test, for its session. + * @return Writes per guest request. + */ +async function guestWrites( page: Page ): Promise< GuestWrites > { + const response = await page.request.get( LOG ); + expect( response.ok(), 'the e2e plugin answers' ).toBe( true ); + return ( await response.json() ).data; +} + +test.describe( 'Admin shell: hover side effects', () => { + test.beforeEach( async ( { page } ) => { + // Enough memory that the shell prewarms every member on hover. + await page.addInitScript( () => + Object.defineProperty( Navigator.prototype, 'deviceMemory', { get: () => 8 } ) + ); + await installShellProbe( page ); + } ); + + test( 'hovering each dashboard in the menu saves nothing', async ( { page } ) => { + const reset = await page.request.get( `${ LOG }&reset=1` ); + test.skip( ! reset.ok(), 'Needs the e2e-admin-shell plugin' ); + const fetched = new Set< string >(); + // Finished, not just answered: the plugin logs the writes as the request shuts down. + page.on( 'requestfinished', request => { + const url = new URL( request.url() ); + if ( url.searchParams.get( 'action' ) === 'jetpack_admin_shell_guest' ) { + fetched.add( url.searchParams.get( 'member' ) ?? '' ); + } + } ); + await openMember( page, 'my-jetpack' ); + + for ( const slug of GUESTS ) { + await menuLink( page, slug ).hover(); + await expect + .poll( () => fetched.has( slug ), { message: `hovering ${ slug } prewarms it` } ) + .toBe( true ); + } + + expect( await guestWrites( page ) ).toEqual( [] ); + } ); +} ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts index 311c6ab649f8..c7bade035c5c 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/kept-state.test.ts @@ -4,6 +4,7 @@ import { menuLink, openMember, switchTo, + waitForQuiet, where, } from '../../helpers/admin-shell-helper'; @@ -53,6 +54,8 @@ test.describe( 'Admin shell: state survives a round trip', () => { test( 'scroll position survives a round trip', async ( { page } ) => { await page.setViewportSize( { width: 1280, height: 500 } ); await openMember( page, 'my-jetpack' ); + // Late cards above the fold would shift a scroll position set now (scroll anchoring). + await waitForQuiet( page, 8000 ); // Playwright scrolls a link out from under the fixed admin bar before clicking it, moving the page. const belowAdminBar = await menuLink( page, FORMS ).evaluate( a => diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/leave-guard.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/leave-guard.test.ts deleted file mode 100644 index d059199fb881..000000000000 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/leave-guard.test.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { test, expect, type Page } from '@playwright/test'; -import { - installShellProbe, - menuLink, - openMember, - readShell, - switchTo, - withinDocument, -} from '../../helpers/admin-shell-helper'; - -const NEWSLETTER = 'jetpack-newsletter'; -const EDIT = 'Admin shell leave guard'; - -/** - * Open Newsletter's Settings tab and leave an unsaved edit in it. - * - * @param page - Page under test. - * @return The edited field. - */ -async function editNewsletterSettings( page: Page ) { - await openMember( page, 'my-jetpack' ); - test.skip( ! ( await menuLink( page, NEWSLETTER ).count() ), 'Newsletter is not on this site' ); - await switchTo( page, NEWSLETTER ); - await page.getByRole( 'tab', { name: 'Settings' } ).filter( { visible: true } ).click(); - const sender = page.getByRole( 'textbox', { name: 'Sender name' } ).filter( { visible: true } ); - await sender.fill( EDIT ); - return sender; -} - -/** - * Answer every native dialog with `answer.accept`, and record its type. - * - * @param page - Page under test. - * @return The recorded dialog types, and the answer to give the next ones. - */ -function answerDialogs( page: Page ) { - const state = { seen: [] as string[], accept: true }; - page.on( 'dialog', dialog => { - state.seen.push( dialog.type() ); - return state.accept ? dialog.accept() : dialog.dismiss(); - } ); - return state; -} - -test.describe( 'Admin shell: unsaved changes', () => { - test.beforeEach( async ( { page } ) => { - await installShellProbe( page ); - } ); - - test( 'a menu click away from unsaved Newsletter Settings keeps the edit without asking', async ( { - page, - } ) => { - const dialogs = answerDialogs( page ); - const sender = await editNewsletterSettings( page ); - - await switchTo( page, 'my-jetpack' ); - await switchTo( page, NEWSLETTER ); - await expect( sender ).toHaveValue( EDIT ); - expect( dialogs.seen ).toEqual( [] ); - } ); - - test( 'a link to another Newsletter tab asks before dropping unsaved Settings', async ( { - page, - } ) => { - const dialogs = answerDialogs( page ); - const sender = await editNewsletterSettings( page ); - await switchTo( page, 'my-jetpack' ); - dialogs.accept = false; - - // No Jetpack link targets another Newsletter tab yet; a future one would take this path. - await page.evaluate( slug => { - const a = document.createElement( 'a' ); - a.id = 'leave-guard-link'; - a.textContent = 'Newsletter subscribers'; - a.href = `admin.php?page=${ slug }&p=${ encodeURIComponent( '/?tab=subscribers' ) }`; - // Above the app's fixed header, so the click is a real one. - a.style.cssText = 'position: fixed; bottom: 0; right: 0; z-index: 100000'; - document.getElementById( 'wpbody-content' )!.append( a ); - }, NEWSLETTER ); - await withinDocument( page, 'the declined link', async () => { - await page.locator( '#leave-guard-link' ).click(); - await expect.poll( () => dialogs.seen ).toEqual( [ 'confirm' ] ); - } ); - expect( ( await readShell( page ) ).visible ).toBe( 'my-jetpack' ); - - dialogs.accept = true; - await switchTo( page, NEWSLETTER ); - await expect( sender ).toHaveValue( EDIT ); - } ); -} ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/memory.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/memory.test.ts index 83c8b7b64b94..2639482227a0 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/memory.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/memory.test.ts @@ -5,13 +5,15 @@ import { menuLink, openMember, sameDocument, - skipUnlessOnSite, switchTo, waitForShown, withinDocument, } from '../../helpers/admin-shell-helper'; const FORMS = 'jetpack-forms-responses-wp-admin'; +/* Members every CI site has, so the test runs there. */ +const AI = 'jetpack-ai'; +const PODCAST = 'jetpack-podcast'; test.describe( 'Admin shell: memory budget', () => { test.beforeEach( async ( { page } ) => { @@ -23,16 +25,15 @@ test.describe( 'Admin shell: memory budget', () => { } ); test( 'past the live-app limit, a new dashboard is a full page load', async ( { page } ) => { - await skipUnlessOnSite( page, 'jetpack-seo', 'jetpack-boost' ); await openMember( page, 'my-jetpack' ); await switchTo( page, FORMS ); - await switchTo( page, 'jetpack-seo' ); + await switchTo( page, AI ); // Live dashboards still switch in place at the limit. await switchTo( page, FORMS ); await markDocument( page ); - await menuLink( page, 'jetpack-boost' ).click(); - await waitForShown( page, 'jetpack-boost' ); + await menuLink( page, PODCAST ).click(); + await waitForShown( page, PODCAST ); expect( await sameDocument( page ), 'a new document loaded' ).toBe( false ); // The page load freed the budget. @@ -42,10 +43,9 @@ test.describe( 'Admin shell: memory budget', () => { test( 'past the live-app limit, a hidden dashboard with unsaved changes keeps the page', async ( { page, } ) => { - await skipUnlessOnSite( page, 'jetpack-seo', 'jetpack-boost' ); await openMember( page, 'my-jetpack' ); await switchTo( page, FORMS ); - await switchTo( page, 'jetpack-seo' ); + await switchTo( page, AI ); // Stands in for My Jetpack with an unsaved edit whose user chooses to stay. await page.evaluate( () => window.addEventListener( 'jetpack-admin-shell:before-leave', event => { @@ -58,13 +58,13 @@ test.describe( 'Admin shell: memory budget', () => { ); await withinDocument( page, 'the cancelled page load', async () => { - await menuLink( page, 'jetpack-boost' ).click(); + await menuLink( page, PODCAST ).click(); await expect .poll( () => page.evaluate( () => ( window as unknown as { __askedFor?: string } ).__askedFor ?? '' ) ) - .toContain( 'page=jetpack-boost' ); + .toContain( 'page=jetpack-podcast' ); } ); - expect( new URL( page.url() ).searchParams.get( 'page' ) ).toBe( 'jetpack-seo' ); + expect( new URL( page.url() ).searchParams.get( 'page' ) ).toBe( AI ); } ); } ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/navigation-matrix.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/navigation-matrix.test.ts index 31ed3ad961d3..ae7722f16a2a 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/navigation-matrix.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/navigation-matrix.test.ts @@ -24,12 +24,15 @@ test.describe( 'Admin shell: navigation matrix', () => { } ); for ( const [ a, b ] of pairs ) { - test( `${ a.slug } → ${ b.slug } → ${ a.slug }`, async ( { page } ) => { + test( `${ a.slug } → ${ b.slug } → ${ a.slug }`, { tag: '@smoke' }, async ( { page } ) => { await skipUnlessOnSite( page, a.slug, b.slug ); await openMember( page, a.slug ); await expect( menuLink( page, b.slug ), `${ b.slug } is in the menu` ).toBeAttached(); await expectShown( page, a.slug ); const leftAt = await where( page ); + expect( leftAt, `a full load of ${ a.slug } lands where it does with the shell off` ).toMatch( + a.landing + ); await switchTo( page, b.slug ); await expectShown( page, b.slug ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/shell-off.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/shell-off.test.ts index 97fd07ac4863..fa29991e4190 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/shell-off.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/shell-off.test.ts @@ -21,7 +21,7 @@ test.describe( 'Admin shell off: smoke', () => { await installShellProbe( page ); } ); - test( 'every member loads and links to the next', async ( { page } ) => { + test( 'every member loads and links to the next', { tag: '@smoke' }, async ( { page } ) => { const [ first, ...rest ] = MEMBERS; await page.goto( `/wp-admin/admin.php?page=${ first.slug }` ); await waitForShown( page, first.slug ); diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts index 97e69fbe7f23..e0ec15c92242 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts @@ -1,35 +1,22 @@ import { test, expect, type Page } from '@playwright/test'; import { - MEMBERS, VIEW_EVENT, installShellProbe, openMember, settle, - skipUnlessOnSite, switchTo, tracksEvents, } from '../../helpers/admin-shell-helper'; const FORMS = 'jetpack-forms-responses-wp-admin'; -/* The other members may record no views on the unconnected test site, which would pass vacuously. */ -const TRACKED = MEMBERS.filter( m => [ 'my-jetpack', FORMS ].includes( m.slug ) ); +/* My Jetpack is the one member that records views on the unconnected test site; Forms is the other side. */ +const MJ = 'my-jetpack'; /* Tracks calls go out after render: the longest to wait for one, and the quiet spell that ends a wait. */ const SETTLE = 5000; const QUIET = 1000; -/** - * View events recorded since `from` events had been seen. - * - * @param page - Page under test. - * @param from - Count of events already seen. - * @return New view event names. - */ -async function viewsSince( page: Page, from: number ): Promise< string[] > { - return ( await tracksEvents( page ) ).slice( from ).filter( name => VIEW_EVENT.test( name ) ); -} - /** * Wait until `done` holds for the view events since `from` and no event has arrived for `QUIET`, or `SETTLE` passes. * @@ -96,53 +83,23 @@ test.describe( 'Admin shell: Tracks page views', () => { await installShellProbe( page ); } ); - for ( const m of TRACKED ) { - const other = TRACKED.find( x => x !== m )!.slug; - - test( `the first switch to ${ m.slug } records the page view a full load does`, async ( { - page, - } ) => { - await skipUnlessOnSite( page, m.slug ); - const expected = await fullLoadViews( page, m.slug ); - await openMember( page, other ); - expect( await viewsOnSwitch( page, m.slug, expected ) ).toEqual( - expect.arrayContaining( expected ) - ); - } ); - - test( `a return switch to ${ m.slug } records the page view again`, async ( { page } ) => { - await skipUnlessOnSite( page, m.slug ); - const expected = await fullLoadViews( page, m.slug ); - await openMember( page, other ); - await switchTo( page, m.slug ); - await switchTo( page, other ); - expect( await viewsOnSwitch( page, m.slug, expected ) ).toEqual( - expect.arrayContaining( expected ) - ); - } ); - } - - test( 'hidden apps record no page views while another is shown', async ( { page } ) => { + test( 'the first switch to My Jetpack records the page view a full load does', async ( { + page, + } ) => { + const expected = await fullLoadViews( page, MJ ); await openMember( page, FORMS ); - const formsViews = new Set( await waitForViews( page, 0, any ) ); - await openMember( page, 'my-jetpack' ); - const own = new Set( await waitForViews( page, 0, any ) ); - expect( own.size, 'the probe sees My Jetpack’s own page view' ).toBeGreaterThan( 0 ); - test.skip( - [ ...formsViews ].every( name => own.has( name ) ), - 'Forms records no view event of its own, so a leak would not show' + expect( await viewsOnSwitch( page, MJ, expected ) ).toEqual( + expect.arrayContaining( expected ) ); + } ); - // Forms' router stays mounted while hidden; My Jetpack's URL writes must not reach it. + test( 'a return switch to My Jetpack records the page view again', async ( { page } ) => { + const expected = await fullLoadViews( page, MJ ); + await openMember( page, FORMS ); + await switchTo( page, MJ ); await switchTo( page, FORMS ); - await switchTo( page, 'my-jetpack' ); - await waitForViews( page, 0 ); - const seen = ( await tracksEvents( page ) ).length; - await page.getByRole( 'tab', { name: 'Features' } ).filter( { visible: true } ).click(); - await settle( page, SETTLE ); - const foreign = ( await viewsSince( page, seen ) ).filter( - name => formsViews.has( name ) && ! own.has( name ) + expect( await viewsOnSwitch( page, MJ, expected ) ).toEqual( + expect.arrayContaining( expected ) ); - expect( foreign, 'view events from apps that are not shown' ).toEqual( [] ); } ); } ); From f03ddaada52e7ae330cd27ac20773b434be06042 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 18 Nov 2026 09:19:37 -0600 Subject: [PATCH 27/34] Admin shell e2e: Widen full-suite triggers, and isolate the hover test - Run the full suite when a PR changes the Jetpack plugin's Settings or AI dashboards, the shell wiring, the suite itself, its CI files, or the e2e environment. Drop Boost from the list: it can't reach this entry. - Drop the Playwright browser cache: on pull requests it only served reruns. - Add the hover project only with ADMIN_SHELL_HOVER=1 and Chromium, which the CI script sets for its own run, and fail rather than skip in CI. - Save the guest write log at the end of shutdown, after other shutdown saves. --- .github/files/e2e-tests/e2e-matrix.js | 44 ++++++++++++++++--- .github/workflows/e2e-tests.yml | 8 ---- projects/plugins/jetpack/tests/e2e/README.md | 4 +- .../jetpack/tests/e2e/bin/admin-shell-ci.sh | 4 +- .../e2e/playwright.admin-shell.config.ts | 28 +++++++----- .../tests/e2e/plugins/e2e-admin-shell.php | 2 +- .../admin-shell/hover-side-effects.test.ts | 6 ++- 7 files changed, 63 insertions(+), 33 deletions(-) diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index 0eacd33277df..638edbdf90cf 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -44,7 +44,7 @@ const projects = [ testArgs: [], targets: [ 'plugins/jetpack' ], buildGroup: 'jetpack-core', - // On pull requests: WordPress latest only, and only the @smoke tests unless the PR itself changes one of these. + // On pull requests: WordPress latest only, and only the @smoke tests unless the PR itself changes one of these projects or files. pullRequest: { wpVersions: [ 'latest' ], fullSuiteFor: [ @@ -61,8 +61,15 @@ const projects = [ 'packages/newsletter', 'packages/seo', 'packages/videopress', - 'plugins/boost', ], + // The Settings and AI dashboards and the shell wiring in the Jetpack plugin, the suite itself, and how CI runs it. + fullSuiteForFiles: new RegExp( + [ + '^projects/plugins/jetpack/(_inc/lib/admin-pages/|routes/(settings|ai-hub)/|load-jetpack\\.php|class\\.jetpack-admin\\.php)', + '^projects/plugins/jetpack/tests/e2e/(specs/admin-shell/|helpers/admin-shell|plugins/e2e-admin-shell|bin/admin-shell|playwright\\.admin-shell)', + '^\\.github/(workflows/e2e-tests\\.yml|files/e2e-tests/)', + ].join( '|' ) + ), }, }, { @@ -202,16 +209,38 @@ function minWpVersion() { const matrix = []; +/** + * The pull request's diff range, for `git diff`. + * + * @return {string} `base...head`. + */ +function pullRequestDiff() { + const event = JSON.parse( fs.readFileSync( process.env.GITHUB_EVENT_PATH, 'utf8' ) ); + return `${ event.pull_request.base.sha }...${ event.pull_request.head.sha }`; +} + +/** + * Files the pull request changes. + * + * @return {string[]} Paths from the repository root. + */ +function changedFiles() { + return execSync( `git diff --name-only ${ pullRequestDiff() }` ) + .toString() + .split( '\n' ) + .filter( Boolean ); +} + /** * Projects the pull request changes itself, without the projects that only depend on them. * * @return {Set} Project slugs, e.g. 'packages/admin-ui'. */ function directlyChangedProjects() { - const event = JSON.parse( fs.readFileSync( process.env.GITHUB_EVENT_PATH, 'utf8' ) ); - const diff = `${ event.pull_request.base.sha }...${ event.pull_request.head.sha }`; + const diff = pullRequestDiff(); return new Set( - execSync( `pnpm jetpack dependencies list --git-changed=${ diff }` ) + // `--extra=e2e`: a change to the e2e environment counts as a change to every project. + execSync( `pnpm jetpack dependencies list --extra=e2e --git-changed=${ diff }` ) .toString() .split( '\n' ) .filter( Boolean ) @@ -261,8 +290,11 @@ switch ( process.env.GITHUB_EVENT_NAME ) { pushBothVersions( project ); continue; } + const { fullSuiteFor, fullSuiteForFiles } = project.pullRequest; const direct = directlyChangedProjects(); - const smoke = ! project.pullRequest.fullSuiteFor.some( slug => direct.has( slug ) ); + const smoke = + ! fullSuiteFor.some( slug => direct.has( slug ) ) && + ! changedFiles().some( file => fullSuiteForFiles.test( file ) ); for ( const wpVersion of project.pullRequest.wpVersions ) { matrix.push( { ...project, wpVersion, smoke } ); } diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index c1a121caf77f..77936f4ea1d9 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -265,14 +265,6 @@ jobs: nohup pnpm run tunnel:up "$HOME/tunnel.log" echo "::endgroup::" - - name: Cache Playwright browsers - if: matrix.testScript == 'test:admin-shell:ci' - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ~/.cache/ms-playwright - # The Playwright version is pinned in package.json. - key: playwright-${{ runner.os }}-${{ hashFiles( format( '{0}/package.json', matrix.path ) ) }}-${{ env.ADMIN_SHELL_BROWSERS }} - - name: Run ${{ matrix.project }} tests working-directory: ${{ matrix.path }} env: diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index b2f28a5edb20..1f39a7898948 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -157,14 +157,14 @@ pnpm test:admin-shell - `ADMIN_SHELL_STANDALONE_URL` (with `ADMIN_SHELL_STANDALONE_USER` / `ADMIN_SHELL_STANDALONE_PASSWORD`) is optional: a site with the shell on and only standalone plugins, such as Backup, Social and VideoPress, without the Jetpack plugin (JETPACK-3419). It adds the `standalone` projects; without it there are none. Run it again after installing standalone plugins built against different Admin UI versions. - `ADMIN_SHELL_BROWSERS` (default `chromium,firefox,webkit`) is a comma-separated list of the browsers to install and run. - `ADMIN_SHELL_SMOKE=1` runs only the tests tagged `@smoke`. -- The `hover side effects` project needs `plugins/e2e-admin-shell.php` on the site, and skips without it. +- `ADMIN_SHELL_HOVER=1` adds the `hover side effects` project (Chromium), which needs `plugins/e2e-admin-shell.php` on the site. Run it on its own, with `--project='hover side effects'`: other tests' requests would mix into its log. - Add `--project='shell on: chromium'` to run one browser. Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the `hover side effects` project alone first, then the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. -Pull requests run it in Chromium, against WordPress latest only. A pull request that changes `admin-ui`, `my-jetpack`, `jitm` or a dashboard package (the `fullSuiteFor` list in `e2e-matrix.js`) runs the whole suite; any other pull request that reaches the Jetpack plugin runs only the tests tagged `@smoke` (`ADMIN_SHELL_SMOKE=1`). The post-merge runs against the `jetpack-production` mirror, and manual runs, use all three browsers and the whole suite. +Pull requests run it in Chromium, against WordPress latest only. A pull request that changes `admin-ui`, `my-jetpack`, `jitm`, a dashboard package, the Jetpack plugin's Settings or AI dashboard, the e2e environment or this suite (`fullSuiteFor` and `fullSuiteForFiles` in `e2e-matrix.js`) runs the whole suite; any other pull request that reaches the Jetpack plugin runs only the tests tagged `@smoke` (`ADMIN_SHELL_SMOKE=1`). The post-merge runs against the `jetpack-production` mirror, and manual runs, use all three browsers and the whole suite. Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index eec4f674752f..d23a6eec6de1 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -38,9 +38,9 @@ echo "::group::Shell on" # Jetpack AI's sidebar item shows only with the ai module on, and it needs the stubbed connection to activate. "${WP[@]}" jetpack module activate ai || exit 1 "${WP[@]}" option delete e2e_admin_shell_off >/dev/null 2>&1 -# Alone and first, so no other test saves what it checks that hovering does not. +# A run of its own, first: other tests' requests would mix into the hover test's write log. if [[ "${ADMIN_SHELL_SMOKE:-}" != 1 ]]; then - ADMIN_SHELL_RUN=hover playwright test -c playwright.admin-shell.config.ts --project='hover side effects' "$@" || STATUS=1 + ADMIN_SHELL_RUN=hover ADMIN_SHELL_HOVER=1 playwright test -c playwright.admin-shell.config.ts --project='hover side effects' "$@" || STATUS=1 fi ADMIN_SHELL_RUN=shell-on playwright test -c playwright.admin-shell.config.ts --project='shell on: *' "$@" || STATUS=1 echo "::endgroup::" diff --git a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts index c3e7cf71389f..77cdc2db4e70 100644 --- a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts +++ b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts @@ -98,18 +98,22 @@ export default defineConfig( { storageState: STATE_ON, }, } ) ), - // Chromium only. bin/admin-shell-ci.sh runs it alone, first, so no other test saves what it checks for. - { - name: 'hover side effects', - testMatch: 'hover-side-effects.test.ts', - dependencies: [ 'admin shell login' ], - use: { - ...devices[ 'Desktop Chrome' ], - viewport: { width: 1280, height: 1600 }, - baseURL: onUrl, - storageState: STATE_ON, - }, - }, + // Only with ADMIN_SHELL_HOVER=1; see bin/admin-shell-ci.sh. + ...( process.env.ADMIN_SHELL_HOVER === '1' && browserNames.includes( 'chromium' ) + ? [ + { + name: 'hover side effects', + testMatch: 'hover-side-effects.test.ts', + dependencies: [ 'admin shell login' ], + use: { + ...devices[ 'Desktop Chrome' ], + viewport: { width: 1280, height: 1600 }, + baseURL: onUrl, + storageState: STATE_ON, + }, + }, + ] + : [] ), ...browsers.map( browser => ( { name: `shell off: ${ browser.name }`, testMatch: 'shell-off.test.ts', diff --git a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php index 4d7d83fb5447..70a81807ccb2 100644 --- a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php +++ b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php @@ -115,7 +115,7 @@ static function () use ( &$e2e_admin_shell_writes ) { false ); }, - 0 + PHP_INT_MAX ); } diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/hover-side-effects.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/hover-side-effects.test.ts index c0f403248ed2..b178b357a665 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/hover-side-effects.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/hover-side-effects.test.ts @@ -31,7 +31,9 @@ test.describe( 'Admin shell: hover side effects', () => { test( 'hovering each dashboard in the menu saves nothing', async ( { page } ) => { const reset = await page.request.get( `${ LOG }&reset=1` ); - test.skip( ! reset.ok(), 'Needs the e2e-admin-shell plugin' ); + // In CI the plugin is always on, so a failed reset there is a broken site, not a missing plugin. + test.skip( ! reset.ok() && ! process.env.CI, 'Needs the e2e-admin-shell plugin' ); + expect( reset.ok(), 'the e2e plugin resets its log' ).toBe( true ); const fetched = new Set< string >(); // Finished, not just answered: the plugin logs the writes as the request shuts down. page.on( 'requestfinished', request => { @@ -45,7 +47,7 @@ test.describe( 'Admin shell: hover side effects', () => { for ( const slug of GUESTS ) { await menuLink( page, slug ).hover(); await expect - .poll( () => fetched.has( slug ), { message: `hovering ${ slug } prewarms it` } ) + .poll( () => fetched.has( slug ), { message: `${ slug }'s guest data was fetched` } ) .toBe( true ); } From f7cfba4f892d666453aa7bb7424027524e0a2965 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 18 Nov 2026 09:43:18 -0600 Subject: [PATCH 28/34] Admin shell e2e: Fix the smoke flag for matrix entries without one case() needs a boolean predicate, and only the admin shell entry sets smoke, so every other e2e job failed to start its test step. --- .github/workflows/e2e-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 77936f4ea1d9..3be31ec36409 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -271,7 +271,7 @@ jobs: JSON_ARGS: ${{ toJSON(matrix.testArgs) }} TEST_SCRIPT: ${{ matrix.testScript || 'test:run' }} # Set by e2e-matrix.js on pull requests that don't change the admin shell or a dashboard it switches to. - ADMIN_SHELL_SMOKE: ${{ case( matrix.smoke, '1', '' ) }} + ADMIN_SHELL_SMOKE: ${{ case( matrix.smoke == true, '1', '' ) }} run: | mapfile -t TEST_ARGS < <(jq -r '.[]' <<<"$JSON_ARGS") pnpm run "$TEST_SCRIPT" "${TEST_ARGS[@]}" From a7cdcdbfdb760dcd7d8014dd3f1b2b27ed299919 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 18 Nov 2026 09:58:47 -0600 Subject: [PATCH 29/34] Admin shell e2e: Fix Phan issues in the e2e plugin, and guard the hover run - Delete log rows in a loop, not array_map(), and pass a real status code. - Run the hover project only when Chromium is among the browsers, since the config only defines it then. - Say that a change to only the e2e workflow files doesn't queue the entry. --- .github/files/e2e-tests/e2e-matrix.js | 2 +- projects/plugins/jetpack/tests/e2e/README.md | 2 +- projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh | 2 +- .../plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php | 6 ++++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index 638edbdf90cf..d2c2c32dc8b9 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -62,7 +62,7 @@ const projects = [ 'packages/seo', 'packages/videopress', ], - // The Settings and AI dashboards and the shell wiring in the Jetpack plugin, the suite itself, and how CI runs it. + // The Settings and AI dashboards and the shell wiring in the Jetpack plugin, the suite itself, and its CI files (when the PR also reaches the plugin). fullSuiteForFiles: new RegExp( [ '^projects/plugins/jetpack/(_inc/lib/admin-pages/|routes/(settings|ai-hub)/|load-jetpack\\.php|class\\.jetpack-admin\\.php)', diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index 1f39a7898948..359a5b5fd373 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -164,7 +164,7 @@ Tests read shell state only through `readShell()` in `helpers/admin-shell-helper In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the `hover side effects` project alone first, then the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. -Pull requests run it in Chromium, against WordPress latest only. A pull request that changes `admin-ui`, `my-jetpack`, `jitm`, a dashboard package, the Jetpack plugin's Settings or AI dashboard, the e2e environment or this suite (`fullSuiteFor` and `fullSuiteForFiles` in `e2e-matrix.js`) runs the whole suite; any other pull request that reaches the Jetpack plugin runs only the tests tagged `@smoke` (`ADMIN_SHELL_SMOKE=1`). The post-merge runs against the `jetpack-production` mirror, and manual runs, use all three browsers and the whole suite. +Pull requests run it in Chromium, against WordPress latest only. A pull request that changes `admin-ui`, `my-jetpack`, `jitm`, a dashboard package, the Jetpack plugin's Settings or AI dashboard, the e2e environment or this suite (`fullSuiteFor` and `fullSuiteForFiles` in `e2e-matrix.js`) runs the whole suite (a change to only the e2e workflow files doesn't queue the entry at all); any other pull request that reaches the Jetpack plugin runs only the tests tagged `@smoke` (`ADMIN_SHELL_SMOKE=1`). The post-merge runs against the `jetpack-production` mirror, and manual runs, use all three browsers and the whole suite. Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index d23a6eec6de1..5a30d790787c 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -39,7 +39,7 @@ echo "::group::Shell on" "${WP[@]}" jetpack module activate ai || exit 1 "${WP[@]}" option delete e2e_admin_shell_off >/dev/null 2>&1 # A run of its own, first: other tests' requests would mix into the hover test's write log. -if [[ "${ADMIN_SHELL_SMOKE:-}" != 1 ]]; then +if [[ "${ADMIN_SHELL_SMOKE:-}" != 1 && " ${BROWSERS[*]} " == *" chromium "* ]]; then ADMIN_SHELL_RUN=hover ADMIN_SHELL_HOVER=1 playwright test -c playwright.admin-shell.config.ts --project='hover side effects' "$@" || STATUS=1 fi ADMIN_SHELL_RUN=shell-on playwright test -c playwright.admin-shell.config.ts --project='shell on: *' "$@" || STATUS=1 diff --git a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php index 70a81807ccb2..deeb4c8a7127 100644 --- a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php +++ b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php @@ -135,10 +135,12 @@ static function () { $log = array_map( 'get_option', $names ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Test-only, admins only. if ( ! empty( $_GET['reset'] ) ) { - array_map( 'delete_option', $names ); + foreach ( $names as $name ) { + delete_option( $name ); + } // What the Forms hover bug saved. Settings' hover writes need WordPress.com answers this site never gets. delete_option( 'jetpack_forms_classic_state' ); } - wp_send_json_success( $log, null, JSON_UNESCAPED_SLASHES ); + wp_send_json_success( $log, 200, JSON_UNESCAPED_SLASHES ); } ); From f66e0163ff1b6208bb5e2ba0cb161f802189d395 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 18 Nov 2026 10:36:22 -0600 Subject: [PATCH 30/34] Admin shell e2e: Run site-wide state specs alone, fix feature-off - feature-off switches Forms off for the whole site, and the hover test watches site-wide writes, so both now run first with one worker (ADMIN_SHELL_ALONE=1), and the parallel run leaves them out. - feature-off posted to /wp-json/, which on a site without pretty permalinks serves the home page with a 200, so Forms never switched off. Use ?rest_route= and require a JSON answer. --- projects/plugins/jetpack/tests/e2e/README.md | 4 ++-- .../jetpack/tests/e2e/bin/admin-shell-ci.sh | 12 +++++++---- .../e2e/playwright.admin-shell.config.ts | 20 +++++++++++-------- .../e2e/specs/admin-shell/feature-off.test.ts | 5 +++-- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index 359a5b5fd373..3396e683de84 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -157,12 +157,12 @@ pnpm test:admin-shell - `ADMIN_SHELL_STANDALONE_URL` (with `ADMIN_SHELL_STANDALONE_USER` / `ADMIN_SHELL_STANDALONE_PASSWORD`) is optional: a site with the shell on and only standalone plugins, such as Backup, Social and VideoPress, without the Jetpack plugin (JETPACK-3419). It adds the `standalone` projects; without it there are none. Run it again after installing standalone plugins built against different Admin UI versions. - `ADMIN_SHELL_BROWSERS` (default `chromium,firefox,webkit`) is a comma-separated list of the browsers to install and run. - `ADMIN_SHELL_SMOKE=1` runs only the tests tagged `@smoke`. -- `ADMIN_SHELL_HOVER=1` adds the `hover side effects` project (Chromium), which needs `plugins/e2e-admin-shell.php` on the site. Run it on its own, with `--project='hover side effects'`: other tests' requests would mix into its log. +- `ADMIN_SHELL_ALONE=1` runs only the specs that change or watch site-wide state (`ALONE` in the config: `feature-off`, and the Chromium `hover side effects` project, which needs `plugins/e2e-admin-shell.php`). Without it, those specs are left out. Run them with `--workers=1`, apart from the rest. - Add `--project='shell on: chromium'` to run one browser. Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. -In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the `hover side effects` project alone first, then the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. +In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the `ALONE` specs first, with one worker, then the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. Pull requests run it in Chromium, against WordPress latest only. A pull request that changes `admin-ui`, `my-jetpack`, `jitm`, a dashboard package, the Jetpack plugin's Settings or AI dashboard, the e2e environment or this suite (`fullSuiteFor` and `fullSuiteForFiles` in `e2e-matrix.js`) runs the whole suite (a change to only the e2e workflow files doesn't queue the entry at all); any other pull request that reaches the Jetpack plugin runs only the tests tagged `@smoke` (`ADMIN_SHELL_SMOKE=1`). The post-merge runs against the `jetpack-production` mirror, and manual runs, use all three browsers and the whole suite. diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index 5a30d790787c..5558b7d4e864 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Runs the admin shell suite against the e2e Docker site from `pnpm env:up`: hover side effects, shell on, then shell off. +# Runs the admin shell suite against the e2e Docker site from `pnpm env:up`: site-wide state specs, shell on, then shell off. # Extra arguments go to every Playwright run. ADMIN_SHELL_SMOKE=1 runs only the @smoke tests. set -uo pipefail @@ -38,9 +38,13 @@ echo "::group::Shell on" # Jetpack AI's sidebar item shows only with the ai module on, and it needs the stubbed connection to activate. "${WP[@]}" jetpack module activate ai || exit 1 "${WP[@]}" option delete e2e_admin_shell_off >/dev/null 2>&1 -# A run of its own, first: other tests' requests would mix into the hover test's write log. -if [[ "${ADMIN_SHELL_SMOKE:-}" != 1 && " ${BROWSERS[*]} " == *" chromium "* ]]; then - ADMIN_SHELL_RUN=hover ADMIN_SHELL_HOVER=1 playwright test -c playwright.admin-shell.config.ts --project='hover side effects' "$@" || STATUS=1 +# The specs that need the site to themselves (ALONE in the config), first and one at a time. +if [[ "${ADMIN_SHELL_SMOKE:-}" != 1 ]]; then + ALONE_PROJECTS=( --project='shell on: *' ) + # The config defines the hover project only for Chromium. + [[ " ${BROWSERS[*]} " == *" chromium "* ]] && ALONE_PROJECTS+=( --project='hover side effects' ) + ADMIN_SHELL_RUN=alone ADMIN_SHELL_ALONE=1 PLAYWRIGHT_WORKERS=1 \ + playwright test -c playwright.admin-shell.config.ts "${ALONE_PROJECTS[@]}" "$@" || STATUS=1 fi ADMIN_SHELL_RUN=shell-on playwright test -c playwright.admin-shell.config.ts --project='shell on: *' "$@" || STATUS=1 echo "::endgroup::" diff --git a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts index 77cdc2db4e70..9fd991b12de5 100644 --- a/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts +++ b/projects/plugins/jetpack/tests/e2e/playwright.admin-shell.config.ts @@ -47,6 +47,11 @@ const browsers = [ // ADMIN_SHELL_SMOKE=1 runs only the tests tagged @smoke; the login setup always runs. const smoke = process.env.ADMIN_SHELL_SMOKE === '1' ? { grep: /@smoke/ } : {}; +/* Specs that change or watch site-wide state, so they need the site to themselves. They run only with + * ADMIN_SHELL_ALONE=1, which bin/admin-shell-ci.sh sets for a one-worker run of their own. */ +const ALONE = [ 'feature-off.test.ts', 'hover-side-effects.test.ts' ]; +const alone = process.env.ADMIN_SHELL_ALONE === '1'; + export default defineConfig( { testDir: './specs/admin-shell', outputDir: `${ runDir }/results`, @@ -83,12 +88,11 @@ export default defineConfig( { }, ...browsers.map( browser => ( { name: `shell on: ${ browser.name }`, - testIgnore: [ - 'auth.setup.ts', - 'shell-off.test.ts', - 'standalone.test.ts', - 'hover-side-effects.test.ts', - ], + ...( alone + ? { testMatch: 'feature-off.test.ts' } + : { + testIgnore: [ 'auth.setup.ts', 'shell-off.test.ts', 'standalone.test.ts', ...ALONE ], + } ), dependencies: [ 'admin shell login' ], ...smoke, use: { @@ -98,8 +102,8 @@ export default defineConfig( { storageState: STATE_ON, }, } ) ), - // Only with ADMIN_SHELL_HOVER=1; see bin/admin-shell-ci.sh. - ...( process.env.ADMIN_SHELL_HOVER === '1' && browserNames.includes( 'chromium' ) + // Chromium only: it checks the server, not the browser. + ...( alone && browserNames.includes( 'chromium' ) ? [ { name: 'hover side effects', diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/feature-off.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/feature-off.test.ts index 12ea8879a073..72d54b3209e4 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/feature-off.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/feature-off.test.ts @@ -26,12 +26,13 @@ const FORMS = 'jetpack-forms-responses-wp-admin'; async function switchForms( page: Page, active: boolean ): Promise< void > { const ok = await page.evaluate( async on => { const nonce = await ( await fetch( '/wp-admin/admin-ajax.php?action=rest-nonce' ) ).text(); - const response = await fetch( '/wp-json/wpcom/v2/my-jetpack/site/features/bulk', { + // `rest_route`: the e2e site has no pretty permalinks, and there `/wp-json/` serves the home page with a 200. + const response = await fetch( '/?rest_route=/wpcom/v2/my-jetpack/site/features/bulk', { method: 'POST', headers: { 'X-WP-Nonce': nonce, 'Content-Type': 'application/json' }, body: JSON.stringify( { active: on, modules: [ 'contact-form' ] } ), } ); - return response.ok; + return response.ok && ( response.headers.get( 'content-type' ) ?? '' ).includes( 'json' ); }, active ); expect( ok, `Forms switched ${ active ? 'on' : 'off' }` ).toBe( true ); } From 9c5df682e090e010f50fc6c9de98ff91810837bd Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 18 Nov 2026 12:03:08 -0600 Subject: [PATCH 31/34] Admin shell e2e: Run the smoke set for Jetpack plugin dashboard changes Settings and AI dashboard changes, and the shell wiring in the Jetpack plugin, no longer select the full suite on pull requests. --- .github/files/e2e-tests/e2e-matrix.js | 3 +-- projects/plugins/jetpack/tests/e2e/README.md | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index d2c2c32dc8b9..84d4b38f4302 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -62,10 +62,9 @@ const projects = [ 'packages/seo', 'packages/videopress', ], - // The Settings and AI dashboards and the shell wiring in the Jetpack plugin, the suite itself, and its CI files (when the PR also reaches the plugin). + // The suite itself, and its CI files (when the PR also reaches the plugin). fullSuiteForFiles: new RegExp( [ - '^projects/plugins/jetpack/(_inc/lib/admin-pages/|routes/(settings|ai-hub)/|load-jetpack\\.php|class\\.jetpack-admin\\.php)', '^projects/plugins/jetpack/tests/e2e/(specs/admin-shell/|helpers/admin-shell|plugins/e2e-admin-shell|bin/admin-shell|playwright\\.admin-shell)', '^\\.github/(workflows/e2e-tests\\.yml|files/e2e-tests/)', ].join( '|' ) diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index 3396e683de84..320e285426c6 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -164,7 +164,7 @@ Tests read shell state only through `readShell()` in `helpers/admin-shell-helper In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the `ALONE` specs first, with one worker, then the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. -Pull requests run it in Chromium, against WordPress latest only. A pull request that changes `admin-ui`, `my-jetpack`, `jitm`, a dashboard package, the Jetpack plugin's Settings or AI dashboard, the e2e environment or this suite (`fullSuiteFor` and `fullSuiteForFiles` in `e2e-matrix.js`) runs the whole suite (a change to only the e2e workflow files doesn't queue the entry at all); any other pull request that reaches the Jetpack plugin runs only the tests tagged `@smoke` (`ADMIN_SHELL_SMOKE=1`). The post-merge runs against the `jetpack-production` mirror, and manual runs, use all three browsers and the whole suite. +Pull requests run it in Chromium, against WordPress latest only. A pull request that changes `admin-ui`, `my-jetpack`, `jitm`, a dashboard package, the e2e environment or this suite (`fullSuiteFor` and `fullSuiteForFiles` in `e2e-matrix.js`) runs the whole suite (a change to only the e2e workflow files doesn't queue the entry at all); any other pull request that reaches the Jetpack plugin, including one that changes only its Settings or AI dashboard, runs only the tests tagged `@smoke` (`ADMIN_SHELL_SMOKE=1`). The post-merge runs against the `jetpack-production` mirror, and manual runs, use all three browsers and the whole suite. Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. From 8f754017907dab167f9eac50b5e1ffa3c516c0d7 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Mon, 30 Nov 2026 10:49:11 -0600 Subject: [PATCH 32/34] Admin shell e2e: Widen the full-suite triggers and schedule every browser Run the full suite on pull requests that change Monetize, Premium Analytics or wp-build-polyfills, and add the Back/Forward test to the smoke set. After merge, run Chromium against WordPress latest on each push to the jetpack-production trunk. Run every browser on both WordPress versions daily. The schedule has its own concurrency group, so pushes can't cancel it, and its failures use the existing Slack job. In CI, fail the Tracks tests when a full load records no views instead of skipping them. Switch Forms back on after the one-worker specs, in case their cleanup fails. Part of JETPACK-3406 --- .github/files/e2e-tests/e2e-matrix.js | 37 ++++++++++++++++--- .github/workflows/e2e-tests.yml | 25 ++++++++++--- projects/plugins/jetpack/tests/e2e/README.md | 12 +++++- .../jetpack/tests/e2e/bin/admin-shell-ci.sh | 2 + .../e2e/specs/admin-shell/history.test.ts | 32 +++++++++------- .../e2e/specs/admin-shell/tracks.test.ts | 9 ++++- 6 files changed, 87 insertions(+), 30 deletions(-) diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index 84d4b38f4302..52757ad50502 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -47,6 +47,7 @@ const projects = [ // On pull requests: WordPress latest only, and only the @smoke tests unless the PR itself changes one of these projects or files. pullRequest: { wpVersions: [ 'latest' ], + browsers: 'chromium', fullSuiteFor: [ 'packages/admin-ui', 'packages/my-jetpack', @@ -61,6 +62,10 @@ const projects = [ 'packages/newsletter', 'packages/seo', 'packages/videopress', + 'packages/monetize', + 'packages/premium-analytics', + // The shell imports its view transitions. + 'packages/wp-build-polyfills', ], // The suite itself, and its CI files (when the PR also reaches the plugin). fullSuiteForFiles: new RegExp( @@ -70,6 +75,9 @@ const projects = [ ].join( '|' ) ), }, + // On pushes to the mirror's trunk. The scheduled run covers the other browsers and WordPress version. + mirrorTrunk: { wpVersions: [ 'latest' ], browsers: 'chromium' }, + scheduled: true, }, { project: 'Jetpack sync', @@ -289,13 +297,13 @@ switch ( process.env.GITHUB_EVENT_NAME ) { pushBothVersions( project ); continue; } - const { fullSuiteFor, fullSuiteForFiles } = project.pullRequest; + const { wpVersions, browsers, fullSuiteFor, fullSuiteForFiles } = project.pullRequest; const direct = directlyChangedProjects(); const smoke = ! fullSuiteFor.some( slug => direct.has( slug ) ) && ! changedFiles().some( file => fullSuiteForFiles.test( file ) ); - for ( const wpVersion of project.pullRequest.wpVersions ) { - matrix.push( { ...project, wpVersion, smoke } ); + for ( const wpVersion of wpVersions ) { + matrix.push( { ...project, wpVersion, browsers, smoke } ); } } break; @@ -323,17 +331,32 @@ switch ( process.env.GITHUB_EVENT_NAME ) { } break; } + case 'schedule': + for ( const project of projects.filter( ( { scheduled } ) => scheduled ) ) { + pushBothVersions( project ); + } + break; case 'repository_dispatch': if ( process.env.DISPATCH_REPO ) { const repoName = process.env.DISPATCH_REPO.split( '/' )[ 1 ]; + const isTrunk = + process.env.DISPATCH_REF_TYPE === 'branch' && process.env.DISPATCH_REF_NAME === 'trunk'; for ( const project of projects ) { const packageJson = JSON.parse( fs.readFileSync( `${ project.path }/package.json`, 'utf8' ) ); - if ( packageJson?.ci?.mirrorName === repoName ) { + if ( packageJson?.ci?.mirrorName !== repoName ) { + continue; + } + if ( ! isTrunk || ! project.mirrorTrunk ) { pushBothVersions( project ); + continue; + } + const { wpVersions, browsers } = project.mirrorTrunk; + for ( const wpVersion of wpVersions ) { + matrix.push( { ...project, wpVersion, browsers } ); } } } else { @@ -344,5 +367,7 @@ switch ( process.env.GITHUB_EVENT_NAME ) { console.error( `Unsupported GITHUB_EVENT_NAME ${ process.env.GITHUB_EVENT_NAME }.` ); } -// `pullRequest` is input for this script, not for the workflow. -console.log( JSON.stringify( matrix.map( ( { pullRequest, ...entry } ) => entry ) ) ); +// These are input for this script, not for the workflow. +console.log( + JSON.stringify( matrix.map( ( { pullRequest, mirrorTrunk, scheduled, ...entry } ) => entry ) ) +); diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 707769c933ec..d1ae0791ed17 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -7,6 +7,9 @@ on: - '**/changelog/**' repository_dispatch: types: [ 'e2e tests**' ] + schedule: + # Daily, for the projects marked `scheduled` in e2e-matrix.js. + - cron: '43 4 * * *' workflow_dispatch: inputs: wp_version: @@ -16,6 +19,7 @@ on: concurrency: # wp_version keeps concurrent dispatches for different WordPress versions from cancelling each other. + # The event name keeps pushes, which arrive as repository_dispatch, from cancelling scheduled runs. group: e2e-tests-${{ github.event_name }}-${{ github.ref }}-${{ case( github.event_name == 'repository_dispatch', github.event.action, '' ) }}-${{ inputs.wp_version }} cancel-in-progress: true @@ -35,7 +39,9 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 # 2025-11-20: The pnpm install may take a few minutes on cache miss. # Only run tests in the main repository - if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name + if: > + github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && + ( github.event_name != 'schedule' || github.repository == 'Automattic/jetpack' ) outputs: matrix: ${{ steps.evaluate.outputs.matrix }} build-matrix: ${{ steps.evaluate.outputs.build-matrix }} @@ -61,6 +67,8 @@ jobs: id: evaluate env: DISPATCH_REPO: ${{ github.event.client_payload.repository }} + DISPATCH_REF_NAME: ${{ github.event.client_payload.ref_name }} + DISPATCH_REF_TYPE: ${{ github.event.client_payload.ref_type }} WP_VERSION: ${{ inputs.wp_version }} run: | MATRIX="$(node .github/files/e2e-tests/e2e-matrix.js)" @@ -165,8 +173,8 @@ jobs: # Used in tests for enhanced reporting of global projects. The WordPress version is part of the # name so the two runs of a project are distinguishable in the report. PROJECT_NAME: '${{ matrix.project }} WP ${{ matrix.wpVersion }}' - # Admin shell suite: Chromium on pull requests, every browser after merge and on manual runs. - ADMIN_SHELL_BROWSERS: ${{ case( github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch', 'chromium,firefox,webkit', 'chromium' ) }} + # Admin shell suite: every browser, unless e2e-matrix.js narrows it. + ADMIN_SHELL_BROWSERS: ${{ matrix.browsers || 'chromium,firefox,webkit' }} strategy: fail-fast: false matrix: @@ -343,9 +351,14 @@ jobs: actions: read # actions/checkout, actions/download-artifact contents: read - # Only mirror-repo dispatches notify. PR feedback is already in the GitHub Checks UI, and a manual - # dispatch has a human watching it who doesn't need the channel told. - if: ${{ always() && needs.e2e-tests.result != 'cancelled' && github.event_name == 'repository_dispatch' }} + # Only mirror-repo dispatches and scheduled runs notify. PR feedback is already in the GitHub Checks UI, + # and a manual dispatch has a human watching it who doesn't need the channel told. + # A timed-out job counts as cancelled. No push replaces a scheduled run, so there that's worth reporting. + if: > + always() && ( + github.event_name == 'repository_dispatch' && needs.e2e-tests.result != 'cancelled' || + github.event_name == 'schedule' && github.repository == 'Automattic/jetpack' + ) needs: [e2e-tests] steps: diff --git a/projects/plugins/jetpack/tests/e2e/README.md b/projects/plugins/jetpack/tests/e2e/README.md index 320e285426c6..561231c7ea33 100644 --- a/projects/plugins/jetpack/tests/e2e/README.md +++ b/projects/plugins/jetpack/tests/e2e/README.md @@ -162,9 +162,17 @@ pnpm test:admin-shell Tests read shell state only through `readShell()` in `helpers/admin-shell-helper.ts`, which uses the `data-shell-page` / `data-shell-state` hooks. A document without the shell (shell off, or `?jetpack_admin_shell=0`) never has those hooks, so `readShell()` reads it from the `jetpack_page_` body class and that page's mount element; keep that path after the rewrite. `switchTo()` fails if a switch reloads the document, so tests that expect a full load click `menuLink()` instead. -In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the `ALONE` specs first, with one worker, then the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. +In CI, the `Jetpack admin shell` entry in `.github/files/e2e-tests/e2e-matrix.js` runs it on PRs that touch the Jetpack plugin or any project it depends on (which covers `admin-ui` and every member), or the suite itself. `pnpm test:admin-shell:ci` (`bin/admin-shell-ci.sh`) runs it against the Docker site from `pnpm env:up`, reading the login from the decrypted config (`pnpm config:decrypt`). It activates the Forms and Podcast modules, then the `e2e-admin-shell` plugin, which keeps the site out of offline mode, stubs a WordPress.com connection (most members need one) and fails WordPress.com requests at once, and then the AI module, which needs that connection. It runs the `ALONE` specs first, with one worker, and makes sure Forms is on again. Then it runs the shell-on projects, then sets the `e2e_admin_shell_off` option and runs the shell-off smoke, so the two runs differ only by the flag. The standalone projects don't run in CI. -Pull requests run it in Chromium, against WordPress latest only. A pull request that changes `admin-ui`, `my-jetpack`, `jitm`, a dashboard package, the e2e environment or this suite (`fullSuiteFor` and `fullSuiteForFiles` in `e2e-matrix.js`) runs the whole suite (a change to only the e2e workflow files doesn't queue the entry at all); any other pull request that reaches the Jetpack plugin, including one that changes only its Settings or AI dashboard, runs only the tests tagged `@smoke` (`ADMIN_SHELL_SMOKE=1`). The post-merge runs against the `jetpack-production` mirror, and manual runs, use all three browsers and the whole suite. +Pull requests run it in Chromium, against WordPress latest only. A pull request that changes `admin-ui`, `my-jetpack`, `jitm`, `wp-build-polyfills`, a dashboard package, the e2e environment or this suite (`fullSuiteFor` and `fullSuiteForFiles` in `e2e-matrix.js`) runs the whole suite (a change to only the e2e workflow files doesn't queue the entry at all); any other pull request that reaches the Jetpack plugin, including one that changes only its Settings or AI dashboard, runs only the tests tagged `@smoke` (`ADMIN_SHELL_SMOKE=1`). + +The full suite opens only the dashboards in `helpers/admin-shell-helper.ts` that the CI site has. Pull request, scheduled and manual runs also build only the packages in this project's `build` script. For a dashboard package that isn't in it, such as `monetize` or `premium-analytics`, these runs don't test its JavaScript. + +Every other run uses the whole suite: + +- Each push to `jetpack-production` trunk runs it in Chromium, against WordPress latest. Its release branches and tags use all three browsers, on WordPress latest and the minimum supported version. +- A daily scheduled run builds monorepo trunk (not the mirror's full production build) and runs only this suite, in all three browsers, on both WordPress versions. New pushes can't cancel it. Failures go to Slack through the same notification job as the mirror runs. +- Manual runs use all three browsers, on one WordPress version. Known bugs are `test.fail()` with a reason, so a fix shows up as an unexpected pass: remove the marker in the same PR. Intermittent bugs can't use `test.fail()`. Wrap those tests in `intermittentSpikeBug()`, which adds the `intermittent spike bug` annotation and the only retries in the config, so they report as flaky and anything else that fails intermittently still fails. diff --git a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh index 5558b7d4e864..e50f50e9b974 100755 --- a/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh +++ b/projects/plugins/jetpack/tests/e2e/bin/admin-shell-ci.sh @@ -45,6 +45,8 @@ if [[ "${ADMIN_SHELL_SMOKE:-}" != 1 ]]; then [[ " ${BROWSERS[*]} " == *" chromium "* ]] && ALONE_PROJECTS+=( --project='hover side effects' ) ADMIN_SHELL_RUN=alone ADMIN_SHELL_ALONE=1 PLAYWRIGHT_WORKERS=1 \ playwright test -c playwright.admin-shell.config.ts "${ALONE_PROJECTS[@]}" "$@" || STATUS=1 + # feature-off switches Forms off. If its cleanup failed, every later Forms test would fail too. + "${WP[@]}" jetpack module activate contact-form || exit 1 fi ADMIN_SHELL_RUN=shell-on playwright test -c playwright.admin-shell.config.ts --project='shell on: *' "$@" || STATUS=1 echo "::endgroup::" diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/history.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/history.test.ts index 584d08f50234..861258b387e1 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/history.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/history.test.ts @@ -31,21 +31,25 @@ test.describe( 'Admin shell: history', () => { await installShellProbe( page ); } ); - test( 'Back and Forward step through members one click at a time', async ( { page } ) => { - await openMember( page, 'my-jetpack' ); - const start = await historyLength( page ); - await switchTo( page, FORMS ); - await switchTo( page, 'my-jetpack' ); - expect( await historyLength( page ), 'one entry per click' ).toBe( start + 2 ); + test( + 'Back and Forward step through members one click at a time', + { tag: '@smoke' }, + async ( { page } ) => { + await openMember( page, 'my-jetpack' ); + const start = await historyLength( page ); + await switchTo( page, FORMS ); + await switchTo( page, 'my-jetpack' ); + expect( await historyLength( page ), 'one entry per click' ).toBe( start + 2 ); - await back( page, FORMS ); - await expectShown( page, FORMS ); - await back( page, 'my-jetpack' ); - expect( await where( page ) ).toMatch( /^\?page=my-jetpack/ ); - await forward( page, FORMS ); - await forward( page, 'my-jetpack' ); - await expectShown( page, 'my-jetpack' ); - } ); + await back( page, FORMS ); + await expectShown( page, FORMS ); + await back( page, 'my-jetpack' ); + expect( await where( page ) ).toMatch( /^\?page=my-jetpack/ ); + await forward( page, FORMS ); + await forward( page, 'my-jetpack' ); + await expectShown( page, 'my-jetpack' ); + } + ); /* `p` routes inside a product: each tab is a history entry, in and out of the shell. */ const tabRoutes = [ diff --git a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts index e0ec15c92242..64b0caf9f846 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts +++ b/projects/plugins/jetpack/tests/e2e/specs/admin-shell/tracks.test.ts @@ -50,7 +50,7 @@ async function waitForViews( const any = ( views: string[] ) => views.length > 0; /** - * View events a full load of `slug` records, skipping the test when there are none. + * View events a full load of `slug` records. When there are none, the test fails in CI and skips elsewhere. * * @param page - Page under test. * @param slug - Member page slug. @@ -59,7 +59,12 @@ const any = ( views: string[] ) => views.length > 0; async function fullLoadViews( page: Page, slug: string ): Promise< string[] > { await openMember( page, slug ); const views = [ ...new Set( await waitForViews( page, 0, any ) ) ]; - test.skip( ! views.length, `${ slug } records no page view on a full load either` ); + // The CI site always records views. Another site may not, for example with Tracks off. + test.skip( + ! views.length && ! process.env.CI, + `${ slug } records no page view on a full load either` + ); + expect( views, `${ slug } records a page view on a full load` ).not.toEqual( [] ); return views; } From c57ef3ca996bdbd1d867edcda247d41ee3ec20c5 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Mon, 30 Nov 2026 11:33:40 -0600 Subject: [PATCH 33/34] Admin shell e2e: Look for saved headers in session storage PR 55202 on trunk moved saved headers from one localStorage key per dashboard to one sessionStorage entry that lists every page. hasSavedHeader() still looked for the old keys, so the header placeholder and stand-in header tests failed in CI, which tests this branch merged with trunk. Look the page up in the new entry instead. Part of JETPACK-3406 --- .../tests/e2e/helpers/admin-shell-a11y-helper.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts index 6558e9681410..9f219caeb1e9 100644 --- a/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts +++ b/projects/plugins/jetpack/tests/e2e/helpers/admin-shell-a11y-helper.ts @@ -136,17 +136,19 @@ export function placeholderSightings( page: Page ): Promise< PlaceholderSighting } /** - * Whether this browser has saved `slug`'s header: the shell shows a stand-in only for a saved one. + * Whether this tab has saved `slug`'s own header. * * @param page - Page under test. * @param slug - Member page slug. - * @return True once the header is in local storage. + * @return True once the header is in session storage. */ export function hasSavedHeader( page: Page, slug: string ): Promise< boolean > { return page.evaluate( s => - Object.keys( localStorage ).some( - key => key.startsWith( 'jetpack-admin-shell-header:' ) && key.endsWith( `:${ s }` ) + Object.keys( sessionStorage ).some( + key => + key.startsWith( 'jetpack-admin-shell-header:' ) && + !! JSON.parse( sessionStorage.getItem( key ) ?? '{}' ).pages?.[ s ] ), slug ); From 47e78d2979f4dc1c692751665c003a24e9d15c15 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Mon, 30 Nov 2026 16:12:19 -0600 Subject: [PATCH 34/34] Admin shell e2e: Turn the shell off when e2e_admin_shell_off is set The flag is now on by default, so the option has to filter it to false. Leaving out the filter that turned it on no longer turns the shell off. --- .../plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php index deeb4c8a7127..ca6b385a2683 100644 --- a/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php +++ b/projects/plugins/jetpack/tests/e2e/plugins/e2e-admin-shell.php @@ -12,9 +12,7 @@ */ // The shell-off run sets this option, so the two runs differ only by the flag. -if ( ! get_option( 'e2e_admin_shell_off' ) ) { - add_filter( 'jetpack_feature_flag_enabled_jetpack-admin-shell', '__return_true' ); -} +add_filter( 'jetpack_feature_flag_enabled_jetpack-admin-shell', get_option( 'e2e_admin_shell_off' ) ? '__return_false' : '__return_true' ); // Most members need a connection: keep Jetpack out of localhost's offline mode and stub one on activation. add_filter( 'jetpack_offline_mode', '__return_false', 99 );