Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion scripts/quality/baseline-headroom.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,27 @@ export function sumTypecheckBaseline(json) {
return n;
}

// Files whose size is not an editable-code signal: generated modules are frozen at
// their emitter's exact output size (β‰ˆ0% headroom by construction β€” growth is policed
// by re-freezing, e.g. openapi.generated.ts in #12212), and vendored code is upstream's.
// The GATE (check:file-size) still enforces both; only the monitor skips them so the
// nightly headroom-alert reflects files a human can actually slim.
export function isMonitorExemptFile(file) {
return file.includes(".generated.") || /(^|\/)vendor\//.test(file);
}

/**
* Frozen-file headroom: the worst (most consumed) frozen file and how many sit within
* `warnFraction` of their cap. `locOf(file)` returns the live line count or null.
* Generated/vendored files are excluded (see isMonitorExemptFile).
*/
export function fileSizeHeadroom(frozen, locOf, warnFraction = 0.1) {
let worst = null;
let nearCap = 0;
let over = 0;
let measured = 0;
for (const [file, capRaw] of Object.entries(frozen)) {
if (file.startsWith("_")) continue;
if (file.startsWith("_") || isMonitorExemptFile(file)) continue;
const cap = Number(capRaw);
const loc = locOf(file);
if (!Number.isFinite(cap) || loc === null || loc === undefined) continue;
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/build/baseline-headroom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import test from "node:test";
import {
fileSizeHeadroom,
headroomOf,
isMonitorExemptFile,
renderMarkdown,
statusOf,
sumTypecheckBaseline,
Expand Down Expand Up @@ -54,6 +55,30 @@ test("fileSizeHeadroom reports the worst frozen file and the near-cap / over cou
assert.ok(r.worst!.headroom < 0);
});

test("fileSizeHeadroom skips generated and vendored files (monitor-only exemption)", () => {
assert.equal(isMonitorExemptFile("src/app/docs/lib/openapi.generated.ts"), true);
assert.equal(
isMonitorExemptFile("open-sse/vendor/codex-chatgpt-web/adapters/chatgpt-web/browser-worker.ts"),
true
);
assert.equal(isMonitorExemptFile("vendor/thing.ts"), true);
assert.equal(isMonitorExemptFile("src/lib/generatedReport.ts"), false);
assert.equal(isMonitorExemptFile("src/lib/vendorAdapter.ts"), false);

const frozen = {
"x.generated.ts": 100, // 0% headroom by construction β€” must not be the worst
"open-sse/vendor/lib/big.ts": 1000,
"real.ts": "1200",
};
const loc = (f: string) =>
({ "x.generated.ts": 100, "open-sse/vendor/lib/big.ts": 999, "real.ts": 900 })[f] ?? null;
const r = fileSizeHeadroom(frozen, loc, 0.1);
assert.equal(r.measured, 1); // only real.ts counted
assert.equal(r.nearCap, 0);
assert.equal(r.over, 0);
assert.equal(r.worst?.file, "real.ts");
});

test("renderMarkdown lists every row with its status icon and flags the bad ones", () => {
const md = renderMarkdown(
[
Expand Down
Loading