Files
TREK/server/tests/setup.console-noise.ts
Maurice 9c46f31c57 refactor(server): fold airports and distance, drop the boot-time backfill cycle (#1834)
Two thirds of be-weather-airports-fold. weatherService (513 LOC, a process
cache and a setInterval at import) is left for its own PR.

airportService split along the line that was already there. The dataset lookup
touches no database — it reads one JSON file and keeps it in memory — and both
MCP registrars call it from outside the container, so findByIata/searchAirports
are free functions in nest/airports/airports.data.ts. backfillFlightEndpoints
needs the connection and became a method on AirportsService.

That backfill was the interesting part. db/database.ts ran it at module eval
through a bare require() back into services/, so the module graph closed a cycle
that only held because `db` happened to be initialised by the time the require
resolved. It runs in onApplicationBootstrap now: it repairs rows, nothing boots
on it, and the container is fully built by then.

The cycle had a visible cost. tests/setup.console-noise.ts carried a suppression
for `Cannot find module '../services/airportService'`, because vitest's
transform pipeline could not resolve that require at all — it fired in roughly
sixty test files. That suppression is now narrowed to the only case left: an e2e
TestingModule whose fixture DB has no reservations table.

distanceService split the same way: haversineKm is arithmetic and moved to
common/geo.ts; getFlightDistanceKm reads the database and became a private
method on AuthService, its only caller.

AirportsModule imports DatabaseModule explicitly. @Global only reaches modules
that are in the graph, and the airports e2e builds its container from
AirportsModule alone — exactly the trap the nest README now documents.

The search ranking gets its first direct tests. It sat in services/, outside the
coverage gate, and only ever ran incidentally through the route; moving it into
src/nest made the gap measurable (16% branches). The ten cases pin the scoring
ladder — exact IATA short-circuit, ICAO over prefix, IATA prefix over city
prefix, city prefix over substring — and the missing-dataset fallback, which no
test had reached. 90% branches now.
2026-08-07 21:07:14 +02:00

43 lines
2.3 KiB
TypeScript

// Filters *expected* noise off the test console so real failures stay visible
// in CI logs (a green run used to emit ~8k stderr lines, burying anything real).
// Scope is deliberately narrow: each pattern below is an artifact of the test
// environment, not of the code under test, and is matched on both the exact
// message head and the specific error. Everything else passes through verbatim
// — an unexpected migration failure or backfill error still prints.
//
// 1. `[migrations] Non-fatal migration step failed:` + `duplicate column
// name: …` — test suites build a fresh :memory: DB via createTables()
// (already-current schema) and then runMigrations() replays historical
// steps against it; some suites additionally re-run migrations on purpose.
// Unguarded ALTER TABLE steps collide with columns the current schema
// already has (which column varies by suite). Production migrates
// incrementally and never replays steps against a current schema; guarding
// the steps in src/ would change production output, so the replay artifact
// is filtered here instead. Non-duplicate-column step failures still print.
// 2. `[DB] Flight endpoint backfill failed:` + `no such table` — the backfill
// runs on application bootstrap now, so it fires in e2e TestingModules whose
// fixture DB has no reservations table. It used to be a module-eval require()
// in database.ts that vitest could not resolve at all, in ~60 files; this is
// the same suppression, narrowed to what actually still happens.
const MIGRATION_WARN_HEAD = '[migrations] Non-fatal migration step failed:';
const DUPLICATE_COLUMN = /duplicate column name: /;
const BACKFILL_ERROR_HEAD = '[DB] Flight endpoint backfill failed:';
const BACKFILL_TABLE_MISSING = /no such table/;
const errorText = (value: unknown): string =>
value instanceof Error ? value.message : String(value);
const realWarn = console.warn.bind(console);
console.warn = (...args: unknown[]) => {
if (args[0] === MIGRATION_WARN_HEAD && DUPLICATE_COLUMN.test(errorText(args[1]))) return;
realWarn(...args);
};
const realError = console.error.bind(console);
console.error = (...args: unknown[]) => {
if (args[0] === BACKFILL_ERROR_HEAD && BACKFILL_TABLE_MISSING.test(errorText(args[1]))) return;
realError(...args);
};