Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ jobs:
run: php packages/playground/website/src/lib/reprint/bridge-test.php

test-e2e-reprint-import:
name: 'Reprint import (wordpress-frame)'
if: github.repository == 'WordPress/wordpress-playground' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 40
Expand All @@ -376,10 +377,14 @@ 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
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
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 &
Expand All @@ -393,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.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
name: playwright-report-reprint-import-wordpress-frame
path: packages/playground/website/playwright-report/
if-no-files-found: ignore
retention-days: 7
Expand All @@ -409,10 +414,11 @@ 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
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:
Expand All @@ -422,17 +428,8 @@ 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]
# 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
Expand All @@ -452,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: |
Expand All @@ -470,24 +465,24 @@ 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
# every run is the repository's largest source of artifact storage.
- 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
Expand Down
9 changes: 5 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.

Expand Down
61 changes: 51 additions & 10 deletions packages/playground/website/bin/wordpress-frame/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.

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,
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`.
20 changes: 19 additions & 1 deletion packages/playground/website/playwright/e2e/deployment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`);
}
});
}

Expand Down Expand Up @@ -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}`);
}
});
36 changes: 34 additions & 2 deletions packages/playground/website/playwright/version-switching-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@ 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 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,
Expand All @@ -22,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(
Expand All @@ -34,6 +58,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/')) {
Expand All @@ -42,8 +74,8 @@ export async function startVersionSwitchingServer({
version === 'old'
? oldVersionDirectory
: version === 'mid'
? midVersionDirectory
: newVersionDirectory
? midVersionDirectory
: newVersionDirectory
);
res.send('Version switched');
next();
Expand Down
Loading
Loading