Fix airline code-collision mismatch (FOX→Flyr); consistency-aware matching #19

Merged
ronnyandre merged 1 commit from fix/airline-code-collision into main 2026-06-03 11:27:25 +02:00
Owner

Fixes the issue you hit: an FR24 flight on Flyr (IATA FS, ICAO FOX) was linked to the seeded FOX Linhas Aéreas (IATA FX, ICAO FOX) — a reused ICAO that the old ICAO-first lookup matched despite the IATA conflicting.

Root cause: neither IATA nor ICAO is unique in the seed — OpenFlights airlines.dat is frozen ~2014, keeps defunct carriers, and codes get reused (34 ICAO + 7 (IATA,ICAO) collisions; Flyr isnt in the seed at all). Verified in the seed DB.

Fix: new pure, unit-tested src/lib/airline-match.ts#pickAirline, used by both resolveAirline (import) and buildPrefill (enrichment):

  1. exact both-code match;
  2. single-code match, rejected if the other code conflicts — unless the airline names corroborate (distinguishes a stale code on the same airline from a reused code on a different one).

Verified against the real seed:

  • Flyr (FS/FOX) → freeform "Flyr" ✓ (was: wrong link)
  • Norwegian Air Shuttle (DY/NOZ) → still links to seeded (DY/NAX) ✓ (name corroboration prevents a regression — the first naive cut broke this)
  • D8 / SAS / FOX Linhas itself → correct

Existing flights are unaffected — the resolved airline_id/freeform is pinned per row (so your manual fix stands). 52 tests pass (10 new for pickAirline). CLAUDE.md pattern #2 updated.

pnpm typecheck/lint/test green.

Fixes the issue you hit: an FR24 flight on **Flyr (IATA FS, ICAO FOX)** was linked to the seeded **FOX Linhas Aéreas (IATA FX, ICAO FOX)** — a reused ICAO that the old ICAO-first lookup matched despite the IATA conflicting. **Root cause:** neither IATA nor ICAO is unique in the seed — OpenFlights `airlines.dat` is frozen ~2014, keeps defunct carriers, and codes get reused (34 ICAO + 7 (IATA,ICAO) collisions; Flyr isnt in the seed at all). Verified in the seed DB. **Fix:** new pure, unit-tested `src/lib/airline-match.ts#pickAirline`, used by both `resolveAirline` (import) and `buildPrefill` (enrichment): 1. exact both-code match; 2. single-code match, **rejected if the other code conflicts** — *unless the airline names corroborate* (distinguishes a stale code on the same airline from a reused code on a different one). **Verified against the real seed:** - Flyr `(FS/FOX)` → freeform "Flyr" ✓ (was: wrong link) - Norwegian Air Shuttle `(DY/NOZ)` → still links to seeded `(DY/NAX)` ✓ (name corroboration prevents a regression — the first naive cut broke this) - D8 / SAS / FOX Linhas itself → correct Existing flights are unaffected — the resolved `airline_id`/freeform is pinned per row (so your manual fix stands). 52 tests pass (10 new for `pickAirline`). CLAUDE.md pattern #2 updated. `pnpm typecheck`/`lint`/`test` green.
Neither IATA nor ICAO is unique in the seed (OpenFlights is frozen ~2014 and
reuses codes across defunct carriers). The old ICAO-first lookup matched FR24's
ICAO FOX (Flyr) to the seeded FOX Linhas Aereas despite the IATA conflicting
(FS vs FX).

New src/lib/airline-match.ts (pure, unit-tested) resolves via: exact both-code
match, then single-code match that's rejected on a conflicting other code
UNLESS the airline names corroborate. This fixes:
- FOX→Flyr: ICAO reused, names differ → freeform 'Flyr' (was: wrong link)
- Norwegian: seed has stale ICAO NAX vs export NOZ, but IATA + names match →
  still links (no regression)
- D8: both-code match picks the right Norwegian/Djibouti row

Wired into both resolveAirline (import-fr24) and buildPrefill (enrichment).
Existing flights are unaffected (resolved FK/freeform is pinned per row).
Updated CLAUDE.md pattern #2.
ronnyandre deleted branch fix/airline-code-collision 2026-06-03 11:27:26 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ronnyandre/fliary!19
No description provided.