Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Fail a pull request that takes a goal scene over its goal

Nguyen Xuan An05d192041255
diff --git a/bench/size/README.md b/bench/size/README.md
index 3048d718..37aa10fb 100644
--- a/bench/size/README.md
+++ b/bench/size/README.md
@@ -59,7 +59,9 @@ A bundle fails when it grows by more than its allowance:
A bundle that the base does not have is reported and never fails. A bundle that shrinks never fails.
-The table in the output shows each bundle, the base size, the growth and the allowance. The release budgets in `budgets.json` and the goals are printed as a report. They do not fail a pull request.
+The 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.
## When a check fails
diff --git a/changes/size-goal-gate.md b/changes/size-goal-gate.md
new file mode 100644
index 00000000..cfece2c0
--- /dev/null
+++ b/changes/size-goal-gate.md
@@ -0,0 +1 @@
+- `npm run size` fails a pull request that takes `scene:lit-box`, `scene:gltf-box` or `scene:agent-scene` over its goal when the base branch met it. Only a `- goal:<scene>:` line, approved by An, accepts that.
diff --git a/scripts/measure-size.mjs b/scripts/measure-size.mjs
index 43674dab..1141ee8a 100644
--- a/scripts/measure-size.mjs
+++ b/scripts/measure-size.mjs
@@ -8,7 +8,7 @@ import { brotliCompressSync, gzipSync } from 'node:zlib';
import { build } from 'esbuild';
import { glslCommentStripperForEsbuild } from './strip-glsl-comments.mjs';
import { budgetsFrom, compareToBudgets, formatRows, initialOutputPaths } from './size-budget.mjs';
-import { compareToBase, formatGrowthRows } from './size-growth.mjs';
+import { compareToBase, formatGrowthRows, goalProblems } from './size-growth.mjs';
import { measureArchiveBytes } from './measure-archive.mjs';
import { DEFAULT_BASE_REF, baseRefExists, measureBase, readAcceptedBundles } from './size-base.mjs';
@@ -210,6 +210,7 @@ if (checkGrowth) {
console.log(formatGrowthRows(growth.rows));
for (const [name, reason] of accepted) console.log(`Accepted: ${name}, ${reason}`);
problems.push(...growth.problems);
+ problems.push(...goalProblems(measured, await baseMeasurement, budgetFile.goals, accepted));
} else if (!refreshing) {
console.log(`No ${baseRef} to compare with, so the growth check is skipped. Fetch it, or pass --base <ref>.`);
}
diff --git a/scripts/size-growth.mjs b/scripts/size-growth.mjs
index dd15895b..3fe0f281 100644
--- a/scripts/size-growth.mjs
+++ b/scripts/size-growth.mjs
@@ -47,6 +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.
+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.`);
+ }
+ return problems;
+}
+
function noteFor(row) {
if (row.growth === null) return 'new, reported only';
if (row.growth <= row.allowance) return '';
diff --git a/tests/size-growth.test.js b/tests/size-growth.test.js
index 19afca8a..0d4c5273 100644
--- a/tests/size-growth.test.js
+++ b/tests/size-growth.test.js
@@ -5,7 +5,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import test from 'node:test';
import { mergeBaseOf, pullRequestBaseOf, readAcceptedBundles } from '../scripts/size-base.mjs';
-import { archiveAllowance, archiveCeilingProblem, archiveGrowthProblem, compareToBase, growthAllowance, parseSizeNote } from '../scripts/size-growth.mjs';
+import { archiveAllowance, archiveCeilingProblem, archiveGrowthProblem, compareToBase, goalProblems, growthAllowance, parseSizeNote } from '../scripts/size-growth.mjs';
const size = gzip => ({ min: gzip * 3, gzip });
@@ -150,3 +150,27 @@ test('a pull request behind the base branch is compared with the base it was mer
rmSync(folder, { recursive: true, force: true });
}
});
+
+test('a goal scene that crosses its goal fails, unless a goal line accepts it', () => {
+ const goals = { 'lit-box': 50000 };
+ const base = { 'scene:lit-box': size(49990) };
+ const measured = { 'scene:lit-box': size(50020) };
+ const problems = goalProblems(measured, base, goals);
+ assert.equal(problems.length, 1);
+ assert.match(problems[0], /scene:lit-box is 50020 bytes gzip, over its goal of 50000, which the base branch met \(49990\)/);
+ assert.match(problems[0], /- goal:lit-box: <why>/);
+ assert.deepEqual(goalProblems(measured, base, goals, new Map([['goal:lit-box', 'approved by An']])), []);
+});
+
+test('a bundle note for the scene does not accept crossing its goal', () => {
+ const accepted = new Map([['scene:lit-box', 'worth it']]);
+ const problems = goalProblems({ 'scene:lit-box': size(50020) }, { 'scene:lit-box': size(49990) }, { 'lit-box': 50000 }, accepted);
+ 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', () => {
+ 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), []);
+});