feat(quality): anti-reinflation Layer 1 — cap test-file size (freeze god-tests, cap new at 800) - #4273
Conversation
… god-tests, cap new at 800 T4 Layer 1 of the Quality Gate v2 anti-reinflation design: check-file-size previously EXCLUDED test files entirely (it skips *.test.ts(x)), so the test suite could re-bloat freely — directly undermining the R1 prune (a pruned suite must not just regrow). Extend the existing frozen-baseline ratchet to test files with the SAME semantics: - existing large test files (41 currently > 800 LOC) frozen shrink-only (testFrozen) - new test files capped at 800 LOC (testCap) Implementation reuses evaluateFileSizes() for the test-file pass (no duplicated logic), adds walkTests()/collectTestLoc(), and a separate [test-file-size] OK/violation summary; a violation in EITHER set exits 1. --update ratchets testFrozen too. The whole test gate is guarded by `typeof testCap === "number"` so a baseline without the key is byte-identical to the old behavior (back-compat). Source-file path unchanged. Baseline change is purely additive (testCap + testFrozen; existing frozen/cap untouched). Runs in the existing check:file-size CI jobs (ci.yml + quality.yml) — no new wiring. TDD: 4 new test-file cases (new>cap fails, new≤cap ok, frozen grew fails, frozen shrank ok).
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Code Review
This pull request introduces a test-file size checking mechanism (Layer 1 anti-reinflation) to prevent test files from growing excessively. It adds a testCap and a testFrozen baseline to the quality configuration, updates the file-size check script to scan and evaluate test files, and includes corresponding unit tests. The reviewer pointed out an issue where running the script with --update can result in partial baseline updates on disk even if the process fails due to violations in another category, and suggested only writing updates when there are no violations in either source or test files.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if (UPDATE) { | ||
| let changed = false; | ||
| if (violations.length === 0 && improvements.length) { | ||
| for (const [file, loc] of improvements) { | ||
| if (loc <= cap) | ||
| delete frozen[file]; // caiu para dentro do cap → sai do baseline | ||
| else frozen[file] = loc; // continua grande mas encolheu → trava no novo valor | ||
| } | ||
| baseline.frozen = Object.fromEntries(Object.entries(frozen).sort()); | ||
| changed = true; | ||
| console.log(`[file-size] baseline ratcheado: ${improvements.length} arquivo(s) encolheram`); | ||
| } | ||
| if (typeof testCap === "number" && testViolations.length === 0 && testImprovements.length) { | ||
| for (const [file, loc] of testImprovements) { | ||
| if (loc <= testCap) | ||
| delete testFrozen[file]; // caiu para dentro do testCap → sai do baseline | ||
| else testFrozen[file] = loc; // continua grande mas encolheu → trava no novo valor | ||
| } | ||
| baseline.testFrozen = Object.fromEntries(Object.entries(testFrozen).sort()); | ||
| changed = true; | ||
| console.log( | ||
| `[test-file-size] baseline ratcheado: ${testImprovements.length} arquivo(s) de teste encolheram` | ||
| ); | ||
| } | ||
| baseline.frozen = Object.fromEntries(Object.entries(frozen).sort()); | ||
| fs.writeFileSync(BASELINE_PATH, JSON.stringify(baseline, null, 2) + "\n"); | ||
| console.log(`[file-size] baseline ratcheado: ${improvements.length} arquivo(s) encolheram`); | ||
| if (changed) fs.writeFileSync(BASELINE_PATH, JSON.stringify(baseline, null, 2) + "\n"); | ||
| } |
There was a problem hiding this comment.
Atualmente, se houver violações em uma categoria (por exemplo, arquivos de código-fonte) mas melhorias em outra (por exemplo, arquivos de teste), o script executado com --update atualizará parcialmente o arquivo de baseline no disco, mesmo que o processo termine com falha (exit 1). Para evitar estados inconsistentes ou modificações parciais indesejadas no repositório local, é recomendável aplicar as atualizações de baseline apenas se não houver nenhuma violação em todo o processo.
const hasViolations = violations.length > 0 || (typeof testCap === "number" && testViolations.length > 0);
if (UPDATE && !hasViolations) {
let changed = false;
if (improvements.length) {
for (const [file, loc] of improvements) {
if (loc <= cap)
delete frozen[file]; // caiu para dentro do cap → sai do baseline
else frozen[file] = loc; // continua grande mas encolheu → trava no novo valor
}
baseline.frozen = Object.fromEntries(Object.entries(frozen).sort());
changed = true;
console.log("[file-size] baseline ratcheado: " + improvements.length + " arquivo(s) encolheram");
}
if (typeof testCap === "number" && testImprovements.length) {
for (const [file, loc] of testImprovements) {
if (loc <= testCap)
delete testFrozen[file]; // caiu para dentro do testCap → sai do baseline
else testFrozen[file] = loc; // continua grande mas encolheu → trava no novo valor
}
baseline.testFrozen = Object.fromEntries(Object.entries(testFrozen).sort());
changed = true;
console.log(
"[test-file-size] baseline ratcheado: " + testImprovements.length + " arquivo(s) de teste encolheram"
);
}
if (changed) fs.writeFileSync(BASELINE_PATH, JSON.stringify(baseline, null, 2) + "\n");
}… god-tests, cap new at 800 (diegosouzapw#4273) Layer 1 anti-reinflation: cap test-file size (freeze god-tests, cap new at 800). Gate validated green against the full combined tree.
O que / por quê
T4 Camada 1 do design anti-reinflação (Quality Gate v2 / Fase 9). Hoje o
check-file-sizeexclui test files (pula*.test.ts(x)), então a suíte pode re-inflar livremente — o que mina a poda R1 (uma suíte podada não pode simplesmente voltar a crescer). Estende a catraca de baseline congelado para test files, com a MESMA semântica:testFrozen)testCap)Como
evaluateFileSizes()no pass de test (sem duplicar lógica); adicionawalkTests()/collectTestLoc()e um resumo[test-file-size]separado; violação em qualquer set → exit 1.--updateratchetatestFrozentambém.typeof testCap === "number"→ baseline sem a chave = comportamento byte-idêntico ao antigo (back-compat). Source path inalterado.testCap+testFrozen;frozen/capexistentes intocados, 0 remoções).check:file-sizejá existentes (ci.yml+quality.yml) — sem wiring novo.Validação (Hard Rule #18 — TDD + gate real)
node scripts/check/check-file-size.mjs→ exit 0 na árvore v3.8.30 (102 source + 41 test congelados; o seed bate).tests/unit/check-file-size.test.ts9/9 (5 originais + 4 novos: novo>cap falha / novo≤cap ok / frozen cresceu falha / frozen encolheu ok).Fecha o loop com os gates existentes:
pr-test-policy(obriga teste p/ código novo) +test-masking(não enfraquece assert) + Camada 1 (não vira monstro) + Camada 2 (contador-de-redundância, vem depois com os scores).🤖 Generated with Claude Code