Files
OmniRoute/scripts/check/check-openapi-coverage.mjs
backryun d1d75fdbf4 ci(quality): cut PR gate wall time without dropping protection (#6716)
Collapse duplicate CI spend while keeping each gate's existence reason:

- quality.yml: TIA __RUN_ALL__ defers full unit to fast-unit 4-shard (#6781);
  path filters via classify-pr-changes; docs-gates split; draft skip
- ci.yml: wire docs/i18n/code path filters; ESLint JSON artifact for quality-gate;
  drop advisory typecheck:noimplicit; float actions/cache@v6
- TIA parity: memory/usage/combo/serial; **/*.test.mjs any depth; electron/bin
  no longer force unit __RUN_ALL__
- check:complexity-ratchets: one ESLint walk, ruleId-isolated baselines + cache
- check:api-docs-refs + lib/apiRoutes: shared API route inventory
- husky pre-push: intentionally light (gates live in pre-commit); CLAUDE.md +
  QUALITY_GATES.md docs synced
- collect-metrics / lint:json: path.resolve cache path; Windows-safe eslint bin
- env-doc allowlist for ESLINT_RESULTS_JSON / COMPLEXITY_ESLINT_REPORT
- release-green --full-ci expects check:api-docs-refs (not docs-symbols alone)

Tests: select-impacted, classify-pr-changes, api-routes lib, complexity-rule-count,
validate-release-green.

Reconciled after #6781 (fast-unit 2→4 shards) per maintainer request on #6716.

Co-authored-by: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com>
2026-07-11 08:03:11 -03:00

64 lines
2.0 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.
const THRESHOLD = 36;
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();
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);
}