mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-24 07:53:09 +00:00
5a842c386a
google-quota, managed, mcp-shared, mcp-transport, public-api, receipt-scan, route-usage, scheduling, school-holidays, tokens and tours had no entry in the per-domain ratchet, so they sat in the pooled src/nest/** catch-all, where a domain can lose twenty points behind the headroom of the files beside it. That includes the cron registrar, the MCP HTTP transport, the public API and the new tours domain. Each is pinned at floor(measured) minus 1 as scripts/coverage-thresholds.mjs prints it, measured over the unit, integration and e2e suites that load the domain. A full run can only measure higher. mcp-shared (59 branches) and route-usage (66 branches, 77 functions) measure below the 80 floor and are pinned where they are; managed holds an empty module. A new unit test fails when a folder under src/nest has no entry, or an entry names a folder that is gone, so the next domain cannot land in the catch-all again.
62 lines
2.4 KiB
TypeScript
62 lines
2.4 KiB
TypeScript
import { readdirSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import config from '../../vitest.config';
|
|
|
|
/**
|
|
* The coverage gate is a ratchet per src/nest domain (vitest.config.ts). A
|
|
* domain without its own entry falls into the pooled `src/nest/**` catch-all,
|
|
* where its coverage is averaged with app.module.ts and the like and can drop
|
|
* twenty points unseen; eleven domains had landed that way. This keeps every
|
|
* domain folder on its own floor, and every entry pointing at a folder that
|
|
* still exists.
|
|
*/
|
|
|
|
const NEST = path.resolve(__dirname, '../../src/nest');
|
|
|
|
function domains(): string[] {
|
|
return readdirSync(NEST, { withFileTypes: true })
|
|
.filter((entry) => entry.isDirectory())
|
|
.map((entry) => entry.name)
|
|
.sort();
|
|
}
|
|
|
|
function domainKeys(): string[] {
|
|
const thresholds = (config.test?.coverage as { thresholds?: Record<string, unknown> } | undefined)?.thresholds ?? {};
|
|
return Object.keys(thresholds)
|
|
.map((key) => key.match(/^src\/nest\/([^/*]+)\/\*\*\/\*\.ts$/)?.[1])
|
|
.filter((name): name is string => Boolean(name))
|
|
.sort();
|
|
}
|
|
|
|
describe('per-domain coverage thresholds', () => {
|
|
it('COVT-001: the config holds the per-domain block at all', () => {
|
|
expect(domainKeys().length).toBeGreaterThan(50);
|
|
expect(domains().length).toBeGreaterThan(50);
|
|
});
|
|
|
|
it('COVT-002: every directory under src/nest has its own threshold entry', () => {
|
|
const pinned = new Set(domainKeys());
|
|
expect(
|
|
domains().filter((d) => !pinned.has(d)),
|
|
"add `'src/nest/<domain>/**/*.ts'` to vitest.config.ts, from `node scripts/coverage-thresholds.mjs` after a coverage run",
|
|
).toEqual([]);
|
|
});
|
|
|
|
it('COVT-003: every domain entry names a directory that exists', () => {
|
|
const present = new Set(domains());
|
|
expect(domainKeys().filter((d) => !present.has(d))).toEqual([]);
|
|
});
|
|
|
|
it('COVT-004: no domain entry sits above 100 or below 0', () => {
|
|
const thresholds = (config.test?.coverage as { thresholds?: Record<string, Record<string, number>> }).thresholds ?? {};
|
|
for (const domain of domainKeys()) {
|
|
const entry = thresholds[`src/nest/${domain}/**/*.ts`];
|
|
for (const metric of ['statements', 'branches', 'functions', 'lines']) {
|
|
expect(entry?.[metric], `${domain}.${metric}`).toBeGreaterThanOrEqual(0);
|
|
expect(entry?.[metric], `${domain}.${metric}`).toBeLessThanOrEqual(100);
|
|
}
|
|
}
|
|
});
|
|
});
|