Files
OmniRoute/tests/unit/check-docs-counts-err-seam.test.ts
Dizzle 81bf3cc36e docs(checks): keep doc counts honest — headings, rankings, catalog, weights, quality gate and scoring diagram now covered (#12507)
Estender o gate de contagens para headings, rankings, catálogo, pesos, quality gate e o diagrama de scoring é exatamente o tipo de trabalho que evita a classe inteira em vez de um caso.

Falo por experiência desta campanha: o `check:docs-counts` caiu **duas vezes** hoje pela mesma causa — contagem de migration escrita à mão em três arquivos mais 41 mirrors, desatualizando a cada migration nova (#12970 e #13209). Cada superfície que este PR passa a cobrir é uma que deixa de virar base-red na mão de quem vier depois.

Revalidei sobre o tip: **19/19**, `check:docs-counts-sync` com 0 drifts, `check:docs-all` PASS, `check:doc-links` PASS.

**Integração:** dois conflitos.

1. `scripts/check/check-docs-counts-sync.mjs` — o bloco de leitura de fatos conflitou com os imports de free-tier que entraram pelo #12786/#12744 nesta campanha. Aditivo, os dois conjuntos ficaram.
2. `docs/diagrams/auto-combo-scoring.mmd` — o seu rótulo dizia `reliability (0.0000)`, mas o #12731 mergeou horas antes e passou a dar peso de reliability a todo mode pack. Ficou o rótulo do tip, `reliability (0.0000 DEFAULT, 0.03 packs, 0.04 reliable)`, que é o número real agora.
2026-09-10 10:54:38 -03:00

74 lines
2.2 KiB
TypeScript

import { afterEach, describe, it } from "node:test";
import assert from "node:assert/strict";
import {
buildChecks,
tallyDrift,
__setSpawnSyncForTest,
__resetSpawnSyncForTest,
} from "../../scripts/check/check-docs-counts-sync.mjs";
type Check = {
label?: string;
docKey?: string;
actual?: unknown;
strict?: boolean;
files?: string[];
validate?: (content: string, claim?: string) => { ok: boolean; detail: string };
};
// inject a failing spawnSync so we can test the failure path (node:child_process.spawnSync is non-configurable in ESM)
afterEach(() => {
try {
__resetSpawnSyncForTest();
} catch {}
});
describe("readCodeFacts failure is reported as a strict failure", () => {
it("reports a strict error when the code facts cannot be loaded", () => {
__setSpawnSyncForTest(
() =>
({
status: 1,
stdout: "",
stderr: "tsx not found",
pid: 1,
output: [],
signal: null,
}) as never
);
const checks = buildChecks() as Check[];
const errCheck = checks.find((c) => c.actual === "ERR");
assert.ok(
errCheck,
"should include a check with actual ERR when the facts loader returns null"
);
assert.equal(errCheck.strict, true, "ERR must be strict");
assert.ok(errCheck.validate, "validate must be defined");
const v = errCheck.validate!("", "code facts:ERR");
assert.equal(v.ok, false, "validate must return ok:false");
assert.match(String(v.detail), /readCodeFacts|tsx|spawnSync/i);
});
it("tallyDrift does not skip actual ERR", () => {
const checks = [
{
label: "Code-derived counts",
actual: "ERR",
strict: true,
files: ["docs/README.md"],
validate: () => ({ ok: false, detail: "ERR" }),
},
] as never;
const { strict } = tallyDrift(checks, () => "");
assert.equal(strict, 1);
});
it("tallyDrift skips actual 0 (source unknown)", () => {
const checks = [
{ label: "Code-derived counts", actual: 0, strict: true, files: ["README.md"] },
] as never;
const { strict } = tallyDrift(checks, () => "content");
assert.equal(strict, 0);
});
});