From 5e8a85c5c8e30a8ef4514b78b0fdfbd84a787f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 21 Oct 2026 13:45:17 +0200 Subject: [PATCH 1/5] [Website] Run every website E2E test in both origin setups --- .github/workflows/ci.yml | 23 +- AGENTS.md | 9 +- .../website/bin/wordpress-frame/README.md | 61 ++- .../website/playwright/e2e/deployment.spec.ts | 20 +- .../playwright/version-switching-server.ts | 14 +- .../wordpress-frame/wordpress-frame.spec.ts | 449 ++++++++++++++++++ 6 files changed, 549 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb25e27c361..5267db580c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -360,6 +360,11 @@ jobs: run: php packages/playground/website/src/lib/reprint/bridge-test.php test-e2e-reprint-import: + name: 'Reprint import (${{ matrix.setup }})' + strategy: + fail-fast: false + matrix: + setup: [same-origin, wordpress-frame] if: github.repository == 'WordPress/wordpress-playground' || github.event_name == 'pull_request' runs-on: ubuntu-latest timeout-minutes: 40 @@ -376,10 +381,16 @@ jobs: php-version: '8.3' extensions: sqlite3, pdo_sqlite, gd, mbstring, curl, zip, xml tools: none + - name: Resolve the local prototype hosts in every browser + if: matrix.setup == 'wordpress-frame' + run: echo '127.0.0.1 playground.localhost wp.playground.localhost' | sudo tee -a /etc/hosts - name: Install Playwright Browser run: sudo npx playwright install chromium --with-deps - name: Build app for E2E tests run: CORS_PROXY_URL=http://127.0.0.1:5263/cors-proxy.php? npx nx e2e:playwright:prepare-app-deploy-and-offline-mode playground-website + - name: Build the WordPress-only origin setup + if: matrix.setup == 'wordpress-frame' + run: CORS_PROXY_URL=http://127.0.0.1:5263/cors-proxy.php? npx nx run playground-website:build:wordpress-frame - name: Serve a WordPress site with Reprint Server run: | bash packages/playground/website/playwright/reprint-site/serve.sh > /tmp/reprint-site.log 2>&1 & @@ -393,14 +404,14 @@ jobs: cat /tmp/reprint-site.log exit 1 - name: Run Playwright reprint-import tests - run: sudo CI=true PLAYWRIGHT_TEST_GROUP=reprint-import REPRINT_E2E_SITE_URL=http://127.0.0.1:8181/ npx playwright test --config=packages/playground/website/playwright/playwright.ci.config.ts --project=chromium + run: sudo CI=true PLAYWRIGHT_TEST_GROUP=reprint-import REPRINT_E2E_SITE_URL=http://127.0.0.1:8181/ npx playwright test --config=packages/playground/website/playwright/playwright.${{ matrix.setup == 'wordpress-frame' && 'wordpress-frame' || 'ci' }}.config.ts --project=chromium - name: Source site log if: ${{ failure() }} run: cat /tmp/reprint-site.log - uses: actions/upload-artifact@v4 if: ${{ failure() }} with: - name: playwright-report-reprint-import + name: playwright-report-reprint-import-${{ matrix.setup }} path: packages/playground/website/playwright-report/ if-no-files-found: ignore retention-days: 7 @@ -425,14 +436,6 @@ jobs: setup: [same-origin, wordpress-frame] browser: [chromium, firefox, webkit] lane: ['1', '2', '3', storage] - # Start with the origin/storage boundary; the next PR adds regular shards. - exclude: - - setup: wordpress-frame - lane: '1' - - setup: wordpress-frame - lane: '2' - - setup: wordpress-frame - lane: '3' steps: - name: Free up runner disk space shell: bash diff --git a/AGENTS.md b/AGENTS.md index 9105d193956..05a0e9c6512 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,10 +77,11 @@ npm run rebuild:wordpress-builds # Rebuild all WordPress versions ``` The WordPress-only origin prototype has `build:wordpress-frame`, -`preview:wordpress-frame`, and `e2e:wordpress-frame` website targets on port 9500. -PHP and directory handles stay on the app origin. CI adds a split-origin storage -lane in each browser; regular website shards still use the normal origin. See -`packages/playground/website/bin/wordpress-frame/README.md` for the boundary. +`preview:wordpress-frame`, and `e2e:wordpress-frame` website targets. It runs on +port 9500, separately from normal development. CI runs all website E2E tests +in both origin setups, with shared storage/import grouping. Deployment tests +use the same boundary on port 7999. See +`packages/playground/website/bin/wordpress-frame/README.md` for its boundaries. External embeds do not need a referrer or new URL parameters. This mode does not block WordPress from embedding fresh app/API documents. diff --git a/packages/playground/website/bin/wordpress-frame/README.md b/packages/playground/website/bin/wordpress-frame/README.md index f5dd9fbcff5..98c40be22c9 100644 --- a/packages/playground/website/bin/wordpress-frame/README.md +++ b/packages/playground/website/bin/wordpress-frame/README.md @@ -111,16 +111,57 @@ npx playwright install chromium npx nx run playground-website:e2e:wordpress-frame --args='wordpress-frame.spec.ts --project=chromium' ``` -The browser checks cover direct parent OPFS and API access, unchanged external -embeds with hidden referrers, cached HTML, and poisoned WordPress helper and -thumbnail cache entries. The OPFS check creates a private file on the app origin, attempts -reads and writes from WordPress, and checks that the private file is unchanged. +The browser checks cover direct parent OPFS access, rejected child PHP API calls, +restricted helper methods, saved-site switching without replacing the SPA, +shared PHP/WordPress downloads, cache-poisoning attempts against the helper and +thumbnail-worker loader, warm offline startup, editor saves, the same-origin +directory-handle path, current-URL reporting, two-way app/WordPress messages, +outside-click dismissal, and cross-origin OAuth popups. The folder test +substitutes an OPFS handle for the OS picker. It does not +verify native permission prompts. For that check, select a disposable directory +outside Documents/iCloud from the normal Save panel, write a file, and reopen the +saved site. The picker should open from the main app, without a guide popup. + +The API boundary check confirms that WordPress cannot use an existing parent +API connection or read the parent or top-level document and storage APIs. +The OPFS check writes a private file from `remote.html`, +attempts reads and same-path writes/deletes from WordPress, and confirms that +both root-origin documents still read the unchanged private file. ## CI -CI runs the existing website suite on its normal origin. Each browser also runs a -split-origin storage lane, including the new boundary checks. Regular split-origin -shards and the workflow checks are added by the next PR in the stack. - -The preview uses port 9500. CI uses port 80 because WordPress multisite rejects -custom ports. +CI runs the entire existing website E2E suite in both setups: same-origin and +WordPress-only origin. Each setup has Chromium, Firefox and WebKit lanes, with +three regular shards and one single-worker storage lane per browser. The real +Reprint import keeps its dedicated Chromium lane in both setups. No test files +are excluded from the WordPress-only setup. CI serves both prototype hosts on +port 80, because WordPress multisite rejects custom ports. The local preview +stays on 9500; multisite needs a default-port server instead. + +Both setups use the same `@storage` and `@reprint-import` routing. The extra +boundary checks run in the storage lane. Failure reports include traces and +screenshots. Existing browser skips remain unchanged. New OPFS and directory-handle +checks use Chromium, matching the regular storage suite; HTTP/API boundary checks, +editor saves, thumbnails and popups still run in all three browsers. + +Deployment and offline tests use `playground.localhost:7999` and +`wp.playground.localhost:7999` when they switch to the new release. The bundled +old releases still exercise the upgrade from the old architecture. This matters: +running those tests on plain localhost would leave the origin split disabled. + +Known areas to check in the full suite: + +- Offline reload needs both origins' bootstrap documents and service workers. + Eager offline prefetch is currently disabled in the prototype. +- APIs that assume the WordPress document and remote.html share an origin, + including editor media, thumbnails, navigation and WebMCP. +- Saved-site imports, reloads and native directory mounts. The automated folder + check uses an OPFS handle; actual OS picker prompts still need a manual check. +- Remote access and account flows. External embeds have browser checks for the + default and hidden referrers, unchanged SDK loading, nested external frames, + and cached HTML. Blocking fresh app/API frames remains unresolved. + +To run the same full suite locally, build the normal CI fixtures first, then the +prototype. Set `PLAYWRIGHT_TEST_GROUP` to `regular`, `storage`, or `reprint-import` +and run this configuration. The import lane also needs its source-site server. +For a single existing test, pass its filename to `e2e:wordpress-frame`. diff --git a/packages/playground/website/playwright/e2e/deployment.spec.ts b/packages/playground/website/playwright/e2e/deployment.spec.ts index 038daca99e2..e33d29ffbdc 100644 --- a/packages/playground/website/playwright/e2e/deployment.spec.ts +++ b/packages/playground/website/playwright/e2e/deployment.spec.ts @@ -8,7 +8,11 @@ import { startVersionSwitchingServer as startServer } from '../version-switching test.describe.configure({ mode: 'serial' }); const port = 7999; -const url = new URL(`http://localhost:${port}`); +const host = + process.env.PLAYWRIGHT_WORDPRESS_FRAME === '1' + ? 'playground.localhost' + : 'localhost'; +const url = new URL(`http://${host}:${port}`); // Disable login because an old WP build used in this test // blocks auto-login. This is because it has an admin user // with an expired email verification window. If we do not @@ -77,6 +81,13 @@ for (const cachingEnabled of [true, false]) { await expect(wordpress.locator('body')).toContainText( 'My WordPress Website' ); + if (process.env.PLAYWRIGHT_WORDPRESS_FRAME === '1') { + expect( + await wordpress + .locator('body') + .evaluate(() => window.location.origin) + ).toBe(`http://wp.playground.localhost:${port}`); + } }); } @@ -173,4 +184,11 @@ test('offline mode – the app should load even when the server goes offline', a await expect(wordpress.locator('body')).toContainText( 'My WordPress Website' ); + if (process.env.PLAYWRIGHT_WORDPRESS_FRAME === '1') { + expect( + await wordpress + .locator('body') + .evaluate(() => window.location.origin) + ).toBe(`http://wp.playground.localhost:${port}`); + } }); diff --git a/packages/playground/website/playwright/version-switching-server.ts b/packages/playground/website/playwright/version-switching-server.ts index 7b2b7d202ef..b6e5decc72e 100644 --- a/packages/playground/website/playwright/version-switching-server.ts +++ b/packages/playground/website/playwright/version-switching-server.ts @@ -3,7 +3,9 @@ import type http from 'http'; import express from 'express'; import path from 'path'; import process from 'process'; +import { wordPressFrameMiddleware } from '../bin/wordpress-frame/middleware.mjs'; +/** Serve replaceable releases, including the WordPress-only origin boundary in its CI lane. */ export async function startVersionSwitchingServer({ port = 7999, oldVersionDirectory, @@ -34,6 +36,14 @@ export async function startVersionSwitchingServer({ next(); }; + if (process.env.PLAYWRIGHT_WORDPRESS_FRAME === '1') { + app.use( + wordPressFrameMiddleware( + `http://playground.localhost:${port}`, + () => path.join(staticDirectory, 'wordpress-bridge.html') + ) + ); + } app.use(noCacheMiddleware); app.use((req, res, next) => { if (req.method === 'GET' && req.path.startsWith('/switch-versions/')) { @@ -42,8 +52,8 @@ export async function startVersionSwitchingServer({ version === 'old' ? oldVersionDirectory : version === 'mid' - ? midVersionDirectory - : newVersionDirectory + ? midVersionDirectory + : newVersionDirectory ); res.send('Version switched'); next(); diff --git a/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts b/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts index 7263d767ece..898adf278ce 100644 --- a/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts +++ b/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts @@ -402,6 +402,435 @@ test.describe('WordPress origin boundary', { tag: '@storage' }, () => { } }); + test('app relay messages reach WordPress and return across the origin boundary', async ({ + page, + }) => { + await page.goto('/?wp=6.9&php=8.3&storage=temp'); + const wp = await ready(page); + await wp.evaluate((appOrigin) => { + window.addEventListener('message', (event) => { + if ( + event.source === window.parent && + event.origin === appOrigin && + event.data?.type === 'relay' && + event.data?.relayType === 'round-trip-probe' + ) { + window.parent.postMessage( + { type: 'relay', relayType: 'round-trip-result' }, + appOrigin + ); + } + }); + }, root); + const relayed = await page + .locator( + '#playground-viewport:visible,.playground-viewport:visible' + ) + .evaluate(async (remote: HTMLIFrameElement) => { + return await new Promise((resolve) => { + const timeout = setTimeout(() => finish(false), 3000); + window.addEventListener('message', onMessage); + remote.contentWindow!.postMessage( + { type: 'relay', relayType: 'round-trip-probe' }, + window.location.origin + ); + + /** Accept the reply through remote.html, not a message from an unrelated window. */ + function onMessage(event: MessageEvent) { + if ( + event.source === remote.contentWindow && + event.origin === window.location.origin && + event.data?.type === 'relay' && + event.data?.relayType === 'round-trip-result' + ) + finish(true); + } + + /** Remove this probe's listener and timer on success or timeout. */ + function finish(result: boolean) { + clearTimeout(timeout); + window.removeEventListener('message', onMessage); + resolve(result); + } + }); + }); + expect(relayed).toBe(true); + }); + + test('the current URL follows WordPress links and history changes', async ({ + page, + }) => { + await page.goto('/?wp=6.9&php=8.3&storage=temp'); + await ready(page); + await page.evaluate(() => + (window as any).playgroundSites.getClient().goTo('/wp-admin/') + ); + const wp = await ready(page); + await wp.locator('#menu-pages > a').click(); + await expect + .poll(() => + page.evaluate(() => + (window as any).playgroundSites.getClient().getCurrentURL() + ) + ) + .toBe('/wp-admin/edit.php?post_type=page'); + await wp.evaluate(() => + window.history.pushState( + null, + '', + '?post_type=page&paged=2#history' + ) + ); + await expect + .poll(() => + page.evaluate(() => + (window as any).playgroundSites.getClient().getCurrentURL() + ) + ) + .toBe('/wp-admin/edit.php?post_type=page&paged=2#history'); + // A document without the MU plugin must not retain the previous page's report. + await page.evaluate(async () => { + const client = (window as any).playgroundSites.getClient(); + await client.writeFile( + '/wordpress/no-url-report.html', + 'Static page' + ); + await client.goTo('/no-url-report.html'); + }); + expect( + await page.evaluate(() => + (window as any).playgroundSites.getClient().getCurrentURL() + ) + ).toBe('/no-url-report.html'); + }); + + test('the HTTP bridge preserves short and large response bodies', async ({ + page, + }) => { + await page.goto('/?wp=6.9&php=8.3&storage=temp'); + const wp = await ready(page); + for (const body of [ + 'short response', + 'chunk '.repeat(32768) + 'end of response', + ]) { + await page.evaluate(async (body) => { + await (window as any).playgroundSites + .getClient() + .writeFile('/wordpress/stream-probe.txt', body); + }, body); + expect( + await wp.evaluate(async () => + (await fetch('./stream-probe.txt')).text() + ) + ).toBe(body); + } + }); + + test('WordPress can fetch and navigate to a static file from the shared asset origin', async ({ + page, + }) => { + await page.goto('/?wp=6.9&php=8.3&storage=temp'); + const wp = await ready(page); + const path = '/wp-includes/js/jquery/jquery.min.js'; + // Let the background ZIP finish so it cannot restore the file after removal. + await expect + .poll(() => + page.evaluate(() => + (window as any).playgroundSites + .getClient() + .readFileAsText( + '/wordpress/wordpress-remote-asset-paths' + ) + ) + ) + .toBe(''); + await page.evaluate( + (path) => + (window as any).playgroundSites + .getClient() + .unlink('/wordpress' + path), + path + ); + // This must exercise the remote backfill, not a copy already in PHP's filesystem. + expect( + await page.evaluate( + (path) => + (window as any).playgroundSites + .getClient() + .fileExists('/wordpress' + path), + path + ) + ).toBe(false); + const target = new URL(await wp.evaluate(() => window.location.href)); + target.pathname += path.substring(1); + expect( + await wp.evaluate(async (url) => { + const response = await fetch(url, { mode: 'same-origin' }); + return response.text(); + }, target.href) + ).toContain('jQuery'); + const response = await wp.goto(target.href); + expect(response?.status()).toBe(200); + expect(await response!.text()).toContain('jQuery'); + expect(await wp.evaluate(() => window.location.origin)).toBe(wpOrigin); + }); + + test('WordPress popups use the running site without app storage access', async ({ + page, + }) => { + await page.goto('/?wp=6.9&php=8.3&storage=temp'); + await ready(page); + const path = await page.evaluate(async () => { + const client = (window as any).playgroundSites.getClient(); + await client.writeFile( + '/wordpress/popup-probe.php', + ' window.open(url, '_blank', 'noopener,noreferrer'), + root + '/wordpress-popup.html#' + path + ); + const popup = await opened; + const content = popup.frameLocator('#wp'); + await expect(content.locator('body')).toHaveText('popup PHP works'); + expect( + await content.locator('body').evaluate(() => { + try { + void window.parent.navigator.storage; + return 'accessible'; + } catch (error) { + return (error as DOMException).name; + } + }) + ).toBe('SecurityError'); + await popup.goto(root + '/wordpress-popup.html#' + root + '/api.html'); + await expect(popup.locator('#wp')).not.toHaveAttribute( + 'src', + /api\.html/ + ); + await popup.close(); + }); + + test('site switching keeps the SPA and reuses the PHP and WordPress downloads', async ({ + page, + browserName, + }) => { + test.skip( + browserName !== 'chromium', + 'Saved-site checks require OPFS, as in the regular storage suite.' + ); + await page.goto('/?wp=6.9&php=8.3&storage=temp'); + await ready(page); + await page.evaluate(() => ((window as any).appDocument = 'kept')); + const alpha = await page.evaluate(async () => { + const api = (window as any).playgroundSites; + await api + .getClient() + .writeFile('/wordpress/alpha.txt', 'alpha files'); + const site = await api.saveInBrowser('Alpha'); + return site; + }); + await ready(page); + await page.evaluate(async () => { + const api = (window as any).playgroundSites; + await api.getClient().flushOpfs('/wordpress'); + await api.rename('Alpha renamed'); + await api.getClient().backfillStaticFilesRemovedFromMinifiedBuild(); + }); + const firstAssets = await ( + await page.request.get('/__wordpress-frame-assets') + ).json(); + await page.evaluate(() => + (window as any).playgroundSites.createNewTemporarySite('Beta', { + phpVersion: '8.3', + wpVersion: '6.9', + }) + ); + await ready(page); + await page.evaluate(() => + (window as any).playgroundSites + .getClient() + .backfillStaticFilesRemovedFromMinifiedBuild() + ); + const laterAssets = ( + await (await page.request.get('/__wordpress-frame-assets')).json() + ).slice(firstAssets.length); + const largeAssetPaths = firstAssets + .filter((asset: { path: string }) => + /\.(wasm|zip|zst)$/.test(asset.path) + ) + .map((asset: { path: string }) => asset.path); + expect( + largeAssetPaths.some((path: string) => path.endsWith('.wasm')) + ).toBe(true); + expect( + largeAssetPaths.some((path: string) => + path.endsWith('/wordpress-static.zip') + ) + ).toBe(true); + expect( + laterAssets + .filter((asset: { path: string }) => + largeAssetPaths.includes(asset.path) + ) + .reduce( + (bytes: number, asset: { bytes: number }) => + bytes + asset.bytes, + 0 + ) + ).toBe(0); + expect( + await page.evaluate(() => + (window as any).playgroundSites + .getClient() + .fileExists('/wordpress/alpha.txt') + ) + ).toBe(false); + await page.evaluate( + (slug) => (window as any).playgroundSites.setActiveSite(slug), + alpha.slug + ); + await ready(page); + expect( + await page.evaluate(() => + (window as any).playgroundSites + .getClient() + .readFileAsText('/wordpress/alpha.txt') + ) + ).toBe('alpha files'); + expect(await page.evaluate(() => (window as any).appDocument)).toBe( + 'kept' + ); + expect(new URL(page.url()).origin).toBe(root); + }); + + test('the block editor can save a post through the cross-origin HTTP transport', async ({ + page, + }) => { + await page.goto('/?wp=6.9&php=8.3&storage=temp'); + await ready(page); + await page.evaluate(() => + (window as any).playgroundSites + .getClient() + .goTo('/wp-admin/post-new.php') + ); + const wp = page + .frameLocator( + '#playground-viewport:visible,.playground-viewport:visible' + ) + .frameLocator('#wp'); + await wp + .getByRole('dialog', { name: 'Welcome to the editor' }) + .getByRole('button', { name: 'Close', exact: true }) + .click(); + await expect( + wp.getByRole('button', { name: 'Publish', exact: true }) + ).toBeVisible(); + const editor = await ready(page); + const result = await editor.evaluate(async () => { + const wp = (window as any).wp; + await wp.data.dispatch('core/editor').editPost({ + title: 'Cross-origin editor', + content: '

Saved through PHP

', + }); + await wp.data.dispatch('core/editor').savePost(); + return wp.data.select('core/editor').getCurrentPostId(); + }); + expect(result).toBeGreaterThan(0); + const title = await page.evaluate(async (id) => { + const response = await (window as any).playgroundSites + .getClient() + .run({ + code: ` { + test.skip( + browserName !== 'chromium', + 'The directory-handle fixture requires Chromium OPFS.' + ); + await page.goto('/?wp=6.9&php=8.3&storage=temp'); + await ready(page); + await page.evaluate(() => { + (window as any).pickerCalls = 0; + // OPFS stands in for the OS picker; this checks the same-origin handle path, + // not native permission prompts. + (window as any).showDirectoryPicker = async () => { + if (window !== window.top) + throw new Error('Picker is not in the top-level app'); + (window as any).pickerCalls++; + return ( + await navigator.storage.getDirectory() + ).getDirectoryHandle('picked-folder', { create: true }); + }; + }); + const saved = await page.evaluate(() => + (window as any).playgroundSites.saveToLocalFileSystem('Folder') + ); + expect(saved.storage).toBe('local-fs'); + const wp = await ready(page); + await page.evaluate(async () => { + const client = (window as any).playgroundSites.getClient(); + await client.writeFile( + '/wordpress/folder-marker.txt', + 'from the PHP mount' + ); + await client.flushOpfs('/wordpress'); + }); + expect( + await page.evaluate(async () => { + const directory = await ( + await navigator.storage.getDirectory() + ).getDirectoryHandle('picked-folder'); + return ( + await ( + await directory.getFileHandle('folder-marker.txt') + ).getFile() + ).text(); + }) + ).toBe('from the PHP mount'); + expect(await page.evaluate(() => (window as any).pickerCalls)).toBe(1); + expect(page.context().pages()).toHaveLength(1); + expect( + await wp.evaluate(async () => { + try { + await ( + await navigator.storage.getDirectory() + ).getDirectoryHandle('picked-folder'); + return 'read'; + } catch (error) { + return (error as DOMException).name; + } + }) + ).toBe('NotFoundError'); + }); + + test('site thumbnails render inside WordPress across the origin boundary', async ({ + page, + }) => { + await page.goto('/?wp=6.9&php=8.3&storage=temp'); + await ready(page); + const thumbnail = await page.evaluate(() => + (window as any).playgroundSites.getClient().captureSiteThumbnail() + ); + expect(['image/webp', 'image/jpeg']).toContain(thumbnail.mime); + expect(Buffer.from(thumbnail.data, 'base64').length).toBeGreaterThan( + 100 + ); + }); + test('WordPress caches cannot replace the thumbnail resource worker', async ({ page, }) => { @@ -466,6 +895,26 @@ test.describe('WordPress origin boundary', { tag: '@storage' }, () => { expect(result).toBe('trusted resource worker'); }); + test('OAuth popups keep their opener after visiting another origin', async ({ + page, + }) => { + await page.goto('/?storage=temp'); + await page.context().route('https://oauth-provider.test/**', (route) => + route.fulfill({ + contentType: 'text/html', + body: ``, + }) + ); + const opened = page.context().waitForEvent('page'); + await page.evaluate(() => { + window.open('https://oauth-provider.test/authorize'); + }); + const popup = await opened; + await popup.waitForURL(root + '/?oauth-callback-probe=1&storage=temp'); + expect(await popup.evaluate(() => window.opener !== null)).toBe(true); + await popup.close(); + }); + /** * Model a WordPress plugin replacing cached helper HTML with its own script. * From 3d46e109f5c2b11270a1e8f65ea97f8fea714cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 21 Oct 2026 17:29:42 +0200 Subject: [PATCH 2/5] [Website] Allow serialized storage E2E jobs to finish after builds --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5267db580c0..e8614ad5ae9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -423,7 +423,8 @@ jobs: name: 'Website E2E (${{ matrix.setup }}, ${{ matrix.browser }}, ${{ matrix.lane }})' if: github.repository == 'WordPress/wordpress-playground' || github.event_name == 'pull_request' runs-on: ubuntu-latest - timeout-minutes: 30 + # Storage tests run one at a time; allow build time plus the full storage suite. + timeout-minutes: ${{ matrix.lane == 'storage' && 45 || 30 }} permissions: contents: read # Required to clone the repo. strategy: From e71fa628d233e9c83d3dcefa00fb65ccafdd403b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 22 Oct 2026 12:05:56 +0200 Subject: [PATCH 3/5] [Website] Explain release switching and cross-origin test coverage --- .../playwright/version-switching-server.ts | 24 ++++++++++++++++++- .../wordpress-frame/wordpress-frame.spec.ts | 9 +++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/playground/website/playwright/version-switching-server.ts b/packages/playground/website/playwright/version-switching-server.ts index b6e5decc72e..ac93ea734a7 100644 --- a/packages/playground/website/playwright/version-switching-server.ts +++ b/packages/playground/website/playwright/version-switching-server.ts @@ -5,7 +5,25 @@ import path from 'path'; import process from 'process'; import { wordPressFrameMiddleware } from '../bin/wordpress-frame/middleware.mjs'; -/** Serve replaceable releases, including the WordPress-only origin boundary in its CI lane. */ +/** + * Serve old, intermediate, and new builds at one address to test deployment upgrades. + * + * Start with oldVersionDirectory. The returned controls, or /switch-versions/ URLs, + * change which directory serves subsequent requests without restarting the server + * or reloading an open page. Tests can therefore leave an old app running while + * its service worker and later asset requests encounter a newly deployed build. + * Serving only the newest build from the start would miss those upgrade failures. + * + * In the split-origin lane, install the same host routing as the normal preview + * before serving static files. Its helper-path callback reads staticDirectory on + * every request: after a release switch, both the app and wordpress-bridge.html + * must come from the selected build. Do not keep serving the old helper with new + * app modules or let this test server expose WordPress HTML on the app host. + * + * The cache control only changes HTTP response headers; it does not clear browser + * HTTP caches or service-worker CacheStorage. Tests manage those separately. + * Call kill() during test cleanup to close the listener and remove signal hooks. + */ export async function startVersionSwitchingServer({ port = 7999, oldVersionDirectory, @@ -24,6 +42,10 @@ export async function startVersionSwitchingServer({ let staticDirectory = oldVersionDirectory; let httpCacheEnabled = true; + /** + * Let upgrade tests opt out of storing these responses in the HTTP cache. + * This affects later responses only, not entries already stored by a browser. + */ const noCacheMiddleware = (req, res, next) => { if (!httpCacheEnabled) { res.setHeader( diff --git a/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts b/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts index 898adf278ce..1d9bae693fe 100644 --- a/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts +++ b/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts @@ -1,3 +1,12 @@ +/** + * Exercise the two-host setup through real WordPress pages, not isolated mocks. + * + * A working origin split must still boot WordPress, save posts, mount app-origin + * directory handles, and reuse shared downloads while the SPA stays loaded. These + * tests also try direct parent/API access and replace WordPress-side cache entries. + * A failed or empty WordPress document is not a successful security check; ready() + * requires the real site's scoped URL and body before those assertions run. + */ import { test, expect } from '@playwright/test'; import type { Frame, Page } from '@playwright/test'; import { createServer } from 'node:http'; From 727a8d831889381cc997efb70e873d768e6ba07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 22 Oct 2026 12:53:10 +0200 Subject: [PATCH 4/5] [Website] Run the website browser suite only with cross-origin WordPress --- .github/workflows/ci.yml | 25 ++++++------------- AGENTS.md | 6 ++--- .../website/bin/wordpress-frame/README.md | 12 ++++----- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8614ad5ae9..1024d233a71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -360,11 +360,7 @@ jobs: run: php packages/playground/website/src/lib/reprint/bridge-test.php test-e2e-reprint-import: - name: 'Reprint import (${{ matrix.setup }})' - strategy: - fail-fast: false - matrix: - setup: [same-origin, wordpress-frame] + name: 'Reprint import (wordpress-frame)' if: github.repository == 'WordPress/wordpress-playground' || github.event_name == 'pull_request' runs-on: ubuntu-latest timeout-minutes: 40 @@ -382,14 +378,12 @@ jobs: extensions: sqlite3, pdo_sqlite, gd, mbstring, curl, zip, xml tools: none - name: Resolve the local prototype hosts in every browser - if: matrix.setup == 'wordpress-frame' run: echo '127.0.0.1 playground.localhost wp.playground.localhost' | sudo tee -a /etc/hosts - name: Install Playwright Browser run: sudo npx playwright install chromium --with-deps - name: Build app for E2E tests run: CORS_PROXY_URL=http://127.0.0.1:5263/cors-proxy.php? npx nx e2e:playwright:prepare-app-deploy-and-offline-mode playground-website - name: Build the WordPress-only origin setup - if: matrix.setup == 'wordpress-frame' run: CORS_PROXY_URL=http://127.0.0.1:5263/cors-proxy.php? npx nx run playground-website:build:wordpress-frame - name: Serve a WordPress site with Reprint Server run: | @@ -404,14 +398,14 @@ jobs: cat /tmp/reprint-site.log exit 1 - name: Run Playwright reprint-import tests - run: sudo CI=true PLAYWRIGHT_TEST_GROUP=reprint-import REPRINT_E2E_SITE_URL=http://127.0.0.1:8181/ npx playwright test --config=packages/playground/website/playwright/playwright.${{ matrix.setup == 'wordpress-frame' && 'wordpress-frame' || 'ci' }}.config.ts --project=chromium + run: sudo CI=true PLAYWRIGHT_TEST_GROUP=reprint-import REPRINT_E2E_SITE_URL=http://127.0.0.1:8181/ npx playwright test --config=packages/playground/website/playwright/playwright.wordpress-frame.config.ts --project=chromium - name: Source site log if: ${{ failure() }} run: cat /tmp/reprint-site.log - uses: actions/upload-artifact@v4 if: ${{ failure() }} with: - name: playwright-report-reprint-import-${{ matrix.setup }} + name: playwright-report-reprint-import-wordpress-frame path: packages/playground/website/playwright-report/ if-no-files-found: ignore retention-days: 7 @@ -420,7 +414,7 @@ jobs: # Previously used a prepare job + artifact sharing, but inline builds allow # all shards to start immediately in parallel, reducing total wall time. test-e2e-playwright: - name: 'Website E2E (${{ matrix.setup }}, ${{ matrix.browser }}, ${{ matrix.lane }})' + name: 'Website E2E (wordpress-frame, ${{ matrix.browser }}, ${{ matrix.lane }})' if: github.repository == 'WordPress/wordpress-playground' || github.event_name == 'pull_request' runs-on: ubuntu-latest # Storage tests run one at a time; allow build time plus the full storage suite. @@ -434,7 +428,6 @@ jobs: # have their own unsharded lane because OPFS is browser-scoped. # That lane uses one worker, so Playwright can retry only the # failed test without allowing storage tests to overlap. - setup: [same-origin, wordpress-frame] browser: [chromium, firefox, webkit] lane: ['1', '2', '3', storage] steps: @@ -456,14 +449,12 @@ jobs: submodules: true - uses: ./.github/actions/prepare-playground - name: Resolve the local prototype hosts in every browser - if: matrix.setup == 'wordpress-frame' run: echo '127.0.0.1 playground.localhost wp.playground.localhost' | sudo tee -a /etc/hosts - name: Install Playwright Browser run: sudo npx playwright install ${{ matrix.browser }} --with-deps - name: Build app for E2E tests run: CORS_PROXY_URL=http://127.0.0.1:5263/cors-proxy.php? npx nx e2e:playwright:prepare-app-deploy-and-offline-mode playground-website - name: Build the WordPress-only origin setup - if: matrix.setup == 'wordpress-frame' run: CORS_PROXY_URL=http://127.0.0.1:5263/cors-proxy.php? npx nx run playground-website:build:wordpress-frame - name: Run every website E2E test in its assigned lane run: | @@ -474,9 +465,9 @@ jobs: SHARD_ARG="--shard=${{ matrix.lane }}/3" fi if [ "${{ matrix.browser }}" = "firefox" ]; then - sudo -E HOME=/root XDG_RUNTIME_DIR=/root CI=true PLAYWRIGHT_TEST_GROUP=$TEST_GROUP npx playwright test --config=packages/playground/website/playwright/playwright.${{ matrix.setup == 'wordpress-frame' && 'wordpress-frame' || 'ci' }}.config.ts --project=${{ matrix.browser }} $SHARD_ARG + sudo -E HOME=/root XDG_RUNTIME_DIR=/root CI=true PLAYWRIGHT_TEST_GROUP=$TEST_GROUP npx playwright test --config=packages/playground/website/playwright/playwright.wordpress-frame.config.ts --project=${{ matrix.browser }} $SHARD_ARG else - sudo CI=true PLAYWRIGHT_TEST_GROUP=$TEST_GROUP npx playwright test --config=packages/playground/website/playwright/playwright.${{ matrix.setup == 'wordpress-frame' && 'wordpress-frame' || 'ci' }}.config.ts --project=${{ matrix.browser }} $SHARD_ARG + sudo CI=true PLAYWRIGHT_TEST_GROUP=$TEST_GROUP npx playwright test --config=packages/playground/website/playwright/playwright.wordpress-frame.config.ts --project=${{ matrix.browser }} $SHARD_ARG fi # Only upload reports and snapshots for failed runs — they exist # to debug failures and update snapshots, and uploading them on @@ -484,14 +475,14 @@ jobs: - uses: actions/upload-artifact@v4 if: ${{ failure() }} with: - name: playwright-report-${{ matrix.setup }}-${{ matrix.browser }}-${{ matrix.lane }} + name: playwright-report-wordpress-frame-${{ matrix.browser }}-${{ matrix.lane }} path: packages/playground/website/playwright-report/ if-no-files-found: ignore retention-days: 7 - uses: actions/upload-artifact@v4 if: ${{ failure() }} with: - name: playwright-snapshots-${{ matrix.setup }}-${{ matrix.browser }}-${{ matrix.lane }} + name: playwright-snapshots-wordpress-frame-${{ matrix.browser }}-${{ matrix.lane }} path: packages/playground/website/playwright/e2e/deployment.spec.ts-snapshots/ if-no-files-found: ignore retention-days: 7 diff --git a/AGENTS.md b/AGENTS.md index 05a0e9c6512..7ff6fe4db77 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -78,9 +78,9 @@ npm run rebuild:wordpress-builds # Rebuild all WordPress versions The WordPress-only origin prototype has `build:wordpress-frame`, `preview:wordpress-frame`, and `e2e:wordpress-frame` website targets. It runs on -port 9500, separately from normal development. CI runs all website E2E tests -in both origin setups, with shared storage/import grouping. Deployment tests -use the same boundary on port 7999. See +port 9500, separately from normal development. CI runs all website E2E tests once +against the separate WordPress origin, with shared storage/import grouping. +Deployment tests use the same boundary on port 7999. See `packages/playground/website/bin/wordpress-frame/README.md` for its boundaries. External embeds do not need a referrer or new URL parameters. This mode does not block WordPress from embedding fresh app/API documents. diff --git a/packages/playground/website/bin/wordpress-frame/README.md b/packages/playground/website/bin/wordpress-frame/README.md index 98c40be22c9..5d81fc0fc26 100644 --- a/packages/playground/website/bin/wordpress-frame/README.md +++ b/packages/playground/website/bin/wordpress-frame/README.md @@ -130,15 +130,15 @@ both root-origin documents still read the unchanged private file. ## CI -CI runs the entire existing website E2E suite in both setups: same-origin and -WordPress-only origin. Each setup has Chromium, Firefox and WebKit lanes, with -three regular shards and one single-worker storage lane per browser. The real -Reprint import keeps its dedicated Chromium lane in both setups. No test files -are excluded from the WordPress-only setup. CI serves both prototype hosts on +CI runs the entire existing website E2E suite once, against the WordPress-only +origin setup. Chromium, Firefox and WebKit each use three regular shards and one +single-worker storage lane: 12 browser jobs, not a second matrix for the old +same-origin setup. The real source-site Reprint import runs once in its dedicated +Chromium lane. No website test files are excluded. CI serves both prototype hosts on port 80, because WordPress multisite rejects custom ports. The local preview stays on 9500; multisite needs a default-port server instead. -Both setups use the same `@storage` and `@reprint-import` routing. The extra +The suite uses the shared `@storage` and `@reprint-import` routing. The extra boundary checks run in the storage lane. Failure reports include traces and screenshots. Existing browser skips remain unchanged. New OPFS and directory-handle checks use Chromium, matching the regular storage suite; HTTP/API boundary checks, From 099748096ab2a32c9bb4ce7a221ee3031d06a100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 22 Oct 2026 16:01:31 +0200 Subject: [PATCH 5/5] [Website] Load rejected popup URLs in a fresh document --- .../wordpress-frame/wordpress-frame.spec.ts | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts b/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts index 1d9bae693fe..ffaf8f8bf9f 100644 --- a/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts +++ b/packages/playground/website/playwright/wordpress-frame/wordpress-frame.spec.ts @@ -617,12 +617,24 @@ test.describe('WordPress origin boundary', { tag: '@storage' }, () => { } }) ).toBe('SecurityError'); - await popup.goto(root + '/wordpress-popup.html#' + root + '/api.html'); - await expect(popup.locator('#wp')).not.toHaveAttribute( - 'src', - /api\.html/ - ); await popup.close(); + // Changing only the first popup's hash would not rerun its URL check. + // Start a fresh document at about:blank so the error listener is ready + // before navigation executes the popup module with the rejected URL. + const rejectedOpen = page.waitForEvent('popup'); + await page.evaluate(() => + window.open('about:blank', '_blank', 'noopener,noreferrer') + ); + const rejected = await rejectedOpen; + const rejection = rejected.waitForEvent('pageerror'); + await rejected.goto( + root + '/wordpress-popup.html#' + root + '/api.html' + ); + expect((await rejection).message).toContain( + 'The popup URL must name a scoped WordPress page.' + ); + await expect(rejected.locator('#wp')).not.toHaveAttribute('src'); + await rejected.close(); }); test('site switching keeps the SPA and reuses the PHP and WordPress downloads', async ({