Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

test(server): pin the eleven unlisted domains on their own coverage floor

Maurice5a842c386a27
diff --git a/server/CLAUDE.md b/server/CLAUDE.md
index 305c7adeb..e66177a4a 100644
--- a/server/CLAUDE.md
+++ b/server/CLAUDE.md
@@ -75,7 +75,7 @@ Nest owns everything. Every domain is a DI module under `src/nest/<domain>/` (`c
- **Upgrade fixtures**: `tests/fixtures/legacy/legacy-v*.sql` are databases the retired positional runner built; `tests/integration/legacy-upgrade-v*.test.ts` boot `buildApp()` on each. `legacy-v244` is the v4.3.3 release with rows across the main tables, rebuilt reproducibly by `node scripts/build-legacy-fixture-v244.mjs` (archives the tag into a temp dir, boots that release's runner, seeds, pins timestamps, dumps).
- **vitest uses the SWC plugin**, not esbuild, because Nest's DI needs emitted decorator metadata. Keep that in `vitest.config.ts`. Pool is `forks` (isolated DB per worker). The config also aliases `@modelcontextprotocol/sdk/*` to its CJS dist because the SDK's exports map is unresolvable.
-- **Coverage is a per-domain ratchet over `src/nest/**`** (≥80% floor, most domains pinned higher). Regenerate the block with `scripts/coverage-thresholds.mjs` when coverage rises; never lower a threshold to land a change.
+- **Coverage is a per-domain ratchet over `src/nest/**`** (≥80% floor, most domains pinned higher). Regenerate the block with `scripts/coverage-thresholds.mjs` when coverage rises; never lower a threshold to land a change. Every folder under `src/nest/` needs its own entry (a new domain too): `tests/unit/coverage-thresholds.test.ts` fails on one that falls through to the pooled `src/nest/**` catch-all.
- CI also runs SonarCloud on the PR's new lines — see the root `CLAUDE.md`.
## Parity discipline (when adding or changing routes)
diff --git a/server/tests/unit/coverage-thresholds.test.ts b/server/tests/unit/coverage-thresholds.test.ts
new file mode 100644
index 000000000..56e551596
--- /dev/null
+++ b/server/tests/unit/coverage-thresholds.test.ts
@@ -0,0 +1,61 @@
+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);
+ }
+ }
+ });
+});
diff --git a/server/vitest.config.ts b/server/vitest.config.ts
index d6536a3a9..bf730a163 100644
--- a/server/vitest.config.ts
+++ b/server/vitest.config.ts
@@ -108,12 +108,24 @@ export default defineConfig({
'src/nest/feeds/**/*.ts': { statements: 91, branches: 83, functions: 83, lines: 91 },
'src/nest/files/**/*.ts': { statements: 97, branches: 95, functions: 99, lines: 98 },
'src/nest/geo/**/*.ts': { statements: 99, branches: 95, functions: 99, lines: 99 },
+ // google-quota, managed, mcp-shared, mcp-transport, public-api,
+ // receipt-scan, route-usage, scheduling, school-holidays, tokens and tours
+ // sat on the 80 catch-all until 2026-10-08. Each is pinned at
+ // floor(measured) - 1 over the unit, integration and e2e suites that load
+ // it, a subset a full run can only measure higher. managed holds an empty
+ // module and nothing to count. mcp-shared and route-usage measure below
+ // the 80 floor on branches and functions and are pinned where they are.
+ // tests/unit/coverage-thresholds.test.ts fails on a domain without an entry.
+ 'src/nest/google-quota/**/*.ts': { statements: 99, branches: 99, functions: 99, lines: 99 },
'src/nest/health/**/*.ts': { statements: 99, branches: 65, functions: 99, lines: 99 },
'src/nest/help/**/*.ts': { statements: 81, branches: 70, functions: 99, lines: 86 },
'src/nest/integrations/**/*.ts': { statements: 78, branches: 68, functions: 78, lines: 80 },
'src/nest/journey/**/*.ts': { statements: 91, branches: 84, functions: 88, lines: 93 },
'src/nest/llm-parse/**/*.ts': { statements: 91, branches: 85, functions: 85, lines: 94 },
+ 'src/nest/managed/**/*.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'src/nest/maps/**/*.ts': { statements: 93, branches: 86, functions: 97, lines: 96 },
+ 'src/nest/mcp-shared/**/*.ts': { statements: 84, branches: 59, functions: 99, lines: 88 },
+ 'src/nest/mcp-transport/**/*.ts': { statements: 89, branches: 79, functions: 87, lines: 90 },
'src/nest/memories/**/*.ts': { statements: 92, branches: 83, functions: 97, lines: 94 },
'src/nest/notifications/**/*.ts': { statements: 83, branches: 72, functions: 85, lines: 87 },
'src/nest/oauth/**/*.ts': { statements: 96, branches: 95, functions: 97, lines: 97 },
@@ -137,8 +149,10 @@ export default defineConfig({
'src/nest/places/**/*.ts': { statements: 91, branches: 82, functions: 96, lines: 94 },
'src/nest/platform/**/*.ts': { statements: 99, branches: 99, functions: 99, lines: 99 },
'src/nest/plugins/**/*.ts': { statements: 86, branches: 81, functions: 78, lines: 89 },
+ 'src/nest/public-api/**/*.ts': { statements: 97, branches: 86, functions: 99, lines: 99 },
'src/nest/query-helpers/**/*.ts': { statements: 90, branches: 75, functions: 99, lines: 92 },
'src/nest/realtime/**/*.ts': { statements: 99, branches: 100, functions: 99, lines: 99 },
+ 'src/nest/receipt-scan/**/*.ts': { statements: 99, branches: 99, functions: 99, lines: 99 },
'src/nest/reservation-import/**/*.ts': { statements: 61, branches: 55, functions: 41, lines: 61 },
'src/nest/reservations/**/*.ts': { statements: 92, branches: 83, functions: 96, lines: 96 },
// New domain in this change. Measured over its own suites at
@@ -149,12 +163,17 @@ export default defineConfig({
// hiding in the 80 catch-all, where 557 new lines could shed twenty
// points against the headroom of the domains beside them.
'src/nest/roadtrip/**/*.ts': { statements: 88, branches: 80, functions: 95, lines: 95 },
+ 'src/nest/route-usage/**/*.ts': { statements: 84, branches: 66, functions: 77, lines: 83 },
+ 'src/nest/scheduling/**/*.ts': { statements: 99, branches: 92, functions: 99, lines: 99 },
+ 'src/nest/school-holidays/**/*.ts': { statements: 97, branches: 95, functions: 99, lines: 97 },
'src/nest/settings/**/*.ts': { statements: 87, branches: 71, functions: 99, lines: 88 },
'src/nest/share/**/*.ts': { statements: 97, branches: 87, functions: 99, lines: 99 },
'src/nest/storage/**/*.ts': { statements: 94, branches: 84, functions: 97, lines: 94 },
'src/nest/system-notices/**/*.ts': { statements: 99, branches: 99, functions: 99, lines: 99 },
'src/nest/tags/**/*.ts': { statements: 97, branches: 89, functions: 99, lines: 99 },
'src/nest/todo/**/*.ts': { statements: 90, branches: 82, functions: 99, lines: 99 },
+ 'src/nest/tokens/**/*.ts': { statements: 99, branches: 97, functions: 99, lines: 99 },
+ 'src/nest/tours/**/*.ts': { statements: 95, branches: 92, functions: 99, lines: 97 },
'src/nest/transit/**/*.ts': { statements: 92, branches: 83, functions: 97, lines: 94 },
'src/nest/trip-invite/**/*.ts': { statements: 91, branches: 93, functions: 93, lines: 89 },
'src/nest/trip-membership/**/*.ts': { statements: 99, branches: 86, functions: 99, lines: 99 },