-
Notifications
You must be signed in to change notification settings - Fork 872
Add full-stack E2E test infrastructure for Boost Cloud pipeline #47961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
LiamSarsfield
wants to merge
11
commits into
trunk
Choose a base branch
from
add/boost-full-stack-e2e-infrastructure
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8baf4f0
Add full-stack E2E test infrastructure for Boost Cloud pipeline
LiamSarsfield 87e4c3b
Address review findings for full-stack E2E infrastructure
LiamSarsfield 67c903d
Fix review round 2 findings for full-stack E2E infrastructure
LiamSarsfield 8d09d5c
Address review round 3 suggestions
LiamSarsfield 038670c
Address review round 4 findings
LiamSarsfield c209798
Address review round 5 findings
LiamSarsfield b307788
Address Copilot review findings
LiamSarsfield 3aafdca
Add timeout to Shield health check fetch in global setup
LiamSarsfield a989494
Add JSDoc warning about string form whitespace splitting in executeDe…
LiamSarsfield 49e2584
Update phan baseline for Boost CLI changes
LiamSarsfield 68012e6
Improve Gate 5 NaN diagnostic and document serial execution requirement
LiamSarsfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/plugins/boost/changelog/add-boost-full-stack-e2e-infrastructure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: fixed | ||
|
|
||
| Fix WP-CLI module activation not triggering side-effect hooks (e.g., Cloud CSS regeneration). Add full-stack E2E test infrastructure for the Boost Cloud pipeline. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,5 @@ plan-data.txt | |
| e2e_tunnels.txt | ||
| jetpack-private-options.txt | ||
| /allure-results | ||
| /.state | ||
| storage.json | ||
50 changes: 50 additions & 0 deletions
50
projects/plugins/boost/tests/e2e/lib/fixtures/full-stack-test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * Playwright fixture for full-stack Boost E2E tests. | ||
| * | ||
| * Extends base-test from e2e-commons. The inherited beforeEach/afterEach hooks | ||
| * (WPCOM request counting) target the e2e container — harmless overhead when | ||
| * that container is running, which it typically is during local dev. | ||
| * | ||
| * Provides: | ||
| * - fullStackUtils (worker-scoped): Docker, Redis, WP-CLI operations against dev container | ||
| * - jetpackBoostPage (test-scoped): Boost admin page object | ||
| */ | ||
|
|
||
| import { test as baseTest, expect } from '_jetpack-e2e-commons/fixtures/base-test'; | ||
| import JetpackBoostPage from '../pages/jetpack-boost-page'; | ||
| import { FullStackUtils } from '../utils/full-stack-utils'; | ||
|
|
||
| const test = baseTest.extend< | ||
| { jetpackBoostPage: JetpackBoostPage }, | ||
| { fullStackUtils: FullStackUtils } | ||
| >( { | ||
| jetpackBoostPage: async ( { page }, use ) => { | ||
| await use( new JetpackBoostPage( page ) ); | ||
| }, | ||
| // Worker-scoped: one instance shared across all tests in a worker. | ||
| // Full-stack specs must use test.describe.serial because the shared Docker | ||
| // environment (dev WordPress, Redis, boost-cloud) cannot handle concurrent tests. | ||
| fullStackUtils: [ | ||
| async ( {}, use ) => { | ||
| await use( new FullStackUtils() ); | ||
| }, | ||
| { scope: 'worker' }, | ||
LiamSarsfield marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ], | ||
| } ); | ||
|
|
||
| // Capture Docker logs on test failure for post-mortem debugging in the Playwright HTML report. | ||
| test.afterEach( async ( { fullStackUtils }, testInfo ) => { | ||
| if ( testInfo.status !== testInfo.expectedStatus ) { | ||
| try { | ||
| const logs = await fullStackUtils.captureDockerLogs(); | ||
| await testInfo.attach( 'docker-logs', { | ||
| body: logs, | ||
| contentType: 'text/plain', | ||
| } ); | ||
| } catch { | ||
| // Don't mask the real test failure | ||
| } | ||
| } | ||
| } ); | ||
|
|
||
| export { test, expect }; | ||
193 changes: 193 additions & 0 deletions
193
projects/plugins/boost/tests/e2e/lib/full-stack-global-setup.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| /** | ||
| * Full-stack E2E test setup project. | ||
| * | ||
| * Performs health-check gates to verify the full-stack environment is ready, | ||
| * then authenticates against the dev WordPress and saves storage state. | ||
| * | ||
| * This file is referenced as a Playwright setup project in playwright.config.ts | ||
| * and runs before any full-stack test specs. | ||
| */ | ||
|
|
||
| import { mkdirSync, existsSync } from 'fs'; | ||
| import { dirname, join } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| import { test as setup, expect } from '@playwright/test'; | ||
| import { | ||
| getDevDomain, | ||
| executeDevWpCommand, | ||
| execDocker, | ||
| flushRedis, | ||
| } from './utils/full-stack-utils'; | ||
|
|
||
| // Keep in sync with storageState path in playwright.config.ts fullStackProjects. | ||
| const STORAGE_STATE_PATH = join( | ||
| dirname( fileURLToPath( import.meta.url ) ), | ||
| '..', | ||
| '.state', | ||
| 'full-stack-storage-state.json' | ||
| ); | ||
LiamSarsfield marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| setup( 'full-stack environment health check', async ( { request } ) => { | ||
| const boostCloudDir = process.env.BOOST_CLOUD_DIR; | ||
| // eslint-disable-next-line playwright/no-conditional-in-test | ||
| if ( ! boostCloudDir ) { | ||
| throw new Error( | ||
| 'BOOST_CLOUD_DIR environment variable is required. ' + | ||
| 'Set it to the path of your boost-cloud repository.' | ||
| ); | ||
| } | ||
| const devDomain = getDevDomain(); | ||
|
|
||
| // Gate 1: BOOST_CLOUD_DIR is valid | ||
| await setup.step( 'BOOST_CLOUD_DIR has docker-compose.yml', () => { | ||
| expect( | ||
| existsSync( join( boostCloudDir, 'docker-compose.yml' ) ), | ||
| `docker-compose.yml not found at ${ boostCloudDir }` | ||
| ).toBe( true ); | ||
| } ); | ||
|
|
||
| // Gate 2: WordPress is alive | ||
| await setup.step( 'WordPress is reachable', async () => { | ||
| const response = await request.get( `http://${ devDomain }/`, { | ||
| maxRedirects: 0, | ||
| failOnStatusCode: false, | ||
| } ); | ||
| expect( | ||
| [ 200, 301, 302 ], | ||
| `WordPress at http://${ devDomain }/ returned ${ response.status() }` | ||
| ).toContain( response.status() ); | ||
| } ); | ||
|
|
||
| // Gate 3: Shield API is healthy. | ||
| // Uses localhost:1982 (host-side port mapping) — not boost-shield:1982 (Docker-internal). | ||
| // BOOST_DEV_DEFAULTS.shield_url uses the Docker hostname for container-to-container routing. | ||
| await setup.step( 'Shield API is healthy', async () => { | ||
| let healthy = false; | ||
| for ( let attempt = 0; attempt < 6; attempt++ ) { | ||
| try { | ||
| const response = await fetch( 'http://localhost:1982/v2/health', { | ||
| signal: AbortSignal.timeout( 5_000 ), | ||
| } ); | ||
| const body = ( await response.json() ) as { status: string }; | ||
| // eslint-disable-next-line playwright/no-conditional-in-test | ||
| if ( body.status === 'ok' ) { | ||
| healthy = true; | ||
| break; | ||
| } | ||
| } catch { | ||
| // Shield may be starting up | ||
| } | ||
| await new Promise( resolve => setTimeout( resolve, 5_000 ) ); | ||
| } | ||
| expect( healthy, 'Shield health check at localhost:1982/v2/health did not return ok' ).toBe( | ||
| true | ||
| ); | ||
LiamSarsfield marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } ); | ||
|
|
||
| // Gate 4: Redis is reachable | ||
| await setup.step( 'Redis is reachable', async () => { | ||
| const output = await execDocker( [ | ||
| 'compose', | ||
| '-f', | ||
| `${ boostCloudDir }/docker-compose.yml`, | ||
| 'exec', | ||
| '-T', | ||
| 'redis', | ||
| 'redis-cli', | ||
| 'ping', | ||
| ] ); | ||
| expect( output, 'Redis did not respond with PONG' ).toContain( 'PONG' ); | ||
| } ); | ||
|
|
||
| // Gate 5: Hydra can reach WordPress | ||
| await setup.step( 'Hydra can reach WordPress', async () => { | ||
| const output = await execDocker( [ | ||
| 'compose', | ||
| '-f', | ||
| `${ boostCloudDir }/docker-compose.yml`, | ||
| 'exec', | ||
| '-T', | ||
| 'boost-hydra-css', | ||
| 'curl', | ||
| '-s', | ||
| '-o', | ||
| '/dev/null', | ||
| '-w', | ||
| '%{http_code}', | ||
| `http://${ devDomain }/`, | ||
| ] ); | ||
| // Extract 3-digit HTTP status code — execDocker concatenates stdout+stderr, | ||
| // so Docker Compose warnings may surround curl's status code output. | ||
| const match = output.match( /\b[1-5]\d{2}\b/ ); | ||
| expect( | ||
| match, | ||
| `No HTTP status code found in Docker output: ${ output.slice( 0, 200 ) }` | ||
| ).not.toBeNull(); | ||
| const httpCode = parseInt( match![ 0 ], 10 ); | ||
| expect( | ||
| [ 200, 301, 302 ], | ||
| `Hydra got HTTP ${ httpCode } reaching http://${ devDomain }/` | ||
| ).toContain( httpCode ); | ||
| } ); | ||
|
|
||
| // Gate 6: boost-developer plugin is active | ||
| await setup.step( 'boost-developer plugin is active', async () => { | ||
| const output = await executeDevWpCommand( 'plugin list --status=active --format=json' ); | ||
| const plugins = JSON.parse( output.trim() ) as Array< { name: string } >; | ||
| const names = plugins.map( p => p.name ); | ||
| expect( names, 'boost-developer plugin is not active' ).toContain( 'boost-developer' ); | ||
| } ); | ||
|
|
||
| // Gate 7: No debug-critical-css-providers.php mu-plugin | ||
| await setup.step( 'debug-critical-css-providers mu-plugin is not present', async () => { | ||
| const output = await executeDevWpCommand( [ | ||
| 'eval', | ||
| "echo file_exists(WPMU_PLUGIN_DIR . '/debug-critical-css-providers.php') ? 'EXISTS' : 'NOT_FOUND';", | ||
| ] ); | ||
| expect( | ||
| output.trim(), | ||
| 'debug-critical-css-providers.php is present in mu-plugins. ' + | ||
| 'This file hardcodes external CSS provider URLs (wincityvoices.org), ' + | ||
| 'causing Hydra to generate CSS for the wrong site. ' + | ||
| 'Remove it: rm tools/docker/mu-plugins/debug-critical-css-providers.php' | ||
| ).toContain( 'NOT_FOUND' ); | ||
| } ); | ||
|
|
||
| // Gate 8: Flush Redis to clear stale BullMQ jobs from interrupted prior runs | ||
| await setup.step( 'Flush Redis', async () => { | ||
| await flushRedis( boostCloudDir ); | ||
| } ); | ||
|
|
||
| // Gate 9: Authenticate against dev WordPress and save storage state | ||
| await setup.step( 'Authenticate against dev WordPress', async () => { | ||
| const loginResponse = await request.post( `http://${ devDomain }/wp-login.php`, { | ||
| form: { | ||
| log: 'jp_docker_acct', | ||
| pwd: 'jp_docker_pass', | ||
| rememberme: 'forever', | ||
| 'wp-submit': 'Log In', | ||
| redirect_to: `http://${ devDomain }/wp-admin/`, | ||
| }, | ||
| } ); | ||
| expect( | ||
| loginResponse.ok() || loginResponse.status() === 302, | ||
| `Login failed with status ${ loginResponse.status() }` | ||
| ).toBe( true ); | ||
|
|
||
LiamSarsfield marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Verify authentication by requesting an admin page — a 200 with the login | ||
| // form would be a false positive from the POST above. | ||
| const adminResponse = await request.get( `http://${ devDomain }/wp-admin/profile.php` ); | ||
| expect( | ||
| adminResponse.url(), | ||
| 'Authentication failed: admin request was redirected to the login page' | ||
| ).not.toContain( 'wp-login.php' ); | ||
|
|
||
| // Save storage state for the full-stack test project | ||
| const stateDir = dirname( STORAGE_STATE_PATH ); | ||
| // eslint-disable-next-line playwright/no-conditional-in-test | ||
| if ( ! existsSync( stateDir ) ) { | ||
| mkdirSync( stateDir, { recursive: true } ); | ||
| } | ||
| await request.storageState( { path: STORAGE_STATE_PATH } ); | ||
| } ); | ||
| } ); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.