Skip to content

Commit 5a99a0a

Browse files
committed
Add malleable HTML conformance test suite and CI gate
1 parent 988f831 commit 5a99a0a

51 files changed

Lines changed: 1015 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitattributes‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# Auto detect text files and perform LF normalization
22
* text=auto
3+
4+
# Conformance fixtures are byte-exact goldens. Force LF so a CRLF checkout (e.g. on
5+
# Windows) can never fail the byte comparison for a non-bug.
6+
conformance/fixtures/** text eol=lf

‎.github/workflows/ci.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 20
16+
cache: npm
17+
- run: npm ci
18+
# Pinned Chromium for the byte-exact conformance goldens. The version is
19+
# locked by playwright in package.json, so CI and local produce the same bytes.
20+
- name: Install pinned Chromium
21+
run: npx playwright install --with-deps chromium
22+
- name: Unit tests (jest)
23+
run: npm test
24+
- name: Conformance byte gate (web-test-runner)
25+
run: npm run test:conformance

‎conformance/config.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// The only per-repo knobs for the conformance harness. The clayjs mirror sets
2+
// these to its own paths; everything else in conformance/ is identical across the
3+
// two clients. Keeping them here is what makes the harness genuinely portable
4+
// rather than "identical except for a hardcoded path buried in harness.js".
5+
6+
// Server-absolute path to the client's snapshot module, imported in the fixture
7+
// iframe realm. Both clients happen to expose it at the same path today.
8+
export const SNAPSHOT_MODULE = '/src/core/snapshot.js';
9+
10+
// Fixtures directory, relative to a conformance test file. The @web/test-runner
11+
// file command resolves paths from the test file's directory.
12+
export const FIXTURES_DIR = 'fixtures';
13+
14+
// Capabilities a fixture may require (the manifest's client-agnostic `requires`).
15+
// Each maps to the client module the harness imports into the fixture realm to
16+
// exercise it. This is the per-repo mapping: clayjs points `form-persist` at its
17+
// own persistence module. A fixture whose `requires` names a capability absent
18+
// here is skipped, not failed (fixtures.md: a client may skip a feature it lacks
19+
// and still claim conformance on the rest).
20+
export const CAPABILITY_MODULES = {
21+
'form-persist': '/src/core/enablePersistentFormInputValues.js',
22+
};
23+
24+
const SUPPORTED = new Set(Object.keys(CAPABILITY_MODULES));
25+
26+
export function supportsFixture(entry) {
27+
return (entry.requires || []).every((cap) => SUPPORTED.has(cap));
28+
}
29+
30+
export function modulesFor(entry) {
31+
return (entry.requires || []).map((cap) => CAPABILITY_MODULES[cap]).filter(Boolean);
32+
}

‎conformance/conformance.test.js‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { expect } from '@esm-bundle/chai';
2+
import { readFile, writeFile } from '@web/test-runner-commands';
3+
import { runFixture } from './harness.js';
4+
import { FIXTURES_DIR, supportsFixture } from './config.js';
5+
6+
const UPDATE = window.__GOLDEN_UPDATE === true;
7+
const manifest = JSON.parse(await readFile({ path: `${FIXTURES_DIR}/manifest.json` }));
8+
9+
async function goldenAssert(relPath, actual) {
10+
if (UPDATE) {
11+
await writeFile({ path: relPath, content: actual });
12+
return;
13+
}
14+
const golden = await readFile({ path: relPath });
15+
expect(
16+
typeof golden,
17+
`missing golden ${relPath} — run: npm run conformance:update`,
18+
).to.equal('string');
19+
expect(actual).to.equal(golden);
20+
}
21+
22+
for (const fx of manifest.fixtures) {
23+
if (!supportsFixture(fx)) {
24+
describe(`fixture: ${fx.name}`, () => {
25+
it(`skipped — unsupported capability: ${(fx.requires || []).join(', ')}`, function () {
26+
this.skip();
27+
});
28+
});
29+
continue;
30+
}
31+
describe(`fixture: ${fx.name}`, () => {
32+
let out;
33+
before(async () => {
34+
out = await runFixture(fx.name);
35+
});
36+
37+
it('snapshot bytes match golden', async () => {
38+
await goldenAssert(`${FIXTURES_DIR}/${fx.name}/snapshot.html`, out.snapshot);
39+
});
40+
41+
if (!fx.skipDocument) {
42+
it('document bytes match golden', async () => {
43+
await goldenAssert(`${FIXTURES_DIR}/${fx.name}/document.html`, out.document);
44+
});
45+
}
46+
});
47+
}

‎conformance/fixtures/README.md‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Conformance fixtures — canonical home
2+
3+
These are the canonical Malleable HTML File conformance fixtures (spec §11). They are
4+
the published arbiter of exact bytes: a conforming client must reproduce each fixture's
5+
`snapshot.html` and `document.html` byte-for-byte from its `input.html`.
6+
7+
This directory is the single source of truth. The two client repos (hyperclayjs, clayjs)
8+
keep a **checked-in copy** under `conformance/fixtures/` so their own CI can run the byte
9+
gate without this workspace. Do not hand-edit those copies — edit here, then sync.
10+
11+
## Layout
12+
13+
```
14+
fixtures/
15+
manifest.json the fixture list both client suites iterate
16+
<name>/
17+
input.html the source document
18+
snapshot.html expected bytes after algorithm steps 1-6
19+
document.html expected bytes after steps 7-8
20+
```
21+
22+
`snapshot.html` / `document.html` are exact bytes: no trimming, no whitespace collapse,
23+
no line-ending tolerance. LF only (each client's `.gitattributes` forces `eol=lf` so a
24+
CRLF checkout cannot fail the compare on a non-bug).
25+
26+
## Syncing down to the clients
27+
28+
From this repo:
29+
30+
```
31+
npm run sync-fixtures # mirror canonical -> hyperclayjs + clayjs copies
32+
npm run check-fixtures # verify each client copy matches canonical (CI/pre-release guard)
33+
```
34+
35+
`check-fixtures` exits non-zero on any drift. Per-repo CI does not run it (no access to
36+
this workspace); it runs `test:conformance` against the committed copy.
37+
38+
## Regenerating goldens
39+
40+
The goldens are browser-serialization output, so they are generated **in a client** (which
41+
has the browser and the snapshot module), then promoted back up here. Do this only when a
42+
fixture's `input.html`/setup or the snapshot algorithm changes on purpose.
43+
44+
1. Edit `input.html` / `manifest.json` here; `npm run sync-fixtures` to push down.
45+
(Imperative setup lives in each client's `conformance/setups.js`, kept identical by hand.)
46+
2. In **each** client: `npm run conformance:update` to regenerate its goldens.
47+
3. Cross-verify the two clients are byte-identical — this is the real conformance check:
48+
`diff -rq hyperclayjs/conformance/fixtures clayjs/conformance/fixtures` must be empty.
49+
4. Promote up: `cp -R hyperclayjs/conformance/fixtures/. malleablehtmlfile/fixtures/`
50+
then `npm run check-fixtures` to confirm both clients now match canonical.
51+
52+
The browser is pinned (Playwright Chromium, version-locked in each client's `package.json`)
53+
so regeneration is reproducible across machines and CI.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html><html lang="en"><head>
2+
<meta charset="utf-8">
3+
<title>Baseline</title>
4+
</head>
5+
<body>
6+
<h1>Hello</h1>
7+
<p>A baseline document that round-trips unchanged.</p>
8+
9+
10+
</body></html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Baseline</title>
6+
</head>
7+
<body>
8+
<h1>Hello</h1>
9+
<p>A baseline document that round-trips unchanged.</p>
10+
</body>
11+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html><html lang="en"><head>
2+
<meta charset="utf-8">
3+
<title>Baseline</title>
4+
</head>
5+
<body>
6+
<h1>Hello</h1>
7+
<p>A baseline document that round-trips unchanged.</p>
8+
9+
10+
</body></html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html><html lang="en"><head>
2+
<meta charset="utf-8">
3+
<title>Doctype coercion</title>
4+
</head>
5+
<body>
6+
<p>The source doctype is not HTML5; the saved document must begin with the HTML5 doctype.</p>
7+
8+
9+
</body></html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Doctype coercion</title>
6+
</head>
7+
<body>
8+
<p>The source doctype is not HTML5; the saved document must begin with the HTML5 doctype.</p>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)