3D engine that AI agents drive
Fail any growth of a goal scene that is already over its goal
Nguyen Xuan An42972f1ce01b
diff --git a/bench/size/README.md b/bench/size/README.mdindex 37aa10fb..8589c5bc 100644--- a/bench/size/README.md+++ b/bench/size/README.md@@ -61,7 +61,7 @@ A bundle that the base does not have is reported and never fails. A bundle thatThe table in the output shows each bundle, the base size, the growth and the allowance. The release budgets in `budgets.json` are printed as a report and do not fail a pull request.-The goals in `budgets.json` (`lit-box`, `gltf-box`, `agent-scene`) also gate: a goal scene that was at or under its goal on the base and goes over it fails, even inside its allowance, because many small accepted increases otherwise add up past the goal. Only a `- goal:<scene>: <why>` line accepts that, and An approves those lines. A `scene:<name>` line does not. A scene already over its goal on the base is held by its allowance only, until work brings it back under.+The goals in `budgets.json` (`lit-box`, `gltf-box`, `agent-scene`) also gate: a goal scene that was at or under its goal on the base and goes over it fails, even inside its allowance, because many small accepted increases otherwise add up past the goal. Only a `- goal:<scene>: <why>` line accepts that, and An approves those lines. A `scene:<name>` line does not. A scene already over its goal on the base may not grow by a single byte, even inside its allowance, until work brings it back under; the same `- goal:<scene>:` line is the only way past.## When a check failsdiff --git a/changes/size-goal-gate-over-base.md b/changes/size-goal-gate-over-base.mdnew file mode 100644index 00000000..b7909399--- /dev/null+++ b/changes/size-goal-gate-over-base.md@@ -0,0 +1 @@+- A goal scene that is already over its goal on the base branch now fails `npm run size` when a pull request grows it by any byte; only a `- goal:<scene>:` line approved by An accepts it.diff --git a/scripts/size-growth.mjs b/scripts/size-growth.mjsindex 3fe0f281..b357a346 100644--- a/scripts/size-growth.mjs+++ b/scripts/size-growth.mjs@@ -47,17 +47,21 @@ export function compareToBase(measured, baseMeasured, accepted = new Map()) {return { rows, problems };}-// A goal scene that was at or under its goal on the base branch may not cross it. Only a "- goal:<scene>:" line accepts that,-// and An approves those lines, so a bundle note for the scene does not count.+// A goal scene may not cross its goal, and a scene already over its goal on the base may not grow by a single byte.+// Only a "- goal:<scene>:" line accepts either, and An approves those lines, so a bundle note for the scene does not count.export function goalProblems(measured, baseMeasured, goals, accepted = new Map()) {const problems = [];for (const [scene, goal] of Object.entries(goals)) {const size = measured[`scene:${scene}`]?.gzip;const baseSize = baseMeasured[`scene:${scene}`]?.gzip;- if (size === undefined || baseSize === undefined) continue;- const crossed = baseSize <= goal && size > goal;- if (!crossed || accepted.has(`goal:${scene}`)) continue;- problems.push(`scene:${scene} is ${size} bytes gzip, over its goal of ${goal}, which the base branch met (${baseSize}). Move code out of the core bundle, or ask An to accept it with the line "- goal:${scene}: <why>" in changes/<issue>.size.md.`);+ if (size === undefined || baseSize === undefined || size <= goal) continue;+ if (accepted.has(`goal:${scene}`)) continue;+ const acceptLine = `ask An to accept it with the line "- goal:${scene}: <why>" in changes/<issue>.size.md`;+ if (baseSize <= goal) {+ problems.push(`scene:${scene} is ${size} bytes gzip, over its goal of ${goal}, which the base branch met (${baseSize}). Move code out of the core bundle, or ${acceptLine}.`);+ } else if (size > baseSize) {+ problems.push(`scene:${scene} grew from ${baseSize} to ${size} bytes gzip while it is over its goal of ${goal}. A scene over its goal may only shrink: move code out of the core bundle, or ${acceptLine}.`);+ }}return problems;}diff --git a/tests/size-growth.test.js b/tests/size-growth.test.jsindex 0d4c5273..134a0f87 100644--- a/tests/size-growth.test.js+++ b/tests/size-growth.test.js@@ -168,9 +168,20 @@ test('a bundle note for the scene does not accept crossing its goal', () => {assert.equal(problems.length, 1);});-test('a goal scene already over its goal on the base, or still under it, does not fail the goal check', () => {+test('a goal scene over its goal on the base may shrink or stay, and one under its goal may grow inside it', () => {const goals = { 'lit-box': 50000, 'gltf-box': 80000 };const base = { 'scene:lit-box': size(50189), 'scene:gltf-box': size(77000) };- const measured = { 'scene:lit-box': size(50200), 'scene:gltf-box': size(79000) };- assert.deepEqual(goalProblems(measured, base, goals), []);+ assert.deepEqual(goalProblems({ 'scene:lit-box': size(50150), 'scene:gltf-box': size(79000) }, base, goals), []);+ assert.deepEqual(goalProblems({ 'scene:lit-box': size(50189), 'scene:gltf-box': size(77000) }, base, goals), []);+});++test('a goal scene over its goal on the base fails when it grows, unless a goal line accepts it', () => {+ const goals = { 'lit-box': 50000 };+ const base = { 'scene:lit-box': size(50127) };+ const measured = { 'scene:lit-box': size(50183) };+ const problems = goalProblems(measured, base, goals);+ assert.equal(problems.length, 1);+ assert.match(problems[0], /scene:lit-box grew from 50127 to 50183 bytes gzip while it is over its goal of 50000/);+ assert.deepEqual(goalProblems(measured, base, goals, new Map([['goal:lit-box', 'approved by An']])), []);+ assert.equal(goalProblems(measured, base, goals, new Map([['scene:lit-box', 'worth it']])).length, 1);});