Files
OmniRoute/tests/unit/check-complexity.test.ts
diegosouzapw 8567a80778 feat(quality): Fase 6 — 8 new gates (Rule #11/#12, migrations, known-symbols, route-guard, complexity, docs-symbols, db-rules)
Deterministic gates, each freezing pre-existing violations in a documented allowlist (ratchet) so they pass now and block only NEW regressions:
- check-error-helper (Rule #12): 7 executors/handlers forwarding raw err.message frozen
- check-public-creds (Rule #11): 5 literal client_ids (Claude/Codex/Qwen/Kimi/Copilot) frozen
- check-migration-numbering: gaps 026/055 + dup 041 frozen (prevents the git-rm-deleted-migration incident)
- check-known-symbols: 93 executors conformance + 15 combo strategies + 18 translator pairs
- check-route-guard-membership (#15/#17): all 25 spawn-capable routes verified local-only (0 gaps)
- check-complexity: cyclomatic>15 / fn-length>80 ratchet (baseline 1739)
- check-docs-symbols: 30 stale doc /api refs frozen (docs hallucination)
- check-db-rules (#2/#5): 25 unexported db modules + 15 raw-SQL routes frozen
Wired into CI (lint / docs-sync-strict / quality-gate jobs). 115 TDD tests, all green. ESLint ratchet held at 3482.
2026-06-09 09:57:43 -03:00

47 lines
1.6 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert";
import { evaluateComplexity } from "../../scripts/check/check-complexity.mjs";
// The .mjs module has no .d.ts; type the pure comparator locally so the test file
// stays free of explicit `any` (ratchet 3482 — zero new warnings allowed).
type ComplexityVerdict = { regressed: boolean; improved: boolean };
const evaluate = evaluateComplexity as (current: number, baseline: number) => ComplexityVerdict;
const BASELINE = 1739;
test("equal to baseline passes", () => {
const r = evaluate(BASELINE, BASELINE);
assert.equal(r.regressed, false);
assert.equal(r.improved, false);
});
test("one more violation is a regression", () => {
const r = evaluate(BASELINE + 1, BASELINE);
assert.equal(r.regressed, true);
assert.equal(r.improved, false);
});
test("a large increase is a regression", () => {
const r = evaluate(BASELINE + 200, BASELINE);
assert.equal(r.regressed, true);
});
test("one fewer violation is an improvement (ratchet down)", () => {
const r = evaluate(BASELINE - 1, BASELINE);
assert.equal(r.regressed, false);
assert.equal(r.improved, true);
});
test("zero violations is an improvement and never regresses", () => {
const r = evaluate(0, BASELINE);
assert.equal(r.regressed, false);
assert.equal(r.improved, true);
});
test("exact-integer comparison — no epsilon tolerance", () => {
// Unlike the duplication gate (float %), complexity is an integer count: any increase
// at all must fail, with no slack.
assert.equal(evaluate(11, 10).regressed, true);
assert.equal(evaluate(10, 10).regressed, false);
});