Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci(cli-smoke): report a CDN's own server error as a labelled soft failure (#9052)

Cindy Zhang925c8e576463
diff --git a/.github/scripts/cdn-template-smoke-test.mjs b/.github/scripts/cdn-template-smoke-test.mjs
index 4a901bfc4c..e00d417413 100644
--- a/.github/scripts/cdn-template-smoke-test.mjs
+++ b/.github/scripts/cdn-template-smoke-test.mjs
@@ -18,7 +18,8 @@
* Usage:
* node .github/scripts/cdn-template-smoke-test.mjs
*
- * Exit code 0 = the page rendered clean
+ * Exit code 0 = the page rendered clean, or the only failure was a CDN's own
+ * server error on every attempt (reported as a soft failure)
* Exit code 1 = it did not
*/
@@ -31,6 +32,7 @@ import * as path from 'node:path';
import {fileURLToPath} from 'node:url';
import {pageAssetUrls, primeCdnAssets} from './lib/cdn-asset-priming.mjs';
import {
+ cdnOutageUrlsAcross,
renderPage,
renderUntilClean,
uncleanFindings,
@@ -158,6 +160,8 @@ const url = `http://127.0.0.1:${server.address().port}/`;
// 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;
+/** Each unclean attempt a retry replaced, for the outage check below. */
+const discardedAttempts = [];
const result = await renderUntilClean(
({budgetMs}) =>
renderPage(url, {launch: async () => chromium.launch(), budgetMs}),
@@ -168,6 +172,7 @@ const result = await renderUntilClean(
// on the retry still shows in the log, rather than vanishing behind a
// green run.
onRetry: (attempt, leftMs, discarded) => {
+ discardedAttempts.push(discarded);
console.log(
` retry ${attempt} of ${ATTEMPTS - 1}, ${Math.round(leftMs / 1000)} s left, after:`,
);
@@ -212,7 +217,24 @@ if (result.button) {
}
fs.rmSync(tmpDir, {recursive: true, force: true});
-if (process.exitCode) {
+// A CDN failing on its own side (a 5xx or 408 on both attempts) breaks every
+// page that loads from it, but no change in this repository caused it or can
+// fix it. Report it loudly as a soft failure instead of a red build; a 404, a
+// page error or anything at another host still fails.
+const outageUrls = process.exitCode
+ ? cdnOutageUrlsAcross([...discardedAttempts, result])
+ : [];
+if (outageUrls.length > 0) {
+ console.log(
+ `\nSOFT FAILURE: external CDN outage, not a regression in this change.\n${outageUrls
+ .map(entry => ` ${entry}`)
+ .join('\n')}`,
+ );
+ console.log(
+ `::warning title=CDN outage (soft failure)::The CDN starter page could not load ${outageUrls.join(', ')} (server error on every attempt). The page is broken for users until the CDN recovers; this run does not fail for it.`,
+ );
+ process.exitCode = 0;
+} else if (process.exitCode) {
console.log('\nCDN starter page is broken.');
} else {
console.log('\nCDN starter page renders clean.');
diff --git a/.github/scripts/lib/cdn-page-render.mjs b/.github/scripts/lib/cdn-page-render.mjs
index 186173d479..dc668d1a1b 100644
--- a/.github/scripts/lib/cdn-page-render.mjs
+++ b/.github/scripts/lib/cdn-page-render.mjs
@@ -146,6 +146,76 @@ export function uncleanFindings(result) {
];
}
+/** Third-party CDNs the starter page loads from. */
+export const CDN_HOSTS = ['esm.sh', 'cdn.jsdelivr.net'];
+
+/** A server-side failure: the CDN itself broke, not the URL the page asked for. */
+const OUTAGE_STATUS = /^(5\d\d|408) (\S+)$/;
+const OUTAGE_CONSOLE =
+ /^Failed to load resource: the server responded with a status of (5\d\d|408)\b/;
+
+/**
+ * The CDN URLs behind an unclean render when the only thing wrong is a CDN
+ * failing on its own side: every failed request is a 5xx or 408 from a host
+ * in `CDN_HOSTS` (or the browser aborting one of those same URLs), every
+ * console error is the browser reporting such a response, and nothing threw on
+ * the page. Empty when anything else went wrong — a 404 (a missing release or
+ * file), a page error, a timeout, a failure at any other host — because those
+ * are the regressions this smoke test exists to catch.
+ */
+export function cdnOutageUrls(result, hosts = CDN_HOSTS) {
+ if (
+ result.timedOut ||
+ result.pageErrors.length > 0 ||
+ result.failedRequests.length === 0
+ ) {
+ return [];
+ }
+ const isCdn = url => {
+ try {
+ return hosts.includes(new URL(url).hostname);
+ } catch {
+ return false;
+ }
+ };
+ const outageUrls = new Set();
+ for (const entry of result.failedRequests) {
+ const match = OUTAGE_STATUS.exec(entry);
+ if (match && isCdn(match[2])) {
+ outageUrls.add(match[2]);
+ }
+ }
+ if (outageUrls.size === 0) {
+ return [];
+ }
+ const explained = result.failedRequests.every(entry => {
+ const match = OUTAGE_STATUS.exec(entry);
+ if (match) {
+ return outageUrls.has(match[2]);
+ }
+ const [url, reason] = entry.split(' :: ');
+ return outageUrls.has(url) && reason === 'net::ERR_ABORTED';
+ });
+ const consoleExplained = result.consoleErrors.every(entry =>
+ OUTAGE_CONSOLE.test(entry),
+ );
+ return explained && consoleExplained ? [...outageUrls] : [];
+}
+
+/**
+ * The CDN URLs behind a run of render attempts when every attempt failed only
+ * because a CDN broke on its own side (see `cdnOutageUrls`). Empty when any
+ * attempt failed for another reason, so a regression on one attempt is never
+ * excused by a CDN error on another.
+ */
+export function cdnOutageUrlsAcross(results, hosts = CDN_HOSTS) {
+ const perAttempt = results.map(result => cdnOutageUrls(result, hosts));
+ if (perAttempt.length === 0 || perAttempt.some(urls => urls.length === 0)) {
+ return [];
+ }
+ return [...new Set(perAttempt.flat())];
+}
+
/** Whether a render went idle with nothing wrong and a button on the page. */
export function isCleanRender(result) {
return (
diff --git a/.github/scripts/lib/cdn-page-render.test.mjs b/.github/scripts/lib/cdn-page-render.test.mjs
index f67e7091ef..e4ce44258a 100644
--- a/.github/scripts/lib/cdn-page-render.test.mjs
+++ b/.github/scripts/lib/cdn-page-render.test.mjs
@@ -3,6 +3,8 @@
import {EventEmitter} from 'node:events';
import {describe, expect, it} from 'vitest';
import {
+ cdnOutageUrls,
+ cdnOutageUrlsAcross,
isCleanRender,
renderPage,
renderUntilClean,
@@ -344,3 +346,116 @@ describe('renderUntilClean', () => {
expect(isCleanRender(result)).toBe(true);
});
});
+
+describe('cdnOutageUrls', () => {
+ const LUCIDE =
+ 'https://esm.sh/lucide-react@%5E1.18.0?external=react&target=es2022';
+ const outage = {
+ timedOut: false,
+ pendingRequests: [],
+ consoleErrors: [
+ 'Failed to load resource: the server responded with a status of 500 ()',
+ ],
+ pageErrors: [],
+ failedRequests: [`500 ${LUCIDE}`, `${LUCIDE} :: net::ERR_ABORTED`],
+ button: null,
+ };
+
+ it('names the CDN URL when a CDN server error is the only thing wrong', () => {
+ expect(cdnOutageUrls(outage)).toEqual([LUCIDE]);
+ });
+
+ it('counts a 408 from a CDN as an outage too', () => {
+ expect(
+ cdnOutageUrls({
+ ...outage,
+ consoleErrors: [
+ 'Failed to load resource: the server responded with a status of 408 ()',
+ ],
+ failedRequests: [`408 ${CORE}`],
+ }),
+ ).toEqual([CORE]);
+ });
+
+ it('is empty for a 404: a missing release or file is a regression to catch', () => {
+ expect(
+ cdnOutageUrls({
+ ...outage,
+ consoleErrors: [
+ 'Failed to load resource: the server responded with a status of 404 ()',
+ ],
+ failedRequests: [`404 ${CSS}`],
+ }),
+ ).toEqual([]);
+ });
+
+ it('is empty when the page threw, even beside a CDN server error', () => {
+ expect(
+ cdnOutageUrls({...outage, pageErrors: ['SyntaxError: bad export']}),
+ ).toEqual([]);
+ });
+
+ it('is empty when any other console error appears', () => {
+ expect(
+ cdnOutageUrls({
+ ...outage,
+ consoleErrors: [...outage.consoleErrors, 'Invalid hook call'],
+ }),
+ ).toEqual([]);
+ });
+
+ it('is empty for a server error at a host that is not a known CDN', () => {
+ const other = 'https://example.com/x.js';
+ expect(
+ cdnOutageUrls({
+ ...outage,
+ failedRequests: [`500 ${other}`, `${other} :: net::ERR_ABORTED`],
+ }),
+ ).toEqual([]);
+ });
+
+ it('is empty for a timeout or a clean render', () => {
+ expect(cdnOutageUrls({...outage, timedOut: true})).toEqual([]);
+ expect(
+ cdnOutageUrls({
+ ...outage,
+ consoleErrors: [],
+ failedRequests: [],
+ button: 'Click',
+ }),
+ ).toEqual([]);
+ });
+});
+
+describe('cdnOutageUrlsAcross', () => {
+ const LUCIDE =
+ 'https://esm.sh/[email protected]?external=react&target=es2022';
+ const outage = {
+ timedOut: false,
+ pendingRequests: [],
+ consoleErrors: [
+ 'Failed to load resource: the server responded with a status of 500 ()',
+ ],
+ pageErrors: [],
+ failedRequests: [`500 ${LUCIDE}`],
+ button: null,
+ };
+ const regression = {
+ ...outage,
+ consoleErrors: [],
+ failedRequests: [],
+ pageErrors: ['SyntaxError: does not provide an export named jsx'],
+ };
+
+ it('names the CDN URLs when every attempt was a CDN outage', () => {
+ expect(cdnOutageUrlsAcross([outage, outage])).toEqual([LUCIDE]);
+ });
+
+ it('is empty when a regression on the first attempt is followed by a CDN error on the retry', () => {
+ expect(cdnOutageUrlsAcross([regression, outage])).toEqual([]);
+ });
+
+ it('is empty with no attempts', () => {
+ expect(cdnOutageUrlsAcross([])).toEqual([]);
+ });
+});