Files
OmniRoute/scripts/check/check-openapi-coverage.mjs
Diego Rodrigues de Sa e Souza 1f4dc830f3 chore(quality): velocity phase — loosen every numeric baseline by 20% until v4.0, monitor headroom nightly (#12125)
Owner decision (2026-08-30): shipping speed matters more than holding the debt line
until the v4.0 LTS modularization; the base was going red on every merge batch and
each red baseline cost a sweep.

Relaxation (one auditable pass, scripts/quality/relax-baselines.mjs):
- quality-baseline.json metrics: lower-is-better ×1.2, higher-is-better ÷1.2
  (coverage floor 60 kept; eslintErrors stays 0; eslintWarnings 0 → 1050 = 20% of
  the 5,247 frozen suppressions). Adds `_policy {phase: velocity, until: 4.0.0,
  relaxPct: 20, requireTighten: false}` + a `_relax_velocity_2026_08_30` note
  listing every before → after.
- complexity count 2681 → 3218; duplication 5.72 → 6.86; file-size cap/testCap
  1000 → 1200 and all 127 frozen caps ×1.2; api/dashboard/open-sse typecheck
  per-file counts ×1.2; openapi-coverage THRESHOLD 36 → 30.
- check-quality-ratchet: --require-tighten is advisory while _policy.requireTighten
  is false (2 new tests); nightly bank-ratchet-shrinks pauses during the phase (it
  would bank the measured shrink and undo the headroom every night).

Monitoring (scripts/quality/baseline-headroom.mjs, npm run quality:headroom):
measures each numeric gate the way CI does, prints live / baseline / headroom per
gate (ok ≥10%, warn <10%, critical <0); the new nightly `baseline-headroom` job
posts the table to the living issue "📈 Baseline headroom (velocity phase)" and
toggles the `headroom-alert` label. 6 unit tests on the pure helpers.

Also aligns the remaining red tests on the tip to contracts already merged:
#11775 (FREE lease-capable connections are ordinary capacity: gate inventory 48/97/99,
sse-auth selection, warmup scheduler), #11794 (dual-loopback readiness probe), and the
8 vi strings #11775 left as __MISSING__.

Docs: QUALITY_GATES.md → "Velocity phase" (what changed, tooling, how to close the
phase at 4.0), AGENTS.md quick reference.
2026-08-30 10:39:01 -03:00

66 lines
2.2 KiB
JavaScript

#!/usr/bin/env node
/**
* Validates that openapi.yaml documents ≥ 99% of implemented routes.
* Routes marked x-internal: true in openapi.yaml count as "covered" because
* they are acknowledged as existing — just not part of the public API surface.
*
* Fails if coverage < 99%.
*/
import fs from "node:fs";
import path from "node:path";
import * as yaml from "js-yaml";
import { apiRoot, collectApiRouteUrlPaths } from "./lib/apiRoutes.mjs";
const ROOT = process.cwd();
const API_ROOT = apiRoot(ROOT);
const OPENAPI_PATH = path.join(ROOT, "docs", "openapi.yaml");
// Floor recorded on 2026-05-26 for release/v3.8.4: 137/365 routes documented.
// The original ≥99% target tracks the OpenAPI audit follow-up (#2701);
// until the backlog (services, free-proxies, relay-tokens, key-groups,
// middleware/hooks, etc.) is documented, the gate enforces "no regressions"
// instead of the absolute target. Raise this back to 99 once the backlog clears.
// Velocity phase (2026-08-30, until v4.0): 36 → 30, same 20% relaxation as the ratchet
// baselines (config/quality/quality-baseline.json `_policy`). Re-tighten at 4.0.
const THRESHOLD = 30;
if (!fs.existsSync(API_ROOT)) {
console.error(`[openapi-coverage] FAIL — API root not found: ${API_ROOT}`);
process.exit(1);
}
if (!fs.existsSync(OPENAPI_PATH)) {
console.error(`[openapi-coverage] FAIL — openapi.yaml not found: ${OPENAPI_PATH}`);
process.exit(1);
}
const implementedPaths = collectApiRouteUrlPaths(ROOT).sort((a, b) => a.localeCompare(b));
const raw = yaml.load(fs.readFileSync(OPENAPI_PATH, "utf-8"));
const documentedPaths = new Set(Object.keys(raw.paths || {}));
let covered = 0;
const missing = [];
for (const p of implementedPaths) {
if (documentedPaths.has(p)) {
covered++;
} else {
missing.push(p);
}
}
const total = implementedPaths.length;
const coverage = (covered / total) * 100;
if (coverage >= THRESHOLD) {
console.log(
`[openapi-coverage] PASS — ${coverage.toFixed(1)}% (${covered}/${total} routes documented)`
);
process.exit(0);
} else {
console.error(`[openapi-coverage] FAIL — coverage ${coverage.toFixed(1)}% < ${THRESHOLD}%`);
console.error(`Missing routes (${missing.length}):`);
missing.forEach((p) => console.error(` - ${p}`));
process.exit(1);
}