Files
OmniRoute/tests/unit/select-impacted-tests.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

125 lines
4.6 KiB
TypeScript

/**
* tests/unit/select-impacted-tests.test.ts
*
* TIA (Test Impact Analysis) selector — given a PR's changed files plus the
* import-graph impact map, pick the impacted unit tests with a run-all
* fail-safe. The `__RUN_ALL__` sentinel and `selectImpacted({changed, map})`
* signature are load-bearing — CI wiring depends on them.
*/
import test from "node:test";
import assert from "node:assert/strict";
import { selectImpacted } from "../../scripts/quality/select-impacted-tests.mjs";
const MAP = {
sources: {
"open-sse/services/combo.ts": ["tests/unit/combo-routing-engine.test.ts"],
"src/sse/services/auth.ts": ["tests/unit/sse-auth.test.ts"],
},
};
test("mapped source → its impacted test(s)", () => {
const sel = selectImpacted({ changed: ["open-sse/services/combo.ts"], map: MAP });
assert.deepEqual(sel, ["tests/unit/combo-routing-engine.test.ts"]);
});
test("changed test file → itself (always run a changed test)", () => {
const sel = selectImpacted({ changed: ["tests/unit/sse-auth.test.ts"], map: MAP });
assert.deepEqual(sel, ["tests/unit/sse-auth.test.ts"]);
});
test("hub file (setupPolyfill) → run all (fail-safe)", () => {
const sel = selectImpacted({ changed: ["open-sse/utils/setupPolyfill.ts"], map: MAP });
assert.deepEqual(sel, ["__RUN_ALL__"]);
});
test("unmapped source file → run all (fail-safe)", () => {
const sel = selectImpacted({ changed: ["open-sse/brand-new-file.ts"], map: MAP });
assert.deepEqual(sel, ["__RUN_ALL__"]);
});
// The TIA step runs selected files via `node --test`, so it must only ever select
// node:test unit files (the `test:unit` glob). vitest/.tsx/e2e/integration changes
// must NOT be selected — running them under node:test was the 99-false-failure bug.
test("changed vitest UI test (.test.tsx) → NOT selected", () => {
const sel = selectImpacted({ changed: ["tests/unit/free-pool-tab.test.tsx"], map: MAP });
assert.deepEqual(sel, []);
});
test("changed e2e test → NOT selected (not a node:test unit file)", () => {
const sel = selectImpacted({ changed: ["tests/e2e/system-failover.test.ts"], map: MAP });
assert.deepEqual(sel, []);
});
test("changed vitest file in uncurated tests/unit/autoCombo → NOT selected", () => {
const sel = selectImpacted({ changed: ["tests/unit/autoCombo/tieredRotation.test.ts"], map: MAP });
assert.deepEqual(sel, []);
});
test("changed unit test in a curated subdir → run itself", () => {
const sel = selectImpacted({ changed: ["tests/unit/db/migration.test.ts"], map: MAP });
assert.deepEqual(sel, ["tests/unit/db/migration.test.ts"]);
});
// Parity with package.json test:unit braces — memory/usage/combo/serial were missing
// from UNIT_SUBDIRS and silently failed to self-select.
test("changed unit test under memory/ → run itself", () => {
const sel = selectImpacted({
changed: ["tests/unit/memory/store.test.ts"],
map: MAP,
});
assert.deepEqual(sel, ["tests/unit/memory/store.test.ts"]);
});
test("changed unit test under usage/ → run itself", () => {
const sel = selectImpacted({
changed: ["tests/unit/usage/quota.test.ts"],
map: MAP,
});
assert.deepEqual(sel, ["tests/unit/usage/quota.test.ts"]);
});
test("changed unit test under combo/ → run itself", () => {
const sel = selectImpacted({
changed: ["tests/unit/combo/routing.test.ts"],
map: MAP,
});
assert.deepEqual(sel, ["tests/unit/combo/routing.test.ts"]);
});
test("changed unit test under serial/ → run itself", () => {
const sel = selectImpacted({
changed: ["tests/unit/serial/flaky-once.test.ts"],
map: MAP,
});
assert.deepEqual(sel, ["tests/unit/serial/flaky-once.test.ts"]);
});
test("changed unit .test.mjs → run itself", () => {
const sel = selectImpacted({
changed: ["tests/unit/example.test.mjs"],
map: MAP,
});
assert.deepEqual(sel, ["tests/unit/example.test.mjs"]);
});
// package.json: tests/unit/**/*.test.mjs (any depth, not only UNIT_SUBDIRS).
test("nested .test.mjs outside UNIT_SUBDIRS → run itself", () => {
const sel = selectImpacted({
changed: ["tests/unit/misc/nested/deep.test.mjs"],
map: MAP,
});
assert.deepEqual(sel, ["tests/unit/misc/nested/deep.test.mjs"]);
});
// electron/bin are outside the import-graph map roots — must NOT force __RUN_ALL__.
test("changed electron/ file alone → empty (not unit fail-safe)", () => {
const sel = selectImpacted({ changed: ["electron/main.js"], map: MAP });
assert.deepEqual(sel, []);
});
test("changed bin/ file alone → empty (not unit fail-safe)", () => {
const sel = selectImpacted({ changed: ["bin/omniroute.js"], map: MAP });
assert.deepEqual(sel, []);
});