Skip to content

feat(quality): anti-reinflation Layer 1 — cap test-file size (freeze god-tests, cap new at 800) - #4273

Merged
diegosouzapw merged 1 commit into
release/v3.8.30from
feat/qg-test-file-cap-v3830
Jun 19, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.30from
feat/qg-test-file-cap-v3830

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

O que / por quê

T4 Camada 1 do design anti-reinflação (Quality Gate v2 / Fase 9). Hoje o check-file-size exclui 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:

  • 41 test files grandes (> 800 LOC hoje) congelados shrink-only (testFrozen)
  • test files novos com teto de 800 LOC (testCap)

Como

  • Reusa evaluateFileSizes() no pass de test (sem duplicar lógica); adiciona walkTests()/collectTestLoc() e um resumo [test-file-size] separado; violação em qualquer set → exit 1.
  • --update ratcheta testFrozen também.
  • Todo o gate de teste é guardado por typeof testCap === "number" → baseline sem a chave = comportamento byte-idêntico ao antigo (back-compat). Source path inalterado.
  • Baseline = puramente aditivo (testCap + testFrozen; frozen/cap existentes intocados, 0 remoções).
  • Roda nos jobs check:file-size já 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).
  • TDD: tests/unit/check-file-size.test.ts 9/9 (5 originais + 4 novos: novo>cap falha / novo≤cap ok / frozen cresceu falha / frozen encolheu ok).
  • Diff: 3 arquivos, +164/−12.

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

… 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).
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +120 to 145
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");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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");
  }

@diegosouzapw
diegosouzapw merged commit 871d109 into release/v3.8.30 Jun 19, 2026
4 checks passed
@diegosouzapw
diegosouzapw deleted the feat/qg-test-file-cap-v3830 branch June 21, 2026 12:33
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant