Format civil-flight components

This commit is contained in:
Sameh Khamis committed 2026-09-13 09:50:16 -07:00
1 parent 7c7e83c9e3
commit e18aeb8565
16 files changed
+6435 -5086

No files matched your search

+62 -17
View File
@@ -5,16 +5,37 @@ import { createFlightState } from './state.js';
import { createEnrichment } from './enrichment.js';
function services() {
const names = ['picking', 'sprites', 'trails', 'aircraftPresentation', 'camera',
'militaryRegistry', 'labels', 'groundFloor', 'meshFloor', 'geoid', 'focus',
'readout', 'context', 'render', 'recession'];
return { ...Object.fromEntries(names.map((name) => [name, {}])),
groundSnap: { createGroundSnap: () => ({ clear() {} }) } };
const names = [
'picking',
'sprites',
'trails',
'aircraftPresentation',
'camera',
'militaryRegistry',
'labels',
'groundFloor',
'meshFloor',
'geoid',
'focus',
'readout',
'context',
'render',
'recession',
];
return {
...Object.fromEntries(names.map((name) => [name, {}])),
groundSnap: { createGroundSnap: () => ({ clear() {} }) },
};
}
test('constructing independent flight layers performs no source request and isolates selection', () => {
let requests = 0;
const source = { label: 'Fixture aircraft', getSnapshot() { requests++; } };
const source = {
label: 'Fixture aircraft',
getSnapshot() {
requests++;
},
};
const first = createCivilFlightLayer({ source, services: services() });
const second = createCivilFlightLayer({ source, services: services() });
first.testing._armFlightTrackingRestoreForTest('abc123');
@@ -34,8 +55,17 @@ test('a layer without a source fails before touching the viewer', () => {
test('flight state owns distinct mutable records, scratch objects and floor samplers', () => {
const first = createFlightState({ services: services() });
const second = createFlightState({ services: services() });
for (const key of ['_flightData', '_billboards', '_positionHistory', '_displayFloorState',
'_groundSnap', '_scratchCarto', '_models', '_activeUpdateControllers', 'lifetime']) {
for (const key of [
'_flightData',
'_billboards',
'_positionHistory',
'_displayFloorState',
'_groundSnap',
'_scratchCarto',
'_models',
'_activeUpdateControllers',
'lifetime',
]) {
assert.notEqual(first[key], second[key], key);
}
});
@@ -43,14 +73,22 @@ test('flight state owns distinct mutable records, scratch objects and floor samp
test('aborted enrichment cannot write into a later lifecycle or decrement its active count', async () => {
let resolve;
let signal;
const source = { getEnrichment(query, options) {
signal = options.signal;
return new Promise((done) => { resolve = done; });
} };
const source = {
getEnrichment(query, options) {
signal = options.signal;
return new Promise((done) => {
resolve = done;
});
},
};
const flightState = createFlightState({ source, services: services() });
const enrichment = createEnrichment({ flightState, services: {}, parts: {} });
let writes = 0;
enrichment._enqueueEnrich('test', { kind: 'type', id: 'abc123' }, () => writes++);
enrichment._enqueueEnrich(
'test',
{ kind: 'type', id: 'abc123' },
() => writes++,
);
await Promise.resolve();
assert.equal(flightState._enrichActive, 1);
flightState.lifetime.abort();
@@ -64,11 +102,18 @@ test('aborted enrichment cannot write into a later lifecycle or decrement its ac
});
test('a synchronous enrichment failure stays bounded and releases its slot', async () => {
const flightState = createFlightState({ services: services(), source: {
getEnrichment() { throw new Error('fixture failure'); },
} });
const flightState = createFlightState({
services: services(),
source: {
getEnrichment() {
throw new Error('fixture failure');
},
},
});
const enrichment = createEnrichment({ flightState, services: {}, parts: {} });
assert.doesNotThrow(() => enrichment._enqueueEnrich('test', {}, () => assert.fail()));
assert.doesNotThrow(() =>
enrichment._enqueueEnrich('test', {}, () => assert.fail()),
);
await new Promise((done) => setImmediate(done));
assert.equal(flightState._enrichActive, 0);
});