Skip to content

E2E Test for api.html site export - #4231

Merged
ashfame merged 20 commits into
trunkfrom
agent/api-html-e2e-test
Aug 4, 2026
Merged

E2E Test for api.html site export#4231
ashfame merged 20 commits into
trunkfrom
agent/api-html-e2e-test

Conversation

@ashfame

@ashfame ashfame commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

  • Add a Chromium E2E test that loads the public client, starts a sandboxed /api.html, exports a saved OPFS site, and verifies the returned ZIP contains unique site content.
  • Make the development client/index.js shim respect Vite's configured base path.

Why

This is stacked on #4220 and verifies the saved-site export API through the same public entry points consumers use.

The test directly seeds a minimal valid OPFS site so it isolates the API contract without coupling the coverage to WordPress startup or unrelated site-manager UI behavior. Its output assertion verifies the complete browser-to-iframe-to-OPFS-to-ZIP path.

Exercising the real development deployment exposed that the public client shim emitted a root-relative /@fs/ import even when the website was served below /website-server/. Using Vite's configured base fixes that path.

Validation

  • npm exec nx -- run playground-website:e2e:playwright --args='packages/playground/website/playwright/e2e/api.spec.ts --project=chromium'
  • The same E2E against the production static bundle
  • npm exec nx -- run playground-website:lint
  • npm exec nx -- run playground-website:typecheck
  • npm exec nx -- run playground-website:build
  • git diff --check

## What

Adds a short explanation to `api.html` for people who open the endpoint
directly. The paragraph starts with the HTML `hidden` attribute and a
small synchronous script reveals it only when `window.self ===
window.top`. The existing module import remains in `api.html`, but
`bootPlaygroundAPI()` is called only when the page is embedded, so
direct navigation does not initialize the export API and iframe
consumers never receive a visible artifact.

## Direct navigation

Opening `api.html` as the top-level page shows the intended explanation.

![Direct navigation to
api.html](https://gist.githubusercontent.com/ashfame/f597ab984bdb9c762ab39c6a477f818e/raw/53ecaf2cdcc7b8cd6a81c126dd1a3ab0ba781f5f/direct-navigation.png)

## Embedded export

For verification, the API iframe was deliberately made visible and given
a border. It remained blank before and after exporting a real saved
site.

![Visible API iframe remains blank during
export](https://gist.githubusercontent.com/ashfame/f597ab984bdb9c762ab39c6a477f818e/raw/53ecaf2cdcc7b8cd6a81c126dd1a3ab0ba781f5f/embedded-export.png)

## `startPlaygroundWeb()` handling

Passing `api.html` as the `remoteUrl` to `startPlaygroundWeb()` does not
load this page. The client validates the URL before assigning
`iframe.src` and throws an `Invalid remote URL` error because
`startPlaygroundWeb()` requires the pathname to be `/remote.html`. The
new direct-navigation explanation therefore covers someone opening
`api.html` in a browser, while the existing client error covers this API
misuse.

## Tested

- Navigated directly to `api.html` and confirmed the explanation is
visible, `window.playgroundAPI` is not initialized, and no page errors
occur.
- Loaded `api.html` in an iframe and confirmed its body remains visually
empty, its paragraph retains `hidden` with zero client rects,
`window.playgroundAPI` is initialized, and no page errors occur.
- Called `startPlaygroundAPI()` with a deliberately visible iframe,
seeded a real OPFS saved site, and ran `exportSavedSiteAsZip()`.
- Confirmed the export returned `application/zip`, 647 bytes, with the
ZIP `PK\x03\x04` signature.
- Confirmed the iframe body remained empty and the paragraph had zero
visible client rects both before and after export.
- Confirmed `npm exec nx lint playground-website` and `npm exec nx
typecheck playground-website` pass.
@ashfame ashfame changed the title Test the saved-site export API end to end E2E Test for api.html site export Aug 3, 2026
@ashfame
ashfame force-pushed the agent/api-html-e2e-test branch from 552508e to 357be89 Compare August 3, 2026 17:32
@ashfame
ashfame force-pushed the agent/hosted-playground-api-deployment branch from a9045ec to 27cc386 Compare August 3, 2026 17:32

@brandonpayton brandonpayton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tyvm, @ashfame!

Base automatically changed from agent/hosted-playground-api-deployment to trunk August 4, 2026 06:58
@ashfame
ashfame merged commit 0abe80d into trunk Aug 4, 2026
54 checks passed
@ashfame
ashfame deleted the agent/api-html-e2e-test branch August 4, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants