Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3ef19f2
test(worker): counts, named differences and the www mirror of the Wor…
wojciechszyjka Nov 30, 2026
0a81840
test(www): the build tests read a Worker mirror with WWW_DIST (WP11)
wojciechszyjka Nov 30, 2026
13deb18
test(www): build tests independent of attribute order and inline modu…
wojciechszyjka Nov 30, 2026
de1c2d6
test(worker): smoke expectations of the WP07 pages and the WP09 Acces…
wojciechszyjka Nov 30, 2026
ab25ae0
test(worker): suite errors, crashed scripts and named owners in the h…
wojciechszyjka Nov 30, 2026
6cc7ca5
feat(scripts): one command runs every check against the Worker build …
wojciechszyjka Nov 30, 2026
51f8924
test(e2e): mark the static-build tools kept for the Pages path until …
wojciechszyjka Nov 30, 2026
d4aea77
fix(scripts): keep the owner's D1 state after a stopped run and resee…
wojciechszyjka Nov 30, 2026
76f0c4a
test(worker): name the PR behind each changed smoke expectation (WP11)
wojciechszyjka Nov 30, 2026
47a64c0
feat(scripts): checks that cannot run print NOT RUN and exit 3 (WP11)
wojciechszyjka Nov 30, 2026
0e5c7a3
Merge remote-tracking branch 'origin/main' into feat/wp11-worker-harness
wojciechszyjka Nov 30, 2026
da7dab1
test(worker): smoke route list with the OG cards of WP08 (WP11)
wojciechszyjka Nov 30, 2026
45f3be5
feat(scripts): the SEO comparison, the OG card pixels and the OG publ…
wojciechszyjka Nov 30, 2026
3db1602
Merge remote-tracking branch 'origin/main' into feat/wp11-worker-harness
wojciechszyjka Nov 30, 2026
1537620
feat(scripts): a cold concurrent walk of every page, WP07's publish.t…
wojciechszyjka Nov 30, 2026
07c8c27
Merge remote-tracking branch 'origin/main' into feat/wp11-worker-harness
wojciechszyjka Nov 30, 2026
1600571
feat(scripts): WP10's publication checks through the Access gate with…
wojciechszyjka Nov 30, 2026
ba39dae
fix(scripts): check the ports of the static server and the fake purge…
wojciechszyjka Nov 30, 2026
fa450c2
Merge remote-tracking branch 'origin/main' into feat/wp11-worker-harness
wojciechszyjka Nov 30, 2026
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
588 changes: 588 additions & 0 deletions scripts/worker-harness.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/design/shots/gallery-shots.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Static build only: /_dev/gallery is not a route of the Worker build (OM_DEV_GALLERY injects it in astro.config.ts
// alone). The page screenshots on the Worker are test/e2e/shots.spec.ts, run by scripts/worker-harness.ts.
// Screenshots of the design gallery (WP11): 1440 and 390 px, full page and one PNG per section.
// Not in CI. Build on real data first (the gallery renders site/.generated when it exists):
// yarn om emit --data .data && OM_DEV_GALLERY=1 yarn astro build
Expand Down
1 change: 1 addition & 0 deletions test/design/shots/preview-clock.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Pages path, kept until WP12 removes it: it reads a static dist of preview data.
// A preview build opened days later (review r6, P0): the clock of the browser is frozen at 27 Oct, four days after
// the preview run of 23 Oct. The STALE DATA banner must stay hidden on every page and the header stamp must read
// `Preview <day>` with no hour and no stale dot, because no nightly run exists to be late. A CI build (dataAsOf
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/build.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Pages path, kept until WP12 removes it: on the Worker, scripts/worker-harness.ts builds these variants and runs the
// suite against `wrangler dev` (E2E_BASE_URL, E2E_STALE_URL, E2E_TEMPLATES_URL).
// Builds the static sites the e2e suite reads (WP16): `real` from a data checkout (E2E_DATA, default .data),
// `stale`, a variant of the CI fixture (test/fixtures/data) whose newest receipt (`dataAsOf.nightly`) is 3 days
// and 1 hour old while `generatedAt` and the npm check are fresh, so the STALE DATA banner of spec 7.6 / 7.8 (P5)
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/serve.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Pages path, kept until WP12 removes it (scripts/worker-harness.ts also serves dist-www with it as the reference of
// compare-live).
// A tiny static server with the lookup order of the static host (spec 3.4, WP02 item 13), for the e2e suite (WP16).
// `/m/@x/y` answers with `m/@x/y.html` even when the folder `m/@x/y/` sits next to it, a folder without a trailing
// slash and with an index.html answers 301, and so does a base path without its slash (`/run`), so the link
Expand Down
17 changes: 17 additions & 0 deletions test/worker/harness-access.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// The Access key source of the harness's publish build (WP11, test/worker/harness-astro.config.ts): the real module of
// src/worker/access.ts with one change, the key set comes from the local key pair of `test/worker/publish/admin-d1.ts
// keys` instead of https://<team>.cloudflareaccess.com, which a local run cannot reach. Verification, issuer,
// audience, expiry and the users of D1 stay the real ones. Never part of a release build.
import { remoteKeys as realRemoteKeys, type KeySource } from '../../src/worker/access.ts'

export * from '../../src/worker/access.ts'

/** The JSON key set of the local key pair, written into this module by the harness build. */
declare const OM_HARNESS_JWKS: string

export function remoteKeys(teamDomain: string): KeySource {
return realRemoteKeys(
teamDomain,
async () => new Response(OM_HARNESS_JWKS, { headers: { 'content-type': 'application/json' } }),
)
}
33 changes: 33 additions & 0 deletions test/worker/harness-astro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// The Worker build of the harness's publish phase (WP11, scripts/worker-harness.ts): astro.worker.config.ts as it is,
// plus one Vite hook that gives src/worker/access-entry.ts the key source of test/worker/harness-access.ts, so EmDash's
// admin API can be called with an assertion signed by a local key pair (WP10's admin-d1.ts). No source file changes.
// OM_HARNESS_JWKS_FILE names the public key set (`node test/worker/publish/admin-d1.ts keys` writes it).
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import type { AstroUserConfig } from 'astro'
import base from '../../astro.worker.config.ts'

const ACCESS = fileURLToPath(new URL('./harness-access.ts', import.meta.url))
const file = process.env.OM_HARNESS_JWKS_FILE
if (!file) throw new Error('OM_HARNESS_JWKS_FILE names the public key set of the local key pair')
const jwks = readFileSync(file, 'utf8')

/** Resolves the `./access.ts` import of access-entry.ts, and only that one, to the harness's key source. */
const localKeys = {
name: 'om-harness-access-keys',
enforce: 'pre' as const,
resolveId(id: string, importer?: string): string | undefined {
if (id === './access.ts' && importer?.replace(/\\/g, '/').endsWith('/src/worker/access-entry.ts')) return ACCESS
return undefined
},
}

const config: AstroUserConfig = {
...base,
vite: {
...base.vite,
define: { ...base.vite?.define, OM_HARNESS_JWKS: JSON.stringify(jwks) },
plugins: [localKeys, ...(base.vite?.plugins ?? [])],
},
}
export default config
130 changes: 130 additions & 0 deletions test/worker/harness-mirror.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// A copy of what a running Worker answers for the main site, laid out as the static build lays out dist-www/
// (`/blog` is blog.html, `/blog-posts/x` is blog-posts/x.html, `/` is index.html, a miss is 404.html), so the build
// tests of test/www/*-build.test.ts read the Worker with WWW_DIST=<folder> and no change to their checks (WP11).
// The paths asked: every address of the Worker's sitemaps, every entry file of www/content (drafts too, so a draft the
// Worker routes shows up as a file the tests refuse), the files those tests read by name, and every og:image and
// image of the site that a page names. Only a 200 is written; a miss leaves no file, as a page the build never wrote.
// node test/worker/harness-mirror.ts <origin> <folder>
import { mkdirSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { ROOT } from '../emit/helpers.ts'

/** Where the entries of a folder of www/content are routed (www/src/pages). */
export const CONTENT_ROUTES: Record<string, string> = {
blog: '/blog-posts/',
'case-studies': '/case-studies/',
partners: '/certified-partners/',
jobs: '/careers-jobs/',
landings: '/',
pages: '/',
}

/** Files the build tests read by name, beside the pages. */
export const FIXED_PATHS = [
'/llms.txt',
'/robots.txt',
'/sitemap-index.xml',
'/sitemap-0.xml',
'/files/page-not-found.svg',
'/apple-touch-icon.png',
]

/** The file of a site path in the dist-www layout. */
export function fileOf(path: string): string {
const clean = decodeURIComponent(path.split(/[?#]/)[0]!).replace(/\/+$/, '')
if (clean === '') return 'index.html'
const rel = clean.slice(1)
return /\.[a-z0-9]+$/i.test(rel) ? rel : `${rel}.html`
}

/** The site path of every entry file under www/content (drafts included). */
export function contentPaths(content = join(ROOT, 'www', 'content')): string[] {
const out: string[] = []
for (const [dir, route] of Object.entries(CONTENT_ROUTES)) {
for (const f of readdirSync(join(content, dir))) {
const id = f.replace(/\.(md|mdx|json|yaml)$/, '')
if (id === f) continue
out.push(route === '/' && id === 'home' ? '/' : `${route}${id}`)
}
}
return out
}

/** The paths on this origin of every `<loc>` of a sitemap text. */
export function sitemapPaths(xml: string): string[] {
return [...xml.matchAll(/<loc>([^<]*)<\/loc>/g)].map((m) => new URL(m[1]!).pathname)
}

/**
* Site paths of the files a page names that the build tests read: og:image and images under /og/, /media/ or /files/,
* and the module scripts and stylesheets it loads.
*/
export function linkedPaths(html: string): string[] {
const out = new Set<string>()
for (const m of html.matchAll(
/(?:content|src|href)="(?:https:\/\/www\.openmercato\.com)?(\/(?:og|media|files)\/[^"?#]+)"/g,
))
out.add(m[1]!)
for (const m of html.matchAll(/<script type="module" src="(\/[^"]+)"/g)) out.add(m[1]!)
for (const m of html.matchAll(/<link rel="stylesheet" href="(\/[^"]+)"/g)) out.add(m[1]!)
return [...out]
}

export interface MirrorResult {
asked: number
written: number
missing: string[]
}

export async function mirror(origin: string, dest: string, extra: readonly string[] = []): Promise<MirrorResult> {
rmSync(dest, { recursive: true, force: true })
mkdirSync(dest, { recursive: true })
// one retry on a network error: a kept-alive socket the dev server closed meanwhile fails the first request on it
const get = (path: string) =>
fetch(`${origin}${path}`, { redirect: 'manual' }).catch(() => fetch(`${origin}${path}`, { redirect: 'manual' }))
const save = (path: string, body: Uint8Array) => {
const file = join(dest, fileOf(path))
mkdirSync(dirname(file), { recursive: true })
writeFileSync(file, body)
}
const index = await (await get('/sitemap-index.xml')).text()
const maps = sitemapPaths(index).filter((p) => !p.startsWith('/run/'))
const pages = new Set<string>([...contentPaths(), ...extra])
for (const m of maps) for (const p of sitemapPaths(await (await get(m)).text())) pages.add(p)
const result: MirrorResult = { asked: 0, written: 0, missing: [] }
const images = new Set<string>()
const one = async (path: string, isPage: boolean): Promise<void> => {
result.asked++
const res = await get(path)
const body = new Uint8Array(await res.arrayBuffer())
if (res.status !== 200) {
result.missing.push(`${res.status} ${path}`)
return
}
save(path, body)
result.written++
if (isPage) for (const i of linkedPaths(new TextDecoder().decode(body))) images.add(i)
}
const queue = [...[...pages].map((p) => [p, true] as const), ...FIXED_PATHS.map((p) => [p, false] as const)]
const drain = async (q: (readonly [string, boolean])[]) =>
Promise.all(
Array.from({ length: 6 }, async () => {
for (let j = q.shift(); j !== undefined; j = q.shift()) await one(j[0], j[1])
}),
)
await drain(queue)
// the page of a miss, as the build writes 404.html, and what it loads
const miss = new Uint8Array(await (await get('/no-such-page-of-the-harness')).arrayBuffer())
writeFileSync(join(dest, '404.html'), miss)
for (const i of linkedPaths(new TextDecoder().decode(miss))) images.add(i)
await drain([...images].filter((i) => !FIXED_PATHS.includes(i)).map((i) => [i, false] as const))
result.missing.sort()
return result
}

if (import.meta.url === `file://${process.argv[1]}`) {
const [origin, dest] = process.argv.slice(2)
if (!origin || !dest) throw new Error('usage: node test/worker/harness-mirror.ts <origin> <folder>')
const r = await mirror(origin.replace(/\/+$/, ''), dest)
console.log(`mirror: ${r.written} of ${r.asked} answered 200 into ${dest}`)
}
45 changes: 45 additions & 0 deletions test/worker/harness-og.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// The OG cards of the Worker against the static cards (WP08 acceptance, run by scripts/worker-harness.ts, WP11): every
// PNG of <dist-www>/og is asked of the Worker at /og/<name> and compared pixel by pixel. A card passes when it answers
// 200 with a PNG of the same size and at most 0.1 % of its pixels differ by more than 16 of 255 in a channel, the
// threshold of test/worker/og/og.test.ts. Prints one `ok` or `FAIL` line per card; exit 1 when one fails.
// node test/worker/harness-og.ts <dist-www> <origin>
import { readdirSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { decodePng, diffShare } from './og/png.ts'

/** The share of pixels that may differ (0.1 %). */
export const MAX_SHARE = 0.001

/** The verdict on one card: the share that differs, or why it could not be compared. */
export function compareCard(
staticPng: Uint8Array,
status: number,
workerPng: Uint8Array,
): { ok: boolean; why: string } {
if (status !== 200) return { ok: false, why: `${status}` }
let share: number
try {
share = diffShare(decodePng(staticPng), decodePng(workerPng))
} catch (e) {
return { ok: false, why: (e as Error).message }
}
return { ok: share <= MAX_SHARE, why: `${(share * 100).toFixed(3)} % of pixels differ` }
}

if (import.meta.url === `file://${process.argv[1]}`) {
const [dist, origin] = process.argv.slice(2)
if (!dist || !origin) throw new Error('usage: node test/worker/harness-og.ts <dist-www> <origin>')
const cards = readdirSync(join(dist, 'og'))
.filter((f) => f.endsWith('.png'))
.sort()
let failed = 0
for (const name of cards) {
const res = await fetch(`${origin.replace(/\/+$/, '')}/og/${name}`, { redirect: 'manual' })
const body = new Uint8Array(await res.arrayBuffer())
const v = compareCard(readFileSync(join(dist, 'og', name)), res.status, body)
if (!v.ok) failed++
console.log(`${v.ok ? 'ok ' : 'FAIL'} /og/${name}: ${v.why}`)
}
console.log(`${cards.length - failed} of ${cards.length} cards equal to the static ones`)
process.exitCode = failed === 0 && cards.length > 0 ? 0 : 1
}
Loading