Skip to content

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

TypeScript

ci: the PR report stays under GitHub's comment limit, cutting at a line and saying what did not fit (#9260)

Cindy Zhangb25d656ca591
diff --git a/.github/scripts/generate-pr-comment.js b/.github/scripts/generate-pr-comment.js
index 314271a410..41ef46827d 100644
--- a/.github/scripts/generate-pr-comment.js
+++ b/.github/scripts/generate-pr-comment.js
@@ -15,11 +15,11 @@
const fs = require('node:fs');
const {buildA11ySection} = require('./lib/a11y-format');
-const {buildCompactReport} = require('./lib/pr-status');
+const {buildCompactReport, notRunLine} = require('./lib/pr-status');
const {renderCiImpact} = require('./lib/ci-impact');
// Report-file strings render as literal inline text, report numbers as
// numbers — the comment's structure comes only from this file's literals.
-const {inline, num} = require('./lib/report-text');
+const {COMMENT_BUDGET, fitToBudget, inline, num} = require('./lib/report-text');
const args = process.argv.slice(2);
const getArg = name => {
@@ -136,17 +136,37 @@ const report = buildCompactReport({
packageSize,
visualFrames,
apiChanges,
+ withNotRun: false,
});
+const notRun = notRunLine({jobs, a11yReport, visualVerdict, touched});
const footerLinksStr = runUrl
? ` | ${extLink('View full report', runUrl)}`
: '';
-const body = `## PR Analysis Report
+const header = `## PR Analysis Report
<!-- astryx-pr-analysis -->
-${report || '_No component or package changed._\n\n'}${renderCiImpact(ciImpact)}${conclusionNote}${diffModeCaveat}${visualFailed}${a11yDetails}---
+`;
+const footer = `---
<sub>Generated by PR Enrichment workflow${footerLinksStr}</sub>
`;
+// The whole comment stays under GitHub's limit (report-text.js). The header,
+// the footer and the short status lines are never cut; the long sections
+// are, from their end, so the API rows (last in the report) go first.
+const status = `${notRun}${renderCiImpact(ciImpact)}${conclusionNote}${diffModeCaveat}${visualFailed}`;
+const room = COMMENT_BUDGET - header.length - footer.length - status.length;
+// The report used to end with the not-run line; the placeholder stands in
+// only when neither shows, as before.
+const mainText =
+ report || (notRun ? '' : '_No component or package changed._\n\n');
+// The accessibility details keep everything the report leaves room for, and
+// at least half of the room when the report is long.
+const a11yFitted = fitToBudget(
+ a11yDetails,
+ Math.max(Math.floor(room / 2), room - mainText.length),
+);
+const main = fitToBudget(mainText, room - a11yFitted.length);
+const body = `${header}${main}${status}${a11yFitted}${footer}`;
console.log(body);
diff --git a/.github/scripts/generate-pr-comment.test.mjs b/.github/scripts/generate-pr-comment.test.mjs
index eae54940b8..abe2c235dc 100644
--- a/.github/scripts/generate-pr-comment.test.mjs
+++ b/.github/scripts/generate-pr-comment.test.mjs
@@ -194,3 +194,95 @@ describe('generate-pr-comment compact report', () => {
expect(out).not.toContain('<img src=x>');
});
});
+
+describe('comment length budget', () => {
+ it('leaves a report that already fits byte-identical, accessibility details included', () => {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-budget-a11y-'));
+ try {
+ const file = path.join(dir, 'a11y.json');
+ const components = Object.fromEntries(
+ Array.from({length: 100}, (_, i) => [
+ `Part${i}`,
+ {
+ violations: [
+ {
+ id: `rule-${i}`,
+ impact: 'serious',
+ description: 'x'.repeat(320),
+ },
+ ],
+ },
+ ]),
+ );
+ fs.writeFileSync(file, JSON.stringify({components}));
+ const out = runComment(baseAnalysis, ['--a11y', file]);
+ expect(out).toContain('rule-99');
+ expect(out).not.toMatch(/did not fit/);
+ } finally {
+ fs.rmSync(dir, {recursive: true, force: true});
+ }
+ });
+
+ it("keeps a report with 150 long API rows under GitHub's comment limit", () => {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-budget-'));
+ try {
+ const rows = Array.from({length: 150}, (_, i) => ({
+ change: 'added',
+ entry: '.',
+ section: 'Types',
+ item: `type Wide${i}`,
+ member: null,
+ line: `type Wide${i} = ${"'a' | ".repeat(150)}'z'`,
+ usage: `import type {Wide${i}} from '@astryxdesign/core'`,
+ }));
+ const apiChanges = path.join(dir, 'api-changes.json');
+ fs.writeFileSync(
+ apiChanges,
+ JSON.stringify({
+ version: 1,
+ packages: [
+ {
+ pkg: '@astryxdesign/core',
+ baseline: false,
+ stale: false,
+ missing: false,
+ counts: {added: 150, changed: 0, removed: 0},
+ rows,
+ },
+ ],
+ }),
+ );
+ const visual = path.join(dir, 'verdict.json');
+ fs.writeFileSync(
+ visual,
+ JSON.stringify({
+ status: 'failed',
+ counts: {total: 3, failed: 3},
+ failures: [],
+ }),
+ );
+ const out = runComment({...baseAnalysis, diffMode: 'two-dot'}, [
+ '--api-changes',
+ apiChanges,
+ '--source-conclusion',
+ 'failure',
+ '--visual',
+ visual,
+ ]);
+ expect(out.length).toBeLessThan(60_500);
+ // The short status lines survive; the API rows are what gets cut.
+ expect(out).toMatch(/CI concluded failure/);
+ expect(out).toMatch(/Approximate analysis/);
+ expect(out).toMatch(/could not be captured/);
+ expect(out).toMatch(/Not run on this PR/);
+ expect(out).toMatch(/more lines did not fit GitHub's comment limit/);
+ expect((out.match(/<details/g) || []).length).toBe(
+ (out.match(/<\/details>/g) || []).length,
+ );
+ expect(out).toContain('<sub>Generated by PR Enrichment workflow');
+ expect(out.startsWith('## PR Analysis Report')).toBe(true);
+ } finally {
+ fs.rmSync(dir, {recursive: true, force: true});
+ }
+ });
+});
diff --git a/.github/scripts/lib/pr-status.js b/.github/scripts/lib/pr-status.js
index 26cc559ccc..e59a366dd8 100644
--- a/.github/scripts/lib/pr-status.js
+++ b/.github/scripts/lib/pr-status.js
@@ -541,6 +541,8 @@ function buildCompactReport({
packageSize = null,
apiChanges = null,
visualFrames = null,
+ // The generator places the not-run line itself, outside the length budget.
+ withNotRun = true,
}) {
const origin =
preview?.state === 'ready' ? preview.url : preview?.aliasOrigin || '';
@@ -550,7 +552,7 @@ function buildCompactReport({
touched,
a11yReport,
visualVerdict,
- })}${buildVisualDeltas({verdict: visualVerdict, frames: visualFrames})}${packagesLine(packageSize)}${apiChangesLine(apiChanges)}${notRunLine({jobs, a11yReport, visualVerdict, touched})}`;
+ })}${buildVisualDeltas({verdict: visualVerdict, frames: visualFrames})}${packagesLine(packageSize)}${apiChangesLine(apiChanges)}${withNotRun ? notRunLine({jobs, a11yReport, visualVerdict, touched}) : ''}`;
}
module.exports = {
diff --git a/.github/scripts/lib/report-text.js b/.github/scripts/lib/report-text.js
index 9623fe830b..70eb5ebae0 100644
--- a/.github/scripts/lib/report-text.js
+++ b/.github/scripts/lib/report-text.js
@@ -50,4 +50,54 @@ function sizeText(bytes) {
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
}
-module.exports = {inline, num, safeUrl, sizeText};
+/**
+ * GitHub refuses a comment over 65,536 characters, and the PR report then
+ * posts nothing at all. The report stays under this budget, leaving room for
+ * the markers and footer added around it.
+ */
+const COMMENT_BUDGET = 60000;
+
+/**
+ * Markdown cut at a line boundary to fit `budget` characters: it closes any
+ * disclosure left open, ends a table it cut, and says how many lines did not
+ * fit. Markdown within the budget is returned unchanged.
+ */
+function fitToBudget(markdown, budget) {
+ const text = String(markdown ?? '');
+ if (text.length <= budget) return text;
+ const lines = text.split('\n');
+ // Room for the closing tags and the note.
+ const reserve = 400;
+ const kept = [];
+ let size = 0;
+ for (const line of lines) {
+ if (size + line.length + 1 > budget - reserve) break;
+ kept.push(line);
+ size += line.length + 1;
+ }
+ // A cut inside a disclosure nested in another (one component's issues in
+ // the accessibility section) backs up to before that nested disclosure, so
+ // the note shows in the outer section rather than hidden in a component.
+ const opened = [];
+ kept.forEach((line, index) => {
+ const opens = (line.match(/<details[\s>]/g) || []).length;
+ const closes = (line.match(/<\/details>/g) || []).length;
+ for (let i = 0; i < opens; i++) opened.push(index);
+ for (let i = 0; i < closes; i++) opened.pop();
+ });
+ while (opened.length > 1) kept.length = opened.pop();
+ const omitted = lines
+ .slice(kept.length)
+ .filter(line => line.trim() !== '').length;
+ const keptText = kept.join('\n');
+ const open = opened.length;
+ const tail = [
+ '',
+ `_${num(omitted).toLocaleString('en-US')} more line${omitted === 1 ? '' : 's'} did not fit GitHub's comment limit; the run's full report has them._`,
+ '',
+ ...Array.from({length: Math.max(0, open)}, () => '</details>\n'),
+ ];
+ return `${keptText}\n${tail.join('\n')}\n`;
+}
+
+module.exports = {COMMENT_BUDGET, fitToBudget, inline, num, safeUrl, sizeText};
diff --git a/.github/scripts/lib/report-text.test.mjs b/.github/scripts/lib/report-text.test.mjs
index 9f8c93bb95..54001a2d9d 100644
--- a/.github/scripts/lib/report-text.test.mjs
+++ b/.github/scripts/lib/report-text.test.mjs
@@ -3,7 +3,9 @@
import {describe, expect, it} from 'vitest';
import {createRequire} from 'node:module';
-const {inline, num, safeUrl} = createRequire(import.meta.url)('./report-text.js');
+const {inline, num, safeUrl} = createRequire(import.meta.url)(
+ './report-text.js',
+);
describe('inline', () => {
it('passes ordinary values through', () => {
@@ -51,7 +53,9 @@ describe('safeUrl', () => {
expect(safeUrl('https://dequeuniversity.com/rules/axe/4.10/list')).toBe(
'https://dequeuniversity.com/rules/axe/4.10/list',
);
- expect(safeUrl(' https://example.com/a?b=c#d ')).toBe('https://example.com/a?b=c#d');
+ expect(safeUrl(' https://example.com/a?b=c#d ')).toBe(
+ 'https://example.com/a?b=c#d',
+ );
});
it('rejects anything that is not one', () => {
@@ -64,3 +68,44 @@ describe('safeUrl', () => {
expect(safeUrl(null)).toBeNull();
});
});
+
+describe('fitToBudget', () => {
+ const {fitToBudget: fit} = createRequire(import.meta.url)('./report-text.js');
+
+ it('returns markdown within the budget unchanged', () => {
+ expect(fit('a\nb\n', 100)).toBe('a\nb\n');
+ });
+
+ it('cuts at a line, closes an open disclosure, ends a table, and counts what did not fit', () => {
+ const rows = Array.from(
+ {length: 40},
+ (_, i) => `| row ${i} | ${'x'.repeat(40)} |`,
+ );
+ const markdown = `Intro\n\n<details>\n<summary>Rows</summary>\n\n| A | B |\n|---|---|\n${rows.join('\n')}\n\n</details>\n`;
+ const out = fit(markdown, 1000);
+ expect(out.length).toBeLessThanOrEqual(1000);
+ expect(out).toMatch(
+ /\| row \d+ \| x+ \|\n\n_\d+ more lines did not fit GitHub's comment limit; the run's full report has them._\n\n<\/details>\n/,
+ );
+ expect((out.match(/<details/g) || []).length).toBe(
+ (out.match(/<\/details>/g) || []).length,
+ );
+ });
+
+ it('backs a cut inside a nested disclosure up to before it, so the note shows in the outer section', () => {
+ const parts = Array.from(
+ {length: 30},
+ (_, i) =>
+ `<details>\n<summary>Part${i} - 1 issue(s)</summary>\n\n${'issue text '.repeat(6)}\n\n</details>\n`,
+ );
+ const markdown = `<details>\n<summary>Accessibility</summary>\n\n${parts.join('\n')}\n</details>\n`;
+ const out = fit(markdown, 1500);
+ expect(out.length).toBeLessThanOrEqual(1500);
+ // The note follows a closed component, at the outer level.
+ expect(out).toMatch(/<\/details>\n+_\d+ more lines did not fit/);
+ expect(out.trimEnd().endsWith('</details>')).toBe(true);
+ expect((out.match(/<details/g) || []).length).toBe(
+ (out.match(/<\/details>/g) || []).length,
+ );
+ });
+});