Files
OmniRoute/tests/unit/classify-pr-changes.test.ts
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

70 lines
2.6 KiB
TypeScript

/**
* tests/unit/classify-pr-changes.test.ts
*
* Locks the *existence reason* of each change flag used by ci.yml path filters:
* - code → heavy static + unit/vitest (code regression surface)
* - docs → docs-sync / prose only
* - i18n → translation validation; pure messages must NOT force full unit
* - workflow → always code (CI is part of the safety net)
* - unknown → code (fail-safe over-run)
*/
import test from "node:test";
import assert from "node:assert/strict";
import { classifyPaths } from "../../scripts/quality/classify-pr-changes.mjs";
test("pure docs PR → docs only (no code unit/lint bag)", () => {
const c = classifyPaths(["docs/architecture/QUALITY_GATES.md", "README.md"]);
assert.deepEqual(c, { code: false, docs: true, i18n: false, workflow: false });
});
test("openapi under docs/ → docs (contract gates live in docs-sync, not unit)", () => {
const c = classifyPaths(["docs/openapi.yaml"]);
assert.equal(c.docs, true);
assert.equal(c.code, false);
});
test("pure message catalog → i18n only (not full unit suite)", () => {
const c = classifyPaths(["src/i18n/messages/en.json", "src/i18n/messages/ko.json"]);
assert.deepEqual(c, { code: false, docs: false, i18n: true, workflow: false });
});
test("i18n tooling/scripts → i18n + code (tooling can break runtime paths)", () => {
const c = classifyPaths(["scripts/i18n/check-ui-keys-coverage.mjs"]);
assert.equal(c.i18n, true);
assert.equal(c.code, true);
});
test("src/i18n loader TS (non-messages) → i18n + code", () => {
const c = classifyPaths(["src/i18n/request.ts"]);
assert.equal(c.i18n, true);
assert.equal(c.code, true);
});
test("workflow change → workflow + code (gates protect the gates)", () => {
const c = classifyPaths([".github/workflows/ci.yml"]);
assert.equal(c.workflow, true);
assert.equal(c.code, true);
});
test("production source → code", () => {
const c = classifyPaths(["open-sse/handlers/chatCore.ts", "src/lib/db/core.ts"]);
assert.deepEqual(c, { code: true, docs: false, i18n: false, workflow: false });
});
test("mixed docs + code → both flags (jobs union their filters)", () => {
const c = classifyPaths(["docs/README.md", "src/lib/db/core.ts"]);
assert.equal(c.docs, true);
assert.equal(c.code, true);
});
test("unknown path → code fail-safe (never skip heavy gates by accident)", () => {
const c = classifyPaths(["weird/unclassified.bin"]);
assert.equal(c.code, true);
});
test("empty change list → all false (nothing to validate)", () => {
const c = classifyPaths([]);
assert.deepEqual(c, { code: false, docs: false, i18n: false, workflow: false });
});