π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
β¨ chore(ci): fold the bundle size gate PR comment into one line when it passes (#20027)
Arvin Xu1389300e4b54
diff --git a/.github/scripts/bundle-size-gate.cjs b/.github/scripts/bundle-size-gate.cjsindex 7ad79a95e1d..64934225f87 100644--- a/.github/scripts/bundle-size-gate.cjs+++ b/.github/scripts/bundle-size-gate.cjs@@ -258,12 +258,35 @@ const humanSize = (bytes) => {const formatDelta = (delta, baseline) => {const sign = delta > 0 ? '+' : delta < 0 ? '-' : '';- const percent = baseline > 0 ? ` (${sign}${((delta / baseline) * 100).toFixed(2)}%)` : '';+ // `delta` is already signed, so its magnitude has to be re-abs'd here: without this a+ // shrinking entry renders as `(--50.00%)`.+ const percent = baseline > 0 ? ` (${sign}${Math.abs((delta / baseline) * 100).toFixed(2)}%)` : '';return `${sign}${humanSize(Math.abs(delta))}${percent}`;};const formatCountLimit = (count) => (Number.isInteger(count) ? String(count) : count.toFixed(2));+/**+ * Verdict line appended to the section heading. The heading is the only place the PR+ * comment can see the numbers from β a passing gate is folded to a single line, so the+ * magnitude has to live where that line can be built without re-deriving the tables.+ *+ * `unit` separates measurements that are not byte sizes: the Vite file count can decide+ * the verdict, but it must never be rendered through the byte-oriented `formatDelta`.+ */+const buildHeadline = (compared) => {+ if (compared.length === 0) return '';+ const overCount = compared.filter((entry) => entry.over).length;+ if (overCount > 0) return `exceeds the gate on ${overCount} of ${compared.length} entries`;+ const sizes = compared.filter((entry) => entry.unit !== 'files');+ if (sizes.length === 0) return '';+ const worst = sizes.reduce((max, entry) =>+ Math.abs(entry.delta) > Math.abs(max.delta) ? entry : max,+ );+ const count = `${sizes.length} ${sizes.length === 1 ? 'entry' : 'entries'}`;+ return `${count}, largest Ξ ${formatDelta(worst.delta, worst.base)}`;+};+const appendReport = (file, section) => {fs.mkdirSync(path.dirname(file), { recursive: true });fs.appendFileSync(file, `${section}\n\n`);@@ -308,6 +331,8 @@ const check = (args) => {const keys = [...new Set([...Object.keys(baselineSizes), ...Object.keys(currentSizes)])];const rows = [];+ // Every comparison that produced a number and a verdict, feeding the heading headline.+ const compared = [];let failed = false;for (const key of keys) {@@ -325,6 +350,7 @@ const check = (args) => {const limit = Math.max((base * percent) / 100, floor);const over = delta > limit;if (over) failed = true;+ compared.push({ base, delta, over, unit: 'bytes' });rows.push(`| ${key} | ${humanSize(base)} | ${humanSize(cur)} | ${formatDelta(delta, base)} | ${over ? 'β' : 'β '} |`,);@@ -351,6 +377,12 @@ const check = (args) => {const chunkLimit = baselineJsChunks.total * (1 + jsChunkPercent / 100);const over = currentJsChunks.total > chunkLimit;if (over) failed = true;+ compared.push({+ base: baselineJsChunks.total,+ delta: currentJsChunks.total - baselineJsChunks.total,+ over,+ unit: 'files',+ });const targetKeys = [...new Set([...Object.keys(baselineJsChunks.targets || {}),@@ -383,8 +415,9 @@ const check = (args) => {({ name, before, after }) => `| ${name} | ${before || 'β'} | ${after || 'β'} |`,);+ const headline = buildHeadline(compared);const section = [- `### ${failed ? 'β' : 'β '} ${label}`,+ `### ${failed ? 'β' : 'β '} ${label}${headline ? ` β ${headline}` : ''}`,'',`| Entry | Baseline | Current | Ξ | Result |`,`| --- | --- | --- | --- | --- |`,@@ -447,6 +480,7 @@ const check = (args) => {};module.exports = {+ buildHeadline,countJsFiles,diffResolvedDeps,measureEntryGraph,diff --git a/.github/scripts/bundle-size-gate.test.cjs b/.github/scripts/bundle-size-gate.test.cjsindex 7db1c847901..1cd3f6031f4 100644--- a/.github/scripts/bundle-size-gate.test.cjs+++ b/.github/scripts/bundle-size-gate.test.cjs@@ -5,6 +5,7 @@ const path = require('node:path');const { test } = require('node:test');const {+ buildHeadline,countJsFiles,diffResolvedDeps,measureEntryGraph,@@ -103,9 +104,18 @@ const runCheck = ({ baselineGraphCount, baselineJsTotal, currentGraphCount, currpath.join(root, 'baseline.json'),'--js-chunk-percent','5',+ '--label',+ 'Web dist',+ '--report',+ path.join(root, 'report.md'),];- return spawnSync(process.execPath, args, { encoding: 'utf8' });+ const result = spawnSync(process.execPath, args, { encoding: 'utf8' });+ const reportPath = path.join(root, 'report.md');+ return {+ ...result,+ report: fs.existsSync(reportPath) ? fs.readFileSync(reportPath, 'utf8') : '',+ };};test('Vite JS output file count over the baseline percentage limit fails the gate', () => {@@ -139,6 +149,62 @@ test('reachable graph count increase alone does not fail the gate', () => {assert.equal(result.status, 0);});+test('a passing gate states the entry count and the largest delta in the heading', () => {+ const result = runCheck({+ baselineGraphCount: 10,+ baselineJsTotal: 100,+ currentGraphCount: 20,+ currentJsTotal: 100,+ });++ assert.equal(result.status, 0);+ assert.ok(result.report.startsWith('### β Web dist β 1 entry, largest Ξ +0.0 KB (+100.00%)'));+});++test('a rising file count never reports itself as a byte delta', () => {+ const result = runCheck({+ baselineGraphCount: 10,+ baselineJsTotal: 100,+ currentGraphCount: 10,+ currentJsTotal: 105,+ });++ assert.equal(result.status, 0);+ // +5 files is a file count, not "+0.0 KB (+5.00%)" of gzip output+ assert.ok(result.report.startsWith('### β Web dist β 1 entry, largest Ξ 0.0 KB (0.00%)'));+});++test('buildHeadline formats bytes only, but still counts a file-count breach', () => {+ const byteEntry = { base: 1024, delta: 0, over: false, unit: 'bytes' };+ const fileEntry = { base: 100, delta: 5, over: false, unit: 'files' };++ assert.equal(buildHeadline([byteEntry, fileEntry]), '1 entry, largest Ξ 0.0 KB (0.00%)');+ assert.equal(+ buildHeadline([byteEntry, { ...fileEntry, over: true }]),+ 'exceeds the gate on 1 of 2 entries',+ );+});++test('a failing gate states how many entries are over it in the heading', () => {+ const result = runCheck({+ baselineGraphCount: 10,+ baselineJsTotal: 100,+ currentGraphCount: 10,+ currentJsTotal: 106,+ });++ assert.equal(result.status, 1);+ assert.ok(result.report.startsWith('### β Web dist β exceeds the gate on 1 of 2 entries'));+});++test('buildHeadline stays empty when nothing was comparable', () => {+ assert.equal(buildHeadline([]), '');+ assert.equal(+ buildHeadline([{ base: 1024, delta: -512, over: false }]),+ '1 entry, largest Ξ -0.5 KB (-50.00%)',+ );+});+test('readResolvedDeps turns pnpm virtual store entries into name@version and drops peer suffixes', () => {const store = writeDist({'@[email protected][email protected]/x': '',diff --git a/.github/scripts/size-gate-comment.cjs b/.github/scripts/size-gate-comment.cjsindex 94e30c3df22..c700ac92e76 100644--- a/.github/scripts/size-gate-comment.cjs+++ b/.github/scripts/size-gate-comment.cjs@@ -9,9 +9,49 @@* `identifier` keeps one comment per gate: the web (e2e) and desktop (asar)* workflows run independently on the same PR and must not overwrite each other.*+ * A passing gate folds the whole report into a collapsed `<details>` so a green PR shows+ * one summary line instead of a multi-table block β one per gate, not per check. A failing+ * gate stays inline: nobody should have to expand a fold to find the offending entry.+ ** A failing gate also submits a REQUEST_CHANGES review from github-actions so the* job itself can stay green; a passing run dismisses that review again.*/+const FOOTER = `---+*Baseline: latest \`canary\` build (workflow artifact). Thresholds configurable via \`SIZE_GATE_PERCENT\` / \`SIZE_GATE_FLOOR_BYTES\` / \`SIZE_GATE_JS_CHUNK_PERCENT\`.*`;++/**+ * Summary line for the folded state. Built from the report's own `### ` headings, so the+ * line can only claim checks the report actually contains; the per-check metrics stay in+ * those headings, one click away.+ */+const summarize = ({ report, title }) => {+ const headings = report+ .split('\n')+ .filter((line) => line.startsWith('### '))+ .map((line) => line.slice(4).trim());+ const skipped = headings.filter((heading) => heading.startsWith('β οΈ')).length;+ const passed = headings.filter((heading) => heading.startsWith('β ')).length;+ const icon = skipped > 0 ? 'β οΈ' : 'β ';++ // No headings means the report never got produced (an earlier step failed, or the run+ // was cancelled). That is not a pass, and folding the only explanation away would hide it.+ if (headings.length === 0) return `β οΈ Bundle Size Gate β ${title} β expand for the details`;++ const detail =+ skipped > 0+ ? `${passed} of ${headings.length} checks passed β expand for why`+ : `${headings.length} ${headings.length === 1 ? 'check' : 'checks'} passed β expand for the tables`;++ return `${icon} Bundle Size Gate β ${title} Β· ${detail}`;+};++/** A passing gate folds into one line; a failing gate is rendered expanded, never folded. */+const buildCommentBody = ({ failed, report, title }) => {+ if (failed) return `### β Bundle Size Gate β ${title}\n\n${report}\n\n${FOOTER}`;++ return `<details>\n<summary>${summarize({ report, title })}</summary>\n\n${report}\n\n${FOOTER}\n\n</details>`;+};+const sizeGateComment = async ({github,context,@@ -27,12 +67,7 @@ const sizeGateComment = async ({const commentIdentifier = `<!-- SIZE-GATE-COMMENT-${identifier} -->`;const body = `${commentIdentifier}-### ${failed ? 'β' : 'β '} Bundle Size Gate β ${title}--${report}------*Baseline: latest \`canary\` build (workflow artifact). Thresholds configurable via \`SIZE_GATE_PERCENT\` / \`SIZE_GATE_FLOOR_BYTES\` / \`SIZE_GATE_JS_CHUNK_PERCENT\`.*`;+${buildCommentBody({ failed, report, title })}`;const { data: comments } = await github.rest.issues.listComments({issue_number: number,@@ -118,3 +153,5 @@ The size gate failed on the latest build. See the [report](${reportUrl}) for the};module.exports = sizeGateComment;+module.exports.buildCommentBody = buildCommentBody;+module.exports.summarize = summarize;diff --git a/.github/scripts/size-gate-comment.test.cjs b/.github/scripts/size-gate-comment.test.cjsindex 5654cbe4dda..ab66a4b9060 100644--- a/.github/scripts/size-gate-comment.test.cjs+++ b/.github/scripts/size-gate-comment.test.cjs@@ -5,6 +5,18 @@ const sizeGateComment = require('./size-gate-comment.cjs');const MARKER = '<!-- SIZE-GATE-REVIEW-web -->';+const REPORT = `### β Web dist β 4 entries, largest Ξ +7.0 KB (+0.00%)++| Entry | Baseline | Current | Ξ | Result |+| --- | --- | --- | --- | --- |+| total | 146.75 MB | 146.76 MB | +7.0 KB (+0.00%) | β |++### β First-screen static import graph (gzip) β 2 entries, largest Ξ +0.3 KB (+0.02%)++| Entry | Baseline | Current | Ξ | Result |+| --- | --- | --- | --- | --- |+| dist/auth | 531.6 KB | 531.6 KB | +0.3 KB (+0.02%) | β |`;+const fakeGithub = ({ comments = [], reviews = [] } = {}) => {const calls = [];const record =@@ -39,10 +51,12 @@ const run = (github, failed) =>github,identifier: 'web',issueNumber: 1,- report: 'report',+ report: REPORT,title: 'Web dist',});+const bodyOf = (github, name) => github.calls.find((c) => c.name === name).params.body;+test('a failing gate requests changes once and links the report comment', async () => {const github = fakeGithub();await run(github, true);@@ -83,3 +97,88 @@ test('a passing gate dismisses only its own open review', async () => {false,);});++test('a passing gate folds the report behind one summary line', async () => {+ const github = fakeGithub();+ await run(github, false);+ const body = bodyOf(github, 'createComment');++ assert.ok(body.startsWith('<!-- SIZE-GATE-COMMENT-web -->'));+ assert.equal(body.split('\n')[1], '<details>');+ assert.ok(body.trimEnd().endsWith('</details>'));++ const summary = body.split('\n').find((line) => line.startsWith('<summary>'));+ assert.equal(+ summary,+ '<summary>β Bundle Size Gate β Web dist Β· 2 checks passed β expand for the tables</summary>',+ );+ // A folded line carries no table of its own; every table sits below the fold.+ assert.ok(!summary.includes('|'));+ assert.equal(body.split('<summary>')[0].includes('|'), false);+ assert.ok(body.indexOf('| Entry |') > body.indexOf('</summary>'));+});++test('a failing gate keeps the report expanded instead of folding it', async () => {+ const github = fakeGithub();+ await run(github, true);+ const body = bodyOf(github, 'createComment');++ assert.ok(body.includes('### β Bundle Size Gate β Web dist'));+ assert.equal(body.includes('<details>'), false);+ assert.ok(body.indexOf('| Entry |') > 0);+});++test('folding also applies when the existing comment is updated in place', async () => {+ const github = fakeGithub({+ comments: [{ body: '<!-- SIZE-GATE-COMMENT-web --> old report', id: 5 }],+ });+ await run(github, false);++ assert.equal(+ github.calls.some((c) => c.name === 'createComment'),+ false,+ );+ const update = github.calls.find((c) => c.name === 'updateComment');+ assert.equal(update.params.comment_id, 5);+ assert.ok(update.params.body.includes('<details>'));+ assert.ok(update.params.body.includes('| Entry |'));+});++test('a skipped gate folds into a single warning line', async () => {+ const github = fakeGithub();+ await sizeGateComment({+ context: { repo: { owner: 'o', repo: 'r' } },+ failed: false,+ github,+ identifier: 'web',+ issueNumber: 1,+ report:+ '### β οΈ Web dist\n\nNo baseline found (`x.json`).\n\n> Gate skipped β no failure is reported.',+ title: 'Web dist',+ });++ assert.ok(+ bodyOf(github, 'createComment').includes(+ '<summary>β οΈ Bundle Size Gate β Web dist Β· 0 of 1 checks passed β expand for why</summary>',+ ),+ );+});++test('a report that never reached the gate folds to a warning line, not a pass', async () => {+ const github = fakeGithub();+ await sizeGateComment({+ context: { repo: { owner: 'o', repo: 'r' } },+ failed: false,+ github,+ identifier: 'web',+ issueNumber: 1,+ report: 'Build did not reach the size gate step.',+ title: 'Web dist',+ });++ const body = bodyOf(github, 'createComment');+ assert.ok(+ body.includes('<summary>β οΈ Bundle Size Gate β Web dist β expand for the details</summary>'),+ );+ assert.ok(body.includes('Build did not reach the size gate step.'));+});diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex 8326f802ee8..2fef53b2af8 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -60,8 +60,12 @@ jobs:git fetch --no-tags --depth=1 origin "${REF_SHA}"git checkout --force FETCH_HEAD- - name: Verify preview build filtering- run: node --test .github/scripts/vercel-ignored-build-step.test.cjs+ - name: Verify CI scripts+ run: |+ node --test \+ .github/scripts/vercel-ignored-build-step.test.cjs \+ .github/scripts/bundle-size-gate.test.cjs \+ .github/scripts/size-gate-comment.test.cjs- name: Setup environmentuses: ./.github/actions/setup-env