mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
6680bc7c74
PluginsModule was 21 controllers, 24 domain imports and 10 providers in one class, which made it the hub most of the Nest graph ran through: AdminModule imported it for a single cascade-disable call and inherited all of it. It is now PluginsRuntimeModule (supervisor, capability router, hook contracts), PluginContributionsModule (the 14 read-only hook controllers, moved to contributions/), PluginOAuthModule (the credential leaf, moved to oauth/) and a composition root that keeps the install and delivery controllers. AdminModule imports the runtime alone. The three plugin files that reached for the db singleton alongside the injected DatabaseService no longer do. plugin-host-state and signature-status take the connection from the caller, and the three per-user settings functions that were bare exports 'so the RPC host wiring can call them directly' are now PluginUserSettingsService - the host wiring is providers, so it injects them. Coverage moves from one repo-wide 80% to a per-domain ratchet. The single number let a well-covered domain subsidise a thin one: booking-import sits at 50% and integrations at 20%, and the aggregate still cleared the bar, so either could have lost another ten points unnoticed. Each domain now carries its own measured floor, regenerated by scripts/coverage-thresholds.mjs. Two test-side findings on the way: expect(undefined).toContain(SomeClass) PASSES in this vitest version - it only throws for a string needle. Every '<X> is listed in its module providers' guard was written that way, so all twelve of them silently stopped guarding the moment their class moved. They go through expectRegisteredProvider now, which asserts the array shape first. The atlas region test paid for the one-off decompression of the multi-MB admin1 bundle inside its own 5s budget, which is why it failed under load and passed alone. The bundle is warmed in beforeAll instead.
56 lines
2.2 KiB
JavaScript
56 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Prints the per-domain `thresholds` block for vitest.config.ts from the last
|
|
* coverage run, at each domain's measured value minus one point of slack.
|
|
*
|
|
* npm run test:coverage # writes coverage/coverage-summary.json
|
|
* node scripts/coverage-thresholds.mjs
|
|
*
|
|
* The gate is a RATCHET: raise an entry when you improve a domain, never lower one
|
|
* to make a build pass. Use this when you have genuinely raised coverage and want the
|
|
* new floor written down, not to re-baseline a regression away.
|
|
*
|
|
* It reads coverage-summary.json rather than the text reporter on purpose. The text
|
|
* reporter prints one row per DIRECTORY, so a domain with subdirectories (plugins,
|
|
* memories, auth) reads several points higher there than it actually is, and a
|
|
* threshold copied off it would be wrong in the loose direction.
|
|
*/
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const summaryPath = path.join(process.cwd(), 'coverage', 'coverage-summary.json');
|
|
if (!fs.existsSync(summaryPath)) {
|
|
console.error(`no ${summaryPath} — run "npm run test:coverage" first`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const METRICS = [
|
|
['statements', 'statements'],
|
|
['branches', 'branches'],
|
|
['functions', 'functions'],
|
|
['lines', 'lines'],
|
|
];
|
|
|
|
const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8'));
|
|
const domains = new Map();
|
|
for (const [file, entry] of Object.entries(summary)) {
|
|
if (file === 'total') continue;
|
|
const match = file.split('\\').join('/').match(/\/src\/nest\/([a-z0-9-]+)\//);
|
|
if (!match) continue;
|
|
const totals = domains.get(match[1]) ?? new Map(METRICS.map(([k]) => [k, { covered: 0, total: 0 }]));
|
|
for (const [key, metric] of METRICS) {
|
|
totals.get(key).covered += entry[metric].covered;
|
|
totals.get(key).total += entry[metric].total;
|
|
}
|
|
domains.set(match[1], totals);
|
|
}
|
|
|
|
// A domain with no branches at all reads as 100%, which is the right floor for it.
|
|
const floorOf = ({ covered, total }) => (total === 0 ? 100 : Math.max(0, Math.floor((100 * covered) / total) - 1));
|
|
|
|
for (const domain of [...domains.keys()].sort()) {
|
|
const totals = domains.get(domain);
|
|
const parts = METRICS.map(([key]) => `${key}: ${floorOf(totals.get(key))}`).join(', ');
|
|
console.log(` 'src/nest/${domain}/**/*.ts': { ${parts} },`);
|
|
}
|