You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte-kit-vice/scripts/check-gate.ts

85 lines
2.9 KiB

feat(gate): fase B de P0 — la puerta existe y sabe fallar El hallazgo mayor confirmado de la auditoría 2026-08-26: ~16 validadores y 429 ficheros de test que nada ejecutaba (sin CI en ninguna rama de la historia, hooks .sample, eidos-lint sin script npm). Esta fase los cablea: - `check:gate` (scripts/check-gate.ts): svelte-check con política — src/ debe cero; web/ se mide contra el ledger menguante scripts/check-debt.ts (34 ficheros, 71 errores congelados; sólo puede bajar, la disciplina de theming-census-debt). Guard anti-vacío: sin marcador COMPLETED o con conteo que no cuadra, falla — un gate que no inspeccionó nada no pasa. - `eidos:lint` deja de ser invocación cruda (exit 1 real en invalid/dead). - `gate`: check:gate → validadores rápidos → vitest al final. `lint` queda deliberadamente FUERA: hay ~2.300 ficheros de deuda de formato preexistente (nunca se formateó el repo entero; el one-shot pendiente es `npm run format` en árbol quieto y re-añadirlo — documentado en el hook). - scripts/hooks/pre-push: la fuente del hook, SIN armar. Se armó en caliente, bloqueó el push legítimo del eje theming (secuencia mal: verde primero, puerta después) y se desarmó — de paso la puerta demostró que sabe fallar, que era el requisito de verificación de la fase. - .prettierrc endOfLine:auto — neutraliza la clase CRLF/autocrlf de Windows (~350 falsos rojos), sin cambiar formato real. Verificación: check:gate exit 0 sobre HEAD (71 dentro del ledger, src/ a cero tras 9d6533cb7 del eje navigation-menu) · sondeo individual del resto de miembros del gate: verdes salvo los adjudicados en fase A. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 month ago
/**
* check-gate — svelte-check with the debt ledger applied.
*
* Policy (P0 fase A, audit 2026-08-26):
* - Any ERROR under `src/` fails the gate: framework source owes zero.
* - ERRORs elsewhere (the demo tree) are measured against the per-file
* ledger in `check-debt.ts`. A file above its ledgered count — or an
* erroring file the ledger does not name — fails. Counts only shrink:
* when a file drops below its entry the gate says so; lower the entry
* in the same change.
* - The run must end with svelte-check's `COMPLETED` marker and the
* parsed error count must match the marker's total — a gate that
* inspected nothing must fail, never pass.
*
* Usage: npm run check:gate
*/
import { spawnSync } from 'node:child_process';
import { CHECK_DEBT } from './check-debt';
const run = spawnSync('npm', ['run', 'check'], {
shell: true,
encoding: 'utf8',
maxBuffer: 64 * 1024 * 1024
});
const out = `${run.stdout ?? ''}\n${run.stderr ?? ''}`;
const completed = /^\d+\s+COMPLETED\s+\d+\s+FILES\s+(\d+)\s+ERRORS\b/m.exec(out);
if (!completed) {
console.error('check-gate: svelte-check produced no COMPLETED marker — treating as failure.');
console.error(out.slice(-2000));
process.exit(1);
}
const reportedErrors = Number(completed[1]);
const errorsByFile = new Map<string, number>();
let parsedErrors = 0;
for (const line of out.split('\n')) {
const m = /^\d+\s+ERROR\s+"(.+?)"\s+\d+:\d+\s+/.exec(line);
if (!m) continue;
const file = m[1].replace(/\\+/g, '/');
errorsByFile.set(file, (errorsByFile.get(file) ?? 0) + 1);
parsedErrors += 1;
}
if (parsedErrors !== reportedErrors) {
console.error(
`check-gate: parsed ${parsedErrors} ERROR lines but svelte-check reported ${reportedErrors} — output format drifted, refusing to judge.`
);
process.exit(1);
}
let failed = false;
const srcErrors = [...errorsByFile].filter(([file]) => file.startsWith('src/'));
if (srcErrors.length > 0) {
failed = true;
console.error('check-gate: framework source has type errors (src/ owes zero):');
for (const [file, count] of srcErrors) console.error(` ${file}: ${count}`);
}
for (const [file, count] of errorsByFile) {
if (file.startsWith('src/')) continue;
const allowed = CHECK_DEBT[file];
if (allowed === undefined) {
failed = true;
console.error(`check-gate: NEW debt — ${file} has ${count} error(s) and no ledger entry.`);
} else if (count > allowed) {
failed = true;
console.error(
`check-gate: debt GREW — ${file} has ${count} error(s), ledger allows ${allowed}.`
);
} else if (count < allowed) {
console.log(
`check-gate: debt shrank — ${file} is at ${count} (ledger says ${allowed}); lower the entry.`
);
}
}
for (const file of Object.keys(CHECK_DEBT)) {
if (!errorsByFile.has(file)) {
console.log(`check-gate: ${file} is clean — remove its ledger entry.`);
}
}
if (!failed) console.log(`check-gate: OK — ${reportedErrors} error(s), all within the ledger.`);
process.exit(failed ? 1 : 0);

Powered by TurnKey Linux.