fix(flights): class an aircraft by its feed's type from the first fix

A civil aircraft was drawn as an airliner until its type lookup answered,
even when its feed already named the type: a helicopter showed the
airliner icon and model for as long as the lookup took.

- Flights classes every contact, and picks its model, by the feed's own
  ICAO type designator from the first fix. A looked-up type replaces it
  once the lookup answers and outranks the feed's on every later poll;
  the lookup still runs and fills the type name and registration.
- A surface emitter category still keeps only a ground type (ZVEH, GRND)
  from the feed.
- State vectors have no type field, so an /api/flights answer may send
  `typeByIcao` beside them, by ICAO address, as `emergencyByIcao` is sent.
  The regional adsb.lol fallback now sends it from each row's `t`.
This commit is contained in:
Sameh Khamis committed 2026-11-17 17:37:48 -08:00
1 parent 2f0c01eaa7
commit f2537743ab
9 files changed
+205 -24

No files matched your search

+72
View File
@@ -608,3 +608,75 @@ test('a route answer for a callsign the plane no longer flies is dropped', async
assert.equal(meta.routeCallsign, 'UAL10');
flightState.lifetime.abort();
});
test("a type lookup overrides the feed's type and fills the type name", async () => {
const queries = [];
const source = {
getEnrichment(query) {
queries.push(query);
return Promise.resolve({
found: true,
typeCode: 'B738',
typeName: 'Boeing 737-800',
registration: 'N123AB',
});
},
};
const flightState = createFlightState({ source, services: services() });
const view = {
viewerLatDeg: null,
viewerLonDeg: null,
trackedId: null,
floorWarmPoints: [],
};
const { meta } = flightState.records.receive(
{
id: 'abc123',
reference: 'abc123',
longitude: -77,
latitude: 39,
callsign: 'TEST1',
baroAltitudeM: 1000,
typeCode: 'EC45',
},
view,
);
assert.equal(meta.klass, 'helicopter', 'classed by the feed type at once');
const restyled = [];
const synced = [];
const enrichment = createEnrichment({
flightState,
services: enrichServices(),
parts: {
icons: { _applyIconPresentation: (id) => restyled.push(id) },
rendering: { _syncModelToClass: (id) => synced.push(id) },
},
});
// A present feed type does not skip the lookup.
enrichment._requestTypeEnrichment('abc123', true);
await new Promise((done) => setImmediate(done));
assert.deepEqual(queries, [{ kind: 'type', id: 'abc123' }]);
const looked = flightState.records.data.get('abc123');
assert.equal(looked.typeCode, 'B738');
assert.equal(looked.typeName, 'Boeing 737-800');
assert.equal(looked.registration, 'N123AB');
assert.equal(looked.klass, 'airliner');
assert.deepEqual(restyled, ['abc123']);
assert.deepEqual(synced, ['abc123']);
// The next poll's feed type no longer wins.
const next = flightState.records.receive(
{
id: 'abc123',
reference: 'abc123',
longitude: -77,
latitude: 39,
callsign: 'TEST1',
baroAltitudeM: 1000,
typeCode: 'EC45',
},
view,
).meta;
assert.equal(next.typeCode, 'B738');
assert.equal(next.klass, 'airliner');
flightState.lifetime.abort();
});