From 08fab64f3d9981f449ecd33256d952b9fbaeba82 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 27 Oct 2026 11:46:10 -0700 Subject: [PATCH 1/6] test(ci): the CDN smoke test's render, moved to a module, fails the whole run on a navigation timeout cdn-template-smoke-test.mjs's render() and its retry loop move unchanged to .github/scripts/lib/cdn-page-render.mjs (renderPage, isCleanRender, renderUntilClean), with the navigation and button timeouts as options, so they can be tested. The tests fail on that unchanged code: - with Playwright's page events and no browser (cdn-page-render.test.mjs): a navigation that times out escapes renderPage as a TimeoutError, so renderUntilClean never retries it and nothing names the request that kept the page from going idle; - in Chromium against a local page whose module request is never answered (cdn-page-render.browser.test.mjs, ASTRYX_CDN_SMOKE_BROWSER=1): the same TimeoutError, the one a smoke-test run hit when a CDN request hung. A navigation error that is not a timeout still throws, and a page that goes idle and renders a button is still clean. --- .github/scripts/cdn-template-smoke-test.mjs | 54 +----- .../lib/cdn-page-render.browser.test.mjs | 65 ++++++++ .github/scripts/lib/cdn-page-render.mjs | 90 ++++++++++ .github/scripts/lib/cdn-page-render.test.mjs | 154 ++++++++++++++++++ 4 files changed, 317 insertions(+), 46 deletions(-) create mode 100644 .github/scripts/lib/cdn-page-render.browser.test.mjs create mode 100644 .github/scripts/lib/cdn-page-render.mjs create mode 100644 .github/scripts/lib/cdn-page-render.test.mjs diff --git a/.github/scripts/cdn-template-smoke-test.mjs b/.github/scripts/cdn-template-smoke-test.mjs index 107ea5bc77939..aab8f078afcd0 100644 --- a/.github/scripts/cdn-template-smoke-test.mjs +++ b/.github/scripts/cdn-template-smoke-test.mjs @@ -30,6 +30,7 @@ import * as os from 'node:os'; import * as path from 'node:path'; import {fileURLToPath} from 'node:url'; import {pageAssetUrls, primeCdnAssets} from './lib/cdn-asset-priming.mjs'; +import {renderPage, renderUntilClean} from './lib/cdn-page-render.mjs'; import {resolvePublishedCdnVersion} from './lib/cdn-version.mjs'; const ROOT = path.resolve( @@ -147,53 +148,14 @@ const server = http.createServer((req, res) => { await new Promise(resolve => server.listen(0, '127.0.0.1', resolve)); const url = `http://127.0.0.1:${server.address().port}/`; -/** Load the page once and report everything that went wrong. */ -async function render() { - const consoleErrors = []; - const pageErrors = []; - const failedRequests = []; - - const browser = await chromium.launch(); - try { - const page = await browser.newPage(); - page.on('console', m => { - if (m.type() === 'error') consoleErrors.push(m.text().slice(0, 300)); - }); - page.on('pageerror', e => pageErrors.push(String(e).slice(0, 300))); - page.on('requestfailed', r => - failedRequests.push(`${r.url()} :: ${r.failure()?.errorText}`), - ); - page.on('response', r => { - if (r.status() >= 400) failedRequests.push(`${r.status()} ${r.url()}`); - }); - - await page.goto(url, {waitUntil: 'networkidle', timeout: 90_000}); - // A page that throws during render still reaches networkidle with an empty - // root, so the render itself has to be asserted, not just the error streams. - const button = await page - .getByRole('button') - .first() - .textContent({timeout: 15_000}) - .catch(() => null); - - return {consoleErrors, pageErrors, failedRequests, button}; - } finally { - await browser.close(); - } -} - // ── 5. Render, retrying once so a blip at a CDN is not a red build ─────────── -let result; -for (let attempt = 1; attempt <= ATTEMPTS; attempt++) { - result = await render(); - const clean = - result.consoleErrors.length === 0 && - result.pageErrors.length === 0 && - result.failedRequests.length === 0 && - result.button; - if (clean) break; - if (attempt < ATTEMPTS) console.log(` retry ${attempt} of ${ATTEMPTS - 1}`); -} +const result = await renderUntilClean( + () => renderPage(url, {launch: () => chromium.launch()}), + { + attempts: ATTEMPTS, + onRetry: attempt => console.log(` retry ${attempt} of ${ATTEMPTS - 1}`), + }, +); server.close(); // ── 6. Report ──────────────────────────────────────────────────────────────── diff --git a/.github/scripts/lib/cdn-page-render.browser.test.mjs b/.github/scripts/lib/cdn-page-render.browser.test.mjs new file mode 100644 index 0000000000000..9b987c7dbf112 --- /dev/null +++ b/.github/scripts/lib/cdn-page-render.browser.test.mjs @@ -0,0 +1,65 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. + +/** + * @file cdn-page-render.browser.test.mjs + * @input A local page whose module request is never answered, and Chromium; + * run with ASTRYX_CDN_SMOKE_BROWSER=1 after `npx playwright install chromium` + * @output Real-browser proof that a page with a request that hangs never goes + * idle, and that renderPage reports that navigation timeout with the hung + * request instead of throwing + * @position The browser half of cdn-page-render.test.mjs, which runs the same + * rules against Playwright's events without a browser + */ + +import http from 'node:http'; +import {chromium} from 'playwright'; +import {afterAll, beforeAll, describe, expect, it} from 'vitest'; +import {renderPage} from './cdn-page-render.mjs'; + +const PAGE = + '' + + ''; + +describe.runIf(process.env.ASTRYX_CDN_SMOKE_BROWSER === '1')( + 'renderPage in Chromium', + () => { + /** The module responses held open, so the page can never go idle. */ + const held = []; + let server; + let url; + + beforeAll(async () => { + server = http.createServer((req, res) => { + if (req.url === '/stall.js') { + held.push(res); + return; + } + res.writeHead(200, {'content-type': 'text/html; charset=utf-8'}); + res.end(PAGE); + }); + await new Promise(resolve => { + server.listen(0, '127.0.0.1', resolve); + }); + url = `http://127.0.0.1:${server.address().port}/`; + }); + + afterAll(async () => { + for (const res of held) { + res.destroy(); + } + server.closeAllConnections(); + await new Promise(resolve => { + server.close(resolve); + }); + }); + + it('reports a page that never goes idle, naming the module that hung', async () => { + const result = await renderPage(url, { + launch: async () => chromium.launch(), + navigationTimeoutMs: 2_000, + }); + expect(result.timedOut).toBe(true); + expect(result.pendingRequests).toEqual([`${url}stall.js`]); + }); + }, +); diff --git a/.github/scripts/lib/cdn-page-render.mjs b/.github/scripts/lib/cdn-page-render.mjs new file mode 100644 index 0000000000000..9ff5a28a7911e --- /dev/null +++ b/.github/scripts/lib/cdn-page-render.mjs @@ -0,0 +1,90 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. + +/** + * Render the CDN starter page in a browser, and report what went wrong. + * + * One render loads the page until its network goes idle, then reads the first + * button: a page that throws while rendering still goes idle with an empty + * root, so the render itself is asserted, not only the error streams. + * renderUntilClean retries an unclean render once, so a blip at a CDN is not a + * red build. + */ + +/** + * Load `url` once in a browser from `launch`, and collect its console errors, + * page errors and failed requests, and the first button's text (null when no + * button rendered). + * + * @param {string} url + * @param {{ + * launch: () => Promise, + * navigationTimeoutMs?: number, + * buttonTimeoutMs?: number, + * }} options + */ +export async function renderPage( + url, + {launch, navigationTimeoutMs = 90_000, buttonTimeoutMs = 15_000}, +) { + const consoleErrors = []; + const pageErrors = []; + const failedRequests = []; + + const browser = await launch(); + try { + const page = await browser.newPage(); + page.on('console', m => { + if (m.type() === 'error') consoleErrors.push(m.text().slice(0, 300)); + }); + page.on('pageerror', e => pageErrors.push(String(e).slice(0, 300))); + page.on('requestfailed', r => + failedRequests.push(`${r.url()} :: ${r.failure()?.errorText}`), + ); + page.on('response', r => { + if (r.status() >= 400) failedRequests.push(`${r.status()} ${r.url()}`); + }); + + await page.goto(url, { + waitUntil: 'networkidle', + timeout: navigationTimeoutMs, + }); + const button = await page + .getByRole('button') + .first() + .textContent({timeout: buttonTimeoutMs}) + .catch(() => null); + + return {consoleErrors, pageErrors, failedRequests, button}; + } finally { + await browser.close(); + } +} + +/** Whether a render came back with nothing wrong and a button on the page. */ +export function isCleanRender(result) { + return ( + result.consoleErrors.length === 0 && + result.pageErrors.length === 0 && + result.failedRequests.length === 0 && + Boolean(result.button) + ); +} + +/** + * Run `render` until one comes back clean, at most `attempts` times, and + * return the last result. `onRetry(attempt)` hears each retry. + * + * @template {{consoleErrors: string[], pageErrors: string[], failedRequests: string[], button: string | null}} R + * @param {() => Promise} render + * @param {{attempts?: number, onRetry?: (attempt: number) => void}} [options] + * @returns {Promise} + */ +export async function renderUntilClean(render, {attempts = 2, onRetry} = {}) { + let result; + for (let attempt = 1; attempt <= attempts; attempt++) { + result = await render(); + if (isCleanRender(result)) break; + if (attempt < attempts) onRetry?.(attempt); + } + return result; +} diff --git a/.github/scripts/lib/cdn-page-render.test.mjs b/.github/scripts/lib/cdn-page-render.test.mjs new file mode 100644 index 0000000000000..1a6094b1359d1 --- /dev/null +++ b/.github/scripts/lib/cdn-page-render.test.mjs @@ -0,0 +1,154 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. + +import {EventEmitter} from 'node:events'; +import {describe, expect, it} from 'vitest'; +import { + isCleanRender, + renderPage, + renderUntilClean, +} from './cdn-page-render.mjs'; + +const URL = 'http://127.0.0.1:1/'; +const CORE = 'https://esm.sh/@astryxdesign/core@0.7.4?external=react,react-dom'; +const CSS = + 'https://cdn.jsdelivr.net/npm/@astryxdesign/core@0.7.4/dist/astryx.css'; + +/** A request as Playwright's page events carry it. */ +function request(url, errorText = null) { + return { + url: () => url, + failure: () => (errorText == null ? null : {errorText}), + }; +} + +/** The error Playwright's `page.goto` throws when its wait never completes. */ +function navigationTimeout() { + const error = new Error('page.goto: Timeout 90000ms exceeded.'); + error.name = 'TimeoutError'; + return error; +} + +/** + * A browser `launch` whose pages run `onGoto(page, launchIndex)` while + * navigating, then settle the navigation with `gotoErrors[launchIndex]` (none + * resolves it) and answer the button query with `button`. + */ +function fakeLaunch({onGoto = () => {}, gotoErrors = [], button = 'Start'}) { + let launches = 0; + let closed = 0; + const launch = async () => { + const index = launches; + launches += 1; + const page = new EventEmitter(); + page.goto = async () => { + onGoto(page, index); + const error = gotoErrors[index]; + if (error != null) { + throw error; + } + }; + page.getByRole = () => ({ + first: () => ({textContent: async () => button}), + }); + return { + newPage: async () => page, + close: async () => { + closed += 1; + }, + }; + }; + return {launch, launches: () => launches, closed: () => closed}; +} + +describe('renderPage', () => { + it('reports a page that goes idle and renders a button as clean', async () => { + const {launch, closed} = fakeLaunch({ + onGoto: page => { + const css = request(CSS); + page.emit('request', css); + page.emit('requestfinished', css); + }, + }); + const result = await renderPage(URL, {launch}); + expect(result.button).toBe('Start'); + expect(isCleanRender(result)).toBe(true); + expect(closed()).toBe(1); + }); + + it('reports a navigation that times out as an unclean render, naming the requests still in flight', async () => { + const {launch, closed} = fakeLaunch({ + onGoto: page => { + const css = request(CSS); + const core = request(CORE); + page.emit('request', css); + page.emit('requestfinished', css); + page.emit('request', core); + }, + gotoErrors: [navigationTimeout()], + }); + const result = await renderPage(URL, {launch}); + expect(result.timedOut).toBe(true); + expect(result.pendingRequests).toEqual([CORE]); + expect(isCleanRender(result)).toBe(false); + expect(closed()).toBe(1); + }); + + it('counts a failed request as failed, not as still in flight', async () => { + const {launch} = fakeLaunch({ + onGoto: page => { + const core = request(CORE, 'net::ERR_BLOCKED_BY_ORB'); + page.emit('request', core); + page.emit('requestfailed', core); + }, + gotoErrors: [navigationTimeout()], + }); + const result = await renderPage(URL, {launch}); + expect(result.failedRequests).toEqual([ + `${CORE} :: net::ERR_BLOCKED_BY_ORB`, + ]); + expect(result.pendingRequests).toEqual([]); + }); + + it('still throws a navigation error that is not a timeout: the local server failing is not a CDN blip', async () => { + const refused = new Error('page.goto: net::ERR_CONNECTION_REFUSED'); + const {launch, closed} = fakeLaunch({gotoErrors: [refused]}); + await expect(renderPage(URL, {launch})).rejects.toBe(refused); + expect(closed()).toBe(1); + }); +}); + +describe('renderUntilClean', () => { + it('retries a navigation timeout once, then reports the requests still in flight', async () => { + const {launch, launches} = fakeLaunch({ + onGoto: page => page.emit('request', request(CORE)), + gotoErrors: [navigationTimeout(), navigationTimeout()], + }); + const retries = []; + const result = await renderUntilClean(() => renderPage(URL, {launch}), { + attempts: 2, + onRetry: attempt => retries.push(attempt), + }); + expect(launches()).toBe(2); + expect(retries).toEqual([1]); + expect(result.timedOut).toBe(true); + expect(result.pendingRequests).toEqual([CORE]); + }); + + it('stops at the first clean render after a timeout', async () => { + const {launch, launches} = fakeLaunch({ + onGoto: (page, index) => { + const core = request(CORE); + page.emit('request', core); + if (index > 0) { + page.emit('requestfinished', core); + } + }, + gotoErrors: [navigationTimeout()], + }); + const result = await renderUntilClean(() => renderPage(URL, {launch}), { + attempts: 2, + }); + expect(launches()).toBe(2); + expect(isCleanRender(result)).toBe(true); + }); +}); From 6b0fb942fdc931749e7955f9b3f85893a80348a6 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 27 Oct 2026 11:47:34 -0700 Subject: [PATCH 2/6] fix(ci): the CDN smoke test retries a page that never goes idle and names the request that hung renderPage now treats a navigation timeout as an unclean render: it tracks the requests the page made that neither finished nor failed, and on Playwright's TimeoutError returns timedOut with those URLs (pendingRequests) instead of throwing. isCleanRender counts it as unclean, so renderUntilClean retries it once, as the script's comment always promised for a CDN blip. Any other navigation error still throws. The script's report names the timeout and every request still in flight, and skips the 'rendered no button' line it would otherwise add for a page that never finished loading. --- .github/scripts/cdn-template-smoke-test.mjs | 12 +++- .github/scripts/lib/cdn-page-render.mjs | 65 ++++++++++++++++----- 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/.github/scripts/cdn-template-smoke-test.mjs b/.github/scripts/cdn-template-smoke-test.mjs index aab8f078afcd0..511a8dfef070f 100644 --- a/.github/scripts/cdn-template-smoke-test.mjs +++ b/.github/scripts/cdn-template-smoke-test.mjs @@ -160,6 +160,16 @@ server.close(); // ── 6. Report ──────────────────────────────────────────────────────────────── console.log(`\n${PAGE} @ ${rendered}`); +if (result.timedOut) { + fail( + 'the page never went idle, so its navigation timed out', + result.pendingRequests.length === 0 + ? ' no request was in flight when the wait gave up' + : result.pendingRequests + .map(entry => ` still in flight: ${entry}`) + .join('\n'), + ); +} for (const [label, entries] of [ ['console error', result.consoleErrors], ['page error', result.pageErrors], @@ -176,7 +186,7 @@ for (const [label, entries] of [ } if (result.button) { console.log(` ok rendered a button: "${result.button.trim()}"`); -} else { +} else if (!result.timedOut) { fail('the page loaded but rendered no button'); } diff --git a/.github/scripts/lib/cdn-page-render.mjs b/.github/scripts/lib/cdn-page-render.mjs index 9ff5a28a7911e..a44e3dd56577a 100644 --- a/.github/scripts/lib/cdn-page-render.mjs +++ b/.github/scripts/lib/cdn-page-render.mjs @@ -5,15 +5,25 @@ * * One render loads the page until its network goes idle, then reads the first * button: a page that throws while rendering still goes idle with an empty - * root, so the render itself is asserted, not only the error streams. - * renderUntilClean retries an unclean render once, so a blip at a CDN is not a - * red build. + * root, so the render itself is asserted, not only the error streams. A page + * with a request that never finishes never goes idle, so its navigation times + * out: that is an unclean render like any other, reported with the requests + * still in flight when the wait gave up, so the output names the asset that + * hung instead of ending the run on a stack trace. renderUntilClean retries + * an unclean render once, so a blip at a CDN is not a red build. */ +/** Playwright's error for a navigation whose wait condition never came. */ +function isTimeout(error) { + return error?.name === 'TimeoutError'; +} + /** * Load `url` once in a browser from `launch`, and collect its console errors, * page errors and failed requests, and the first button's text (null when no - * button rendered). + * button rendered). A navigation that times out comes back with `timedOut` + * and the URLs still in flight (`pendingRequests`, in request order); any + * other navigation error throws. * * @param {string} url * @param {{ @@ -29,6 +39,8 @@ export async function renderPage( const consoleErrors = []; const pageErrors = []; const failedRequests = []; + /** Requests the page made that have neither finished nor failed. */ + const inFlight = new Set(); const browser = await launch(); try { @@ -37,32 +49,57 @@ export async function renderPage( if (m.type() === 'error') consoleErrors.push(m.text().slice(0, 300)); }); page.on('pageerror', e => pageErrors.push(String(e).slice(0, 300))); - page.on('requestfailed', r => - failedRequests.push(`${r.url()} :: ${r.failure()?.errorText}`), - ); + page.on('request', r => inFlight.add(r)); + page.on('requestfinished', r => inFlight.delete(r)); + page.on('requestfailed', r => { + inFlight.delete(r); + failedRequests.push(`${r.url()} :: ${r.failure()?.errorText}`); + }); page.on('response', r => { if (r.status() >= 400) failedRequests.push(`${r.status()} ${r.url()}`); }); - await page.goto(url, { - waitUntil: 'networkidle', - timeout: navigationTimeoutMs, - }); + try { + await page.goto(url, { + waitUntil: 'networkidle', + timeout: navigationTimeoutMs, + }); + } catch (error) { + if (!isTimeout(error)) { + throw error; + } + return { + consoleErrors, + pageErrors, + failedRequests, + timedOut: true, + pendingRequests: [...inFlight].map(r => r.url()), + button: null, + }; + } const button = await page .getByRole('button') .first() .textContent({timeout: buttonTimeoutMs}) .catch(() => null); - return {consoleErrors, pageErrors, failedRequests, button}; + return { + consoleErrors, + pageErrors, + failedRequests, + timedOut: false, + pendingRequests: [], + button, + }; } finally { await browser.close(); } } -/** Whether a render came back with nothing wrong and a button on the page. */ +/** Whether a render went idle with nothing wrong and a button on the page. */ export function isCleanRender(result) { return ( + !result.timedOut && result.consoleErrors.length === 0 && result.pageErrors.length === 0 && result.failedRequests.length === 0 && @@ -74,7 +111,7 @@ export function isCleanRender(result) { * Run `render` until one comes back clean, at most `attempts` times, and * return the last result. `onRetry(attempt)` hears each retry. * - * @template {{consoleErrors: string[], pageErrors: string[], failedRequests: string[], button: string | null}} R + * @template {{timedOut: boolean, consoleErrors: string[], pageErrors: string[], failedRequests: string[], button: string | null}} R * @param {() => Promise} render * @param {{attempts?: number, onRetry?: (attempt: number) => void}} [options] * @returns {Promise} From b98ad868f3d5a38cf9db8a544f52d6ee39974979 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 27 Oct 2026 12:25:24 -0700 Subject: [PATCH 3/6] test(ci): the CDN smoke test's render attempts must fit inside one deadline Each attempt still waits the full 90 s for the network to go idle, so a page that hangs on both attempts takes over 180 s, while the CDN step can start with under two minutes of the smoke-test job's 15-minute limit left: the job is stopped before the report naming the hung request prints. These fail on the current head: - renderUntilClean gives each attempt an equal share of the time left before a deadline, gives the retry what the first attempt left unused, and does not retry once the deadline has passed; - renderPage waits for the navigation no longer than its budget and for the button no longer than what is left of it, and never asks Playwright for a timeout of 0 (no timeout at all); - in Chromium, two attempts at a page that never goes idle finish inside a 4 s deadline, naming the module that hung. --- .../lib/cdn-page-render.browser.test.mjs | 18 ++- .github/scripts/lib/cdn-page-render.test.mjs | 120 +++++++++++++++++- 2 files changed, 130 insertions(+), 8 deletions(-) diff --git a/.github/scripts/lib/cdn-page-render.browser.test.mjs b/.github/scripts/lib/cdn-page-render.browser.test.mjs index 9b987c7dbf112..8aa11b1bd328f 100644 --- a/.github/scripts/lib/cdn-page-render.browser.test.mjs +++ b/.github/scripts/lib/cdn-page-render.browser.test.mjs @@ -14,7 +14,7 @@ import http from 'node:http'; import {chromium} from 'playwright'; import {afterAll, beforeAll, describe, expect, it} from 'vitest'; -import {renderPage} from './cdn-page-render.mjs'; +import {renderPage, renderUntilClean} from './cdn-page-render.mjs'; const PAGE = '' + @@ -61,5 +61,21 @@ describe.runIf(process.env.ASTRYX_CDN_SMOKE_BROWSER === '1')( expect(result.timedOut).toBe(true); expect(result.pendingRequests).toEqual([`${url}stall.js`]); }); + + it('fits both attempts at a page that never goes idle inside one deadline', async () => { + const started = Date.now(); + const result = await renderUntilClean( + (attempt = {}) => + renderPage(url, { + launch: async () => chromium.launch(), + budgetMs: attempt.budgetMs, + }), + {attempts: 2, deadline: Date.now() + 4_000}, + ); + // Two browser launches beside the 4 s the attempts share. + expect(Date.now() - started).toBeLessThan(8_000); + expect(result.timedOut).toBe(true); + expect(result.pendingRequests).toEqual([`${url}stall.js`]); + }, 20_000); }, ); diff --git a/.github/scripts/lib/cdn-page-render.test.mjs b/.github/scripts/lib/cdn-page-render.test.mjs index 1a6094b1359d1..4f5d0765053a1 100644 --- a/.github/scripts/lib/cdn-page-render.test.mjs +++ b/.github/scripts/lib/cdn-page-render.test.mjs @@ -29,26 +29,37 @@ function navigationTimeout() { } /** - * A browser `launch` whose pages run `onGoto(page, launchIndex)` while - * navigating, then settle the navigation with `gotoErrors[launchIndex]` (none - * resolves it) and answer the button query with `button`. + * A browser `launch` whose pages run `onGoto(page, launchIndex, options)` + * while navigating, then settle the navigation with `gotoErrors[launchIndex]` + * (none resolves it), and answer the button query with `button` after running + * `onButton(options)`. */ -function fakeLaunch({onGoto = () => {}, gotoErrors = [], button = 'Start'}) { +function fakeLaunch({ + onGoto = () => {}, + onButton = () => {}, + gotoErrors = [], + button = 'Start', +}) { let launches = 0; let closed = 0; const launch = async () => { const index = launches; launches += 1; const page = new EventEmitter(); - page.goto = async () => { - onGoto(page, index); + page.goto = async (_url, options) => { + onGoto(page, index, options); const error = gotoErrors[index]; if (error != null) { throw error; } }; page.getByRole = () => ({ - first: () => ({textContent: async () => button}), + first: () => ({ + textContent: async options => { + onButton(options); + return button; + }, + }), }); return { newPage: async () => page, @@ -60,6 +71,16 @@ function fakeLaunch({onGoto = () => {}, gotoErrors = [], button = 'Start'}) { return {launch, launches: () => launches, closed: () => closed}; } +/** A render whose navigation timed out with the core module still in flight. */ +const TIMED_OUT = { + consoleErrors: [], + pageErrors: [], + failedRequests: [], + timedOut: true, + pendingRequests: [CORE], + button: null, +}; + describe('renderPage', () => { it('reports a page that goes idle and renders a button as clean', async () => { const {launch, closed} = fakeLaunch({ @@ -117,6 +138,41 @@ describe('renderPage', () => { }); }); +describe('renderPage within a budget', () => { + it('waits for the navigation no longer than its budget, and for the button no longer than what is left of it', async () => { + let clock = 0; + const timeouts = {}; + const {launch} = fakeLaunch({ + onGoto: (_page, _index, options) => { + timeouts.navigation = options.timeout; + clock += 30_000; + }, + onButton: options => { + timeouts.button = options.timeout; + }, + }); + await renderPage(URL, {launch, budgetMs: 40_000, now: () => clock}); + expect(timeouts).toEqual({navigation: 40_000, button: 10_000}); + }); + + it('never asks for a timeout of 0, which Playwright reads as no timeout at all', async () => { + let clock = 0; + const timeouts = {}; + const {launch} = fakeLaunch({ + onGoto: (_page, _index, options) => { + timeouts.navigation = options.timeout; + clock += 5_000; + }, + onButton: options => { + timeouts.button = options.timeout; + }, + }); + await renderPage(URL, {launch, budgetMs: 5_000, now: () => clock}); + expect(timeouts.navigation).toBe(5_000); + expect(timeouts.button).toBeGreaterThan(0); + }); +}); + describe('renderUntilClean', () => { it('retries a navigation timeout once, then reports the requests still in flight', async () => { const {launch, launches} = fakeLaunch({ @@ -134,6 +190,56 @@ describe('renderUntilClean', () => { expect(result.pendingRequests).toEqual([CORE]); }); + it('gives each attempt an equal share of the time left before the deadline', async () => { + let clock = 0; + const budgets = []; + await renderUntilClean( + async ({budgetMs}) => { + budgets.push(budgetMs); + clock += budgetMs; + return TIMED_OUT; + }, + {attempts: 2, deadline: 90_000, now: () => clock}, + ); + expect(budgets).toEqual([45_000, 45_000]); + }); + + it('gives the retry what the first attempt left unused', async () => { + let clock = 0; + const budgets = []; + await renderUntilClean( + async ({budgetMs}) => { + budgets.push(budgetMs); + clock += 10_000; + return {...TIMED_OUT, timedOut: false, failedRequests: [CORE]}; + }, + {attempts: 2, deadline: 90_000, now: () => clock}, + ); + expect(budgets).toEqual([45_000, 80_000]); + }); + + it('does not retry once the deadline has passed, and reports the attempt it has', async () => { + let clock = 0; + let calls = 0; + const retries = []; + const result = await renderUntilClean( + async () => { + calls += 1; + clock += 95_000; + return TIMED_OUT; + }, + { + attempts: 2, + deadline: 90_000, + now: () => clock, + onRetry: attempt => retries.push(attempt), + }, + ); + expect(calls).toBe(1); + expect(retries).toEqual([]); + expect(result).toBe(TIMED_OUT); + }); + it('stops at the first clean render after a timeout', async () => { const {launch, launches} = fakeLaunch({ onGoto: (page, index) => { From 5ba58278f9e780cac3a1bd07eee3a16570165dca Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 27 Oct 2026 12:26:11 -0700 Subject: [PATCH 4/6] fix(ci): the CDN smoke test's render attempts share the one 90 s wait the step always had renderUntilClean takes a deadline and hands each attempt an equal share of the time left (budgetMs), so the retry gets whatever the first attempt left unused, and starts no attempt once the deadline has passed. renderPage fits an attempt in its budget: the navigation waits no longer than the budget and the button no longer than what is left of it, never 0, which Playwright reads as no timeout. The script gives both attempts together the 90 s its one navigation wait always had, so the retry adds no time to the step and a page that hangs on both still prints the report naming the request that hung before the smoke-test job's 15-minute limit stops it; the retry line says how long is left. --- .github/scripts/cdn-template-smoke-test.mjs | 14 ++++- .github/scripts/lib/cdn-page-render.mjs | 63 +++++++++++++++++---- 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/.github/scripts/cdn-template-smoke-test.mjs b/.github/scripts/cdn-template-smoke-test.mjs index 511a8dfef070f..5f6b6120470ef 100644 --- a/.github/scripts/cdn-template-smoke-test.mjs +++ b/.github/scripts/cdn-template-smoke-test.mjs @@ -149,11 +149,21 @@ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve)); const url = `http://127.0.0.1:${server.address().port}/`; // ── 5. Render, retrying once so a blip at a CDN is not a red build ─────────── +// Every attempt shares the one 90 s wait this step has always had, so the retry +// adds no time to it: this step can start with under two minutes of the +// smoke-test job's 15-minute limit left, and a page that hangs on both +// attempts still prints the report naming what hung before the job is stopped. +const RENDER_BUDGET_MS = 90_000; const result = await renderUntilClean( - () => renderPage(url, {launch: () => chromium.launch()}), + ({budgetMs}) => + renderPage(url, {launch: async () => chromium.launch(), budgetMs}), { attempts: ATTEMPTS, - onRetry: attempt => console.log(` retry ${attempt} of ${ATTEMPTS - 1}`), + deadline: Date.now() + RENDER_BUDGET_MS, + onRetry: (attempt, leftMs) => + console.log( + ` retry ${attempt} of ${ATTEMPTS - 1}, ${Math.round(leftMs / 1000)} s left`, + ), }, ); server.close(); diff --git a/.github/scripts/lib/cdn-page-render.mjs b/.github/scripts/lib/cdn-page-render.mjs index a44e3dd56577a..bd25d6432ce9a 100644 --- a/.github/scripts/lib/cdn-page-render.mjs +++ b/.github/scripts/lib/cdn-page-render.mjs @@ -10,7 +10,9 @@ * out: that is an unclean render like any other, reported with the requests * still in flight when the wait gave up, so the output names the asset that * hung instead of ending the run on a stack trace. renderUntilClean retries - * an unclean render once, so a blip at a CDN is not a red build. + * an unclean render once, so a blip at a CDN is not a red build, and fits + * every attempt inside one deadline, so a page that hangs on each attempt + * still gets its report printed before the job running it is stopped. */ /** Playwright's error for a navigation whose wait condition never came. */ @@ -23,19 +25,38 @@ function isTimeout(error) { * page errors and failed requests, and the first button's text (null when no * button rendered). A navigation that times out comes back with `timedOut` * and the URLs still in flight (`pendingRequests`, in request order); any - * other navigation error throws. + * other navigation error throws. With `budgetMs`, the whole attempt fits in + * it: the navigation waits no longer than the budget, and the button no + * longer than what is left of it. * * @param {string} url * @param {{ * launch: () => Promise, * navigationTimeoutMs?: number, * buttonTimeoutMs?: number, + * budgetMs?: number, + * now?: () => number, * }} options */ export async function renderPage( url, - {launch, navigationTimeoutMs = 90_000, buttonTimeoutMs = 15_000}, + { + launch, + navigationTimeoutMs = 90_000, + buttonTimeoutMs = 15_000, + budgetMs, + now = Date.now, + }, ) { + const startedAt = now(); + /** + * `limitMs`, cut to what is left of the budget. Never 0: Playwright reads a + * timeout of 0 as no timeout at all. + */ + const withinBudget = limitMs => + budgetMs == null + ? limitMs + : Math.max(1, Math.min(limitMs, budgetMs - (now() - startedAt))); const consoleErrors = []; const pageErrors = []; const failedRequests = []; @@ -62,7 +83,7 @@ export async function renderPage( try { await page.goto(url, { waitUntil: 'networkidle', - timeout: navigationTimeoutMs, + timeout: withinBudget(navigationTimeoutMs), }); } catch (error) { if (!isTimeout(error)) { @@ -80,7 +101,7 @@ export async function renderPage( const button = await page .getByRole('button') .first() - .textContent({timeout: buttonTimeoutMs}) + .textContent({timeout: withinBudget(buttonTimeoutMs)}) .catch(() => null); return { @@ -109,19 +130,37 @@ export function isCleanRender(result) { /** * Run `render` until one comes back clean, at most `attempts` times, and - * return the last result. `onRetry(attempt)` hears each retry. + * return the last result. With a `deadline` (in `now()`'s clock), each attempt + * is handed `budgetMs`, an equal share of the time left (so the retry gets + * whatever the first attempt left unused), and no attempt starts once the + * deadline has passed. `onRetry(attempt, leftMs)` hears each retry. * * @template {{timedOut: boolean, consoleErrors: string[], pageErrors: string[], failedRequests: string[], button: string | null}} R - * @param {() => Promise} render - * @param {{attempts?: number, onRetry?: (attempt: number) => void}} [options] + * @param {(attempt: {budgetMs?: number}) => Promise} render + * @param {{ + * attempts?: number, + * deadline?: number, + * now?: () => number, + * onRetry?: (attempt: number, leftMs?: number) => void, + * }} [options] * @returns {Promise} */ -export async function renderUntilClean(render, {attempts = 2, onRetry} = {}) { +export async function renderUntilClean( + render, + {attempts = 2, deadline, now = Date.now, onRetry} = {}, +) { + const leftMs = () => (deadline == null ? undefined : deadline - now()); let result; for (let attempt = 1; attempt <= attempts; attempt++) { - result = await render(); - if (isCleanRender(result)) break; - if (attempt < attempts) onRetry?.(attempt); + const left = leftMs(); + result = await render({ + budgetMs: + left == null ? undefined : Math.floor(left / (attempts - attempt + 1)), + }); + if (isCleanRender(result) || attempt === attempts) break; + const remaining = leftMs(); + if (remaining != null && remaining <= 0) break; + onRetry?.(attempt, remaining); } return result; } From 6d8ae991debb069e68fe85db2e8d9c9248e5d6bc Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 27 Oct 2026 13:07:56 -0700 Subject: [PATCH 5/6] test(ci): the CDN smoke test hides no error: not a crashed button read, not a retried attempt Two places still turn an error into silence, and these fail on the current head: - renderPage reads the first button with .catch(() => null), the line moved unchanged from the script, so a crashed page or a closed target reads as 'rendered no button'. Only a wait that runs out means no button; any other error must throw. - renderUntilClean discards an unclean attempt when it retries, so a CDN request that hung or failed and then served on the retry leaves nothing in the log but 'retry 1 of 1'. onRetry must be handed the discarded attempt, and uncleanFindings must name everything that made a render unclean, so the script can print it. Reading no button within the wait still reports a missing button. --- .github/scripts/lib/cdn-page-render.test.mjs | 86 ++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/.github/scripts/lib/cdn-page-render.test.mjs b/.github/scripts/lib/cdn-page-render.test.mjs index 4f5d0765053a1..f67e7091efff1 100644 --- a/.github/scripts/lib/cdn-page-render.test.mjs +++ b/.github/scripts/lib/cdn-page-render.test.mjs @@ -6,6 +6,7 @@ import { isCleanRender, renderPage, renderUntilClean, + uncleanFindings, } from './cdn-page-render.mjs'; const URL = 'http://127.0.0.1:1/'; @@ -39,6 +40,7 @@ function fakeLaunch({ onButton = () => {}, gotoErrors = [], button = 'Start', + buttonError = null, }) { let launches = 0; let closed = 0; @@ -57,6 +59,9 @@ function fakeLaunch({ first: () => ({ textContent: async options => { onButton(options); + if (buttonError != null) { + throw buttonError; + } return button; }, }), @@ -138,6 +143,63 @@ describe('renderPage', () => { }); }); +describe('renderPage reading the button', () => { + it('reports no button when none appears within the wait: the page rendered nothing to press', async () => { + const timeout = navigationTimeout(); + const {launch} = fakeLaunch({buttonError: timeout}); + const result = await renderPage(URL, {launch}); + expect(result.button).toBeNull(); + expect(isCleanRender(result)).toBe(false); + }); + + it('throws any other error from reading the button, rather than reporting it as a missing button', async () => { + const crashed = new Error('locator.textContent: Target crashed'); + const {launch, closed} = fakeLaunch({buttonError: crashed}); + await expect(renderPage(URL, {launch})).rejects.toBe(crashed); + expect(closed()).toBe(1); + }); +}); + +describe('uncleanFindings', () => { + it('names everything that made a render unclean', () => { + expect( + uncleanFindings({ + consoleErrors: ['Uncaught TypeError: x is not a function'], + pageErrors: ['Error: boom'], + failedRequests: [`${CSS} :: net::ERR_BLOCKED_BY_ORB`], + timedOut: false, + pendingRequests: [], + button: null, + }), + ).toEqual([ + 'console error: Uncaught TypeError: x is not a function', + 'page error: Error: boom', + `failed request: ${CSS} :: net::ERR_BLOCKED_BY_ORB`, + 'rendered no button', + ]); + }); + + it('names a timeout with each request still in flight, and no missing button for a page that never finished', () => { + expect(uncleanFindings(TIMED_OUT)).toEqual([ + 'navigation timed out', + `still in flight: ${CORE}`, + ]); + }); + + it('has nothing to say about a clean render', () => { + expect( + uncleanFindings({ + consoleErrors: [], + pageErrors: [], + failedRequests: [], + timedOut: false, + pendingRequests: [], + button: 'Start', + }), + ).toEqual([]); + }); +}); + describe('renderPage within a budget', () => { it('waits for the navigation no longer than its budget, and for the button no longer than what is left of it', async () => { let clock = 0; @@ -190,6 +252,30 @@ describe('renderUntilClean', () => { expect(result.pendingRequests).toEqual([CORE]); }); + it('hands each retry the attempt it discards, so what went wrong on it can be reported', async () => { + const heard = []; + let calls = 0; + const clean = { + ...TIMED_OUT, + timedOut: false, + pendingRequests: [], + button: 'Start', + }; + const result = await renderUntilClean( + async () => { + calls += 1; + return calls === 1 ? TIMED_OUT : clean; + }, + { + attempts: 2, + onRetry: (attempt, _leftMs, discarded) => + heard.push([attempt, discarded]), + }, + ); + expect(heard).toEqual([[1, TIMED_OUT]]); + expect(result).toBe(clean); + }); + it('gives each attempt an equal share of the time left before the deadline', async () => { let clock = 0; const budgets = []; From 05c04a078fa28b3ee5c134818abf710ba52a145c Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 27 Oct 2026 13:10:19 -0700 Subject: [PATCH 6/6] fix(ci): the CDN smoke test hides no error: a crashed button read throws, a retried attempt is printed renderPage turns only a wait that runs out into 'no button'; any other error from reading the button (a crashed page, a closed target) throws, as a navigation error that is not a timeout already did. renderUntilClean hands onRetry the unclean attempt it discards, and uncleanFindings names everything that made a render unclean (the timeout and each request still in flight, console and page errors, failed requests, a missing button). The script prints those findings under the retry line, so a CDN request that hung or failed and then served on the retry shows in the log instead of vanishing behind a green run. The pass and fail rules are unchanged. --- .github/scripts/cdn-template-smoke-test.mjs | 19 ++++++-- .github/scripts/lib/cdn-page-render.mjs | 48 +++++++++++++++++---- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/.github/scripts/cdn-template-smoke-test.mjs b/.github/scripts/cdn-template-smoke-test.mjs index 5f6b6120470ef..4a901bfc4c689 100644 --- a/.github/scripts/cdn-template-smoke-test.mjs +++ b/.github/scripts/cdn-template-smoke-test.mjs @@ -30,7 +30,11 @@ import * as os from 'node:os'; import * as path from 'node:path'; import {fileURLToPath} from 'node:url'; import {pageAssetUrls, primeCdnAssets} from './lib/cdn-asset-priming.mjs'; -import {renderPage, renderUntilClean} from './lib/cdn-page-render.mjs'; +import { + renderPage, + renderUntilClean, + uncleanFindings, +} from './lib/cdn-page-render.mjs'; import {resolvePublishedCdnVersion} from './lib/cdn-version.mjs'; const ROOT = path.resolve( @@ -160,10 +164,17 @@ const result = await renderUntilClean( { attempts: ATTEMPTS, deadline: Date.now() + RENDER_BUDGET_MS, - onRetry: (attempt, leftMs) => + // The attempt a retry replaces is printed in full: a CDN blip that clears + // on the retry still shows in the log, rather than vanishing behind a + // green run. + onRetry: (attempt, leftMs, discarded) => { console.log( - ` retry ${attempt} of ${ATTEMPTS - 1}, ${Math.round(leftMs / 1000)} s left`, - ), + ` retry ${attempt} of ${ATTEMPTS - 1}, ${Math.round(leftMs / 1000)} s left, after:`, + ); + for (const finding of uncleanFindings(discarded)) { + console.log(` ${finding}`); + } + }, }, ); server.close(); diff --git a/.github/scripts/lib/cdn-page-render.mjs b/.github/scripts/lib/cdn-page-render.mjs index bd25d6432ce9a..186173d479123 100644 --- a/.github/scripts/lib/cdn-page-render.mjs +++ b/.github/scripts/lib/cdn-page-render.mjs @@ -12,7 +12,11 @@ * hung instead of ending the run on a stack trace. renderUntilClean retries * an unclean render once, so a blip at a CDN is not a red build, and fits * every attempt inside one deadline, so a page that hangs on each attempt - * still gets its report printed before the job running it is stopped. + * still gets its report printed before the job running it is stopped. It + * hands every retry the attempt it discards, and uncleanFindings names what + * made that attempt unclean, so a blip that clears on the retry still shows + * in the log. Only an expected absence (a wait that ran out) becomes a value; + * every other error throws. */ /** Playwright's error for a navigation whose wait condition never came. */ @@ -98,11 +102,19 @@ export async function renderPage( button: null, }; } - const button = await page - .getByRole('button') - .first() - .textContent({timeout: withinBudget(buttonTimeoutMs)}) - .catch(() => null); + let button; + try { + button = await page + .getByRole('button') + .first() + .textContent({timeout: withinBudget(buttonTimeoutMs)}); + } catch (error) { + if (!isTimeout(error)) { + throw error; + } + // No button within the wait: the page rendered nothing to press. + button = null; + } return { consoleErrors, @@ -117,6 +129,23 @@ export async function renderPage( } } +/** + * Everything that made `result` unclean, one line each: the timeout and the + * requests still in flight, each console error, page error and failed + * request, and a missing button on a page that finished loading. Empty for a + * clean render. + */ +export function uncleanFindings(result) { + return [ + ...(result.timedOut ? ['navigation timed out'] : []), + ...result.pendingRequests.map(url => `still in flight: ${url}`), + ...result.consoleErrors.map(entry => `console error: ${entry}`), + ...result.pageErrors.map(entry => `page error: ${entry}`), + ...result.failedRequests.map(entry => `failed request: ${entry}`), + ...(!result.timedOut && !result.button ? ['rendered no button'] : []), + ]; +} + /** Whether a render went idle with nothing wrong and a button on the page. */ export function isCleanRender(result) { return ( @@ -133,7 +162,8 @@ export function isCleanRender(result) { * return the last result. With a `deadline` (in `now()`'s clock), each attempt * is handed `budgetMs`, an equal share of the time left (so the retry gets * whatever the first attempt left unused), and no attempt starts once the - * deadline has passed. `onRetry(attempt, leftMs)` hears each retry. + * deadline has passed. `onRetry(attempt, leftMs, discarded)` hears each + * retry, with the unclean attempt it replaces. * * @template {{timedOut: boolean, consoleErrors: string[], pageErrors: string[], failedRequests: string[], button: string | null}} R * @param {(attempt: {budgetMs?: number}) => Promise} render @@ -141,7 +171,7 @@ export function isCleanRender(result) { * attempts?: number, * deadline?: number, * now?: () => number, - * onRetry?: (attempt: number, leftMs?: number) => void, + * onRetry?: (attempt: number, leftMs: number | undefined, discarded: R) => void, * }} [options] * @returns {Promise} */ @@ -160,7 +190,7 @@ export async function renderUntilClean( if (isCleanRender(result) || attempt === attempts) break; const remaining = leftMs(); if (remaining != null && remaining <= 0) break; - onRetry?.(attempt, remaining); + onRetry?.(attempt, remaining, result); } return result; }