Skip to content

test(worker): the test harness on the Worker (WP11) - #71

Merged
wojciechszyjka merged 19 commits into
mainfrom
feat/wp11-worker-harness
Nov 30, 2026
Merged

wojciechszyjka merged 19 commits into
mainfrom
feat/wp11-worker-harness

Conversation

@wojciechszyjka

@wojciechszyjka wojciechszyjka commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

WP11 of docs/specs/2026-11-29-unified-astro-emdash.md (PR 56): the test harness on the Worker.

Status: complete, except one check: the browser run on the owner's Mac after the merge (below). Tracking plan: kept outside the repository (AGENTS.md rule 1), in the session notes (runs/wp11/PLAN.md).

One command

node scripts/worker-harness.ts --data <checkout of the data branch>

It builds the Worker, seeds a local D1 and R2 once with yarn om emdash-import run (with the derivatives of the static www build), and runs every check against wrangler dev, one Worker at a time (the Mac's limit). Each phase rebuilds dist-worker/ (about 8 s) and starts the Worker on a fresh copy of the seeded state in .wrangler/state. A state already there is moved aside and put back at the end. Options: --only <phase,...>, --port (default 8831), --out (default out/worker-harness), --no-browser.

Phase Build Checks
matrix route matrix inputs, indexed (test/worker/matrix-build.ts) route matrix (answers counted, body hashes reported), smoke, Access, media
noindex the same with PAGES_NOINDEX=1 route matrix
real <data> in the main site's environment, beside a static Run build and a static www build of the same emit first, on the cold isolate, a walk of every page of both sitemaps at 64 at once with a browser's Accept: text/html (test/worker/editorial/walk.ts), then Run parity, editorial parity, compare-live, the SEO surface (test/worker/og/seo.ts), the 34 OG cards pixel by pixel (test/worker/harness-og.ts), the www build tests on a mirror of the Worker, the calculator, the e2e suite with its screenshots, then the OG publication rule (test/worker/og/publish.ts: an unpublished entry's card answers 404, it writes and restores)
publish the fixture data, the committed config plus one Vite hook that gives src/worker/access-entry.ts a key source reading a local key pair (test/worker/harness-astro.config.ts, test/worker/harness-access.ts) WP10's publication checks through the Access gate and EmDash's admin API (test/worker/publish/admin-d1.ts: the guard, the fake purge, the Cron Trigger), the outage of the editorial reads on a new isolate, the tests that the committed config registers the guard (config.test.ts, plugin.test.ts)
stale the stale fixture variant of test/e2e/build.ts stale.spec.ts
templates the template fixture variant templates.spec.ts

Every check prints ok or FAIL with its counts. A difference already owned elsewhere is listed in KNOWN (test/worker/harness.ts) and reported with its owner, so it never hides. The report goes to out/worker-harness/report.txt and report.json. A check that cannot run prints NOT RUN with the reason. Exit 0 when every check ran and passed, 1 when one failed, 2 when a build or a Worker did not start, 3 when every check that ran passed but some did not run.

What changed

  • scripts/worker-harness.ts: the command.
  • test/worker/harness.ts: the counts read from each check's output (ok/FAIL lines, the Access summary, run-parity and editorial-parity JSON, vitest and Playwright JSON reports, the compare-live report), the named differences, the report. A script that crashed with no line of its own, and a test file that failed before its tests ran, count as failures.
  • test/worker/harness-og.ts: every card of dist-www/og asked of the Worker and compared pixel by pixel (at most 0.1 % of pixels over 16 of 255, the threshold of og.test.ts).
  • test/worker/harness-mirror.ts: the Worker's answers laid out as dist-www/: every sitemap address, every entry file of www/content (drafts too), the files the tests read by name and what each page loads. Only a 200 is written.
  • test/www/*-build.test.ts: WWW_DIST names the folder they read (default dist-www, the Pages path). Six assertions no longer depend on attribute order (the Worker's Preact writes attributes in another order) and pageScripts also reads inline module scripts (the Worker inlines the cookie banner's script). Both builds pass: 186 of 186 on dist-www.
  • test/worker/smoke.ts, outside the owned paths (WP01 and WP04 are merged, so it has no other owner; agreed with the coordinator): the harness calls this one smoke check. Its expectations follow main: the home page and the marketing routes from D1 (WP07, PR 66), the OG card route (WP08, PR 70) and 403, never stored, under /_emdash without a signed Access assertion (WP09, PR 68). No check was loosened: each changed answer is the behaviour those PRs ship.
  • Pages path, kept until WP12 removes it and marked so: test/e2e/build.ts, test/e2e/serve.ts, test/design/shots/preview-clock.mjs. gallery-shots.mjs stays on the static build: /_dev/gallery is no route of the Worker build.

Evidence (owner's Mac, 30 Nov 2026, head fa450c2, data f57612e)

node scripts/worker-harness.ts --no-browser --data .data (1.0 min with the seed of an earlier run; a first run with the seed is about 4 min):

Check Result
matrix / route matrix ok: 280 of 284 passed, 4 named
matrix / smoke ok: 37 of 37 passed
matrix / access ok: 1940 of 1940 passed
matrix / media ok: 10 of 10 passed
noindex / route matrix ok: 280 of 284 passed, 4 named
real / concurrent walk ok: 1634 of 1634 passed (817 pages, 2 rounds at 64 at once, cold isolate)
real / run parity ok: 3596 of 3596 passed
real / editorial parity ok: 164 of 168 passed, 4 named
real / compare-live ok: 168 of 168 passed
real / seo ok: 315 of 315 passed
real / og cards ok: 34 of 34 passed
real / www build tests ok: 184 of 184 passed
real / calculator NOT RUN: no browser on this run (--no-browser)
real / e2e NOT RUN: no browser on this run (--no-browser)
real / og publish ok: 13 of 13 passed
publish / publish guard ok: 35 of 35 passed
publish / outage ok: 3 of 3 passed
publish / guard config ok: 6 of 6 passed
stale / e2e NOT RUN: no browser on this run (--no-browser)
templates / e2e NOT RUN: no browser on this run (--no-browser)

worker harness: 16 of 20 checks passed, 0 failed, 4 not run (exit 3), at fa450c2 with main a023276 (WP08, WP10, PR 72, PR 73, PR 74) merged in. 1.4 min with a seed of an earlier run; a first run with the seed is about 5 min.

  • Route matrix: 280 of 284 answers on both variants. The 4 left are /run/_astro/<stylesheet>.css on 4 hosts (WP04 decision 5: one build serves its bundles at /_astro/). Body hashes are reported, not counted (the Worker renders pages anew, as WP07 noted).
  • Named differences: WP05 (4 posts with soft line breaks in pasted code).
  • WP07's test/worker/editorial/publish.ts and seed-d1.ts write through EmDash's REST API without an Access assertion, which WP09 refuses, so the harness no longer runs them: it seeds with EmDash's first load on an empty state and then yarn om emdash-import (the order WP10 found EmDash needs), and checks publication with WP10's admin-d1.ts.

The one remaining check: the browser part, for the owner after the merge

This session's sandbox refuses to start Chrome, so the browser checks ran nowhere yet. On the owner's Mac, in a normal terminal:

yarn playwright install chromium
node scripts/worker-harness.ts --data .data

The first command installs Chromium build 1248, the one Playwright 1.64 asks for (only 1217 is cached on the Mac). The run passes when it exits 0 and its last line reads worker harness: 20 of 20 checks passed, 0 failed, 0 not run, with these four lines ok among the others:

  • real / calculator: test/www/calculator-browser.test.ts on the Worker's /blog-posts/profit-margin-calculator (40%, Add 20 hours 30%, Reset example, the error of a fee of zero, keyboard).
  • real / e2e: every spec of test/e2e against <worker>/run (a11y, demo, install-card, layout, links, mobile, navbar, perf, shots with its screenshots in out/worker-harness/shots).
  • stale / e2e: stale.spec.ts on the stale fixture variant.
  • templates / e2e: templates.spec.ts on the template fixture variant.

Findings for other owners

  • WP10, fixed by PR 74: an editorial page served from the HTML cache skipped the rule that drops EmDash's edit-mode cookie (found by the smoke check; it passes again).
  • WP07, fixed by PR 72: during the first full run, 18 Run receipt pages answered 500 with Cannot perform I/O on behalf of a different request at publishedShell. The harness now walks every page at 64 at once on a cold isolate first; 0 errors at this head.
  • WP00: the body hashes of some machine files in the route matrix differ from the fixtures on the Worker too (feed.xml, /.well-known/*, apple-touch-icon.png, a badge, a module's .md and .json), where WP03 had every machine file equal. The harness lists them on each run (info:). Worth a look whether the fixtures or the files moved.
  • WP09: test/worker/media/live.ts reads .wrangler/state only, so the harness has to seed that folder. An env override (or an argument) would let it use its own folder.
  • WP01: to bring the design gallery into the Worker build, astro.worker.config.ts would need the OM_DEV_GALLERY route of astro.config.ts.

Asked of WP01 (package.json is its file)

     "dev:worker": "wrangler dev --config dist-worker/server/wrangler.json --persist-to .wrangler/state",
+    "test:worker": "node scripts/worker-harness.ts",
     "check": ...

and in test/schema/repo.test.ts, under the dev:worker expectation:

+    // every check of the release candidate against the Worker build (WP11): never part of `yarn test`
+    expect(pkg.scripts['test:worker']).toBe('node scripts/worker-harness.ts')

Checks

yarn check green, yarn test 3233 passed, 22 failed in 5 files (test/proxy/check-sh, test/receipts/harness, test/receipts/presets-r2, test/rentgen/golden, test/validate/workflow-run): mktemp in /var/folders refused by this session's sandbox, the same 22 WP03 and WP07 recorded.

@wojciechszyjka wojciechszyjka left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 om-auto-review-pr: review of d4aea77

Verdict: approve on the code, with the browser run still to do. No blockers or majors are left. The owner's own PR, so this is a comment review.

Validation

Command Result
yarn check pass (with dist-worker/ removed: check-text does not skip it, as WP08 noted)
yarn test 3104 passed, 22 failed in 5 files, each mktemp refused by this session's sandbox (the same 22 WP03 and WP07 recorded)
node scripts/worker-harness.ts --no-browser 10 of 14 checks passed, 0 failed, 4 browser checks skipped
vitest run test/worker/harness.test.ts 19 of 19

Fixed in this review (d4aea77)

  • major: a run stopped hard (SIGKILL) left the owner's .wrangler/state aside and the harness's copy in its place, and the next run moved the copy over the saved state. Now every copy carries a marker, a stopped run is recovered, and a state that is not the harness's copy is never overwritten (setAside, putBack, 4 tests).
  • major: the seed was reused after www/content, www/public or lib/emdash changed, so parity would fail on stale D1 rows. The seed marker is now a fingerprint of those sources (sourceFingerprint, 1 test).

Open, not blocking

  • minor: the harness leaves dist-worker/ of its last phase (the templates fixture when all phases run). Run yarn build:worker before yarn dev:worker after a harness run.
  • minor: when dist-www/ is missing, the static www build runs twice (once for the seed's derivatives, once after the emit).
  • The browser checks (calculator, e2e, stale, templates) have not run yet: this sandbox refuses to start Chrome, and Playwright 1.64 needs Chromium build 1248. To run on the owner's Mac: yarn playwright install chromium, then node scripts/worker-harness.ts --data .data.

CI was pending when this was posted.

@wojciechszyjka
wojciechszyjka marked this pull request as ready for review November 30, 2026 02:27

@wojciechszyjka wojciechszyjka left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 om-auto-review-pr: re-review of ba39dae

Verdict: approve on the code (the owner's own PR, so a comment review). No blockers or majors. Since the last review: main merged in (WP08, WP10, PR 72, PR 73), WP08's and WP10's checks folded in, a cold concurrent walk added, and a publish phase with a build-time key-source swap.

Validation

Command Result
yarn check pass
yarn test 3219 passed, 22 failed in 5 files, each mktemp refused by this session's sandbox (unchanged)
node scripts/worker-harness.ts --no-browser 15 of 20 passed, 1 failed, 4 not run (browser)
node scripts/worker-harness.ts --only publish --no-browser at ba39dae 3 of 3

The failed harness line is smoke, and its cause is outside this PR. The HTML cache of WP10 answers a request with emdash-edit-mode from a cached page, without clearing the cookie and with public caching, because src/worker/editorial-cache.ts runs before src/outer-middleware.ts. The check is kept as it is and named in the description for WP10.

Checked in the new code

  • The key-source swap touches no source file and only access-entry.ts's import of ./access.ts. Signature, issuer, audience and D1 users stay real. A renamed file would make the hook miss, and admin-d1 would then fail on 403, so it cannot pass silently.
  • test/worker/harness-access.ts and harness-astro.config.ts are reachable only from the harness's own build command.
  • The outage is always reverted (outage-end in finally), and the state it renames is the harness's copy.
  • The seed recipe is now part of the seed fingerprint, so a seed made the old way is made again.

Fixed in this review (ba39dae)

  • minor: the ports of the static www server and the fake purge API are now checked before use, as the Worker's port was.

Open, not blocking

  • nit: harness-astro.config.ts has no unit test of its own. The 35 admin checks through the Access gate exercise it.
  • The browser part is the one remaining check, run on the owner's Mac after the merge (command and pass line in the description).

@wojciechszyjka
wojciechszyjka merged commit 132d47f into main Nov 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant