Files
gods-eye-view/src/layers/earthquakes/edgeCases.test.mjs
T
German Khokhlov 7f478e3815 Remove always-true layer availability and leftover viewer paths
Every layer draws on both engines, so the per-engine availability
machinery always answered yes. The renderer manifest is now the id to
display map plus the wind flow backend; the catalog filter, the voice and
QA-probe refusals and the engine-kind checks go with it. The Navara
notice lists the same layers in the same words.

Paths that read the Cesium viewer behind an engine that is always there
are gone: the Recent Imagery viewer fallbacks, the shell's imagery-host
service (one shared host module remains), the engineless map controller,
viewer gates in voice actions, world packets and camera verbs, the
orientation controls' tracked-entity fallback, and the Bhote Koshi and
FIRMS Cesium-shaped paths. setCameraInputs, which nothing called, leaves
the contract; suspensions remain.

Smaller duplicates go too: one tracker-release helper for navigation and
location, the no-op frame latch, missing-engine guards, one name for the
injected display, flat bikeshare and installations displays, one overlay
host and binder, one name per world-overlay method, and stub-viewer
guards in the Cesium engine. Layers that still read the viewer keep the
shared init(viewer, context) entry.

Behaviour is unchanged on both engines. Viewer lines fall from 849 to
750 and engine-name literals from 32 to 27.
2026-11-08 17:06:01 +04:00

142 lines
4.4 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import * as geo from '../../geo/index.js';
import { createFakeEngine } from '../../globe/testing/fakeEngine.js';
import { isOverlayPointVisible } from '../../overlays/worldOverlay.js';
import {
createEarthquakesLayer,
createEarthquakeOverlayEntry,
normalizeEarthquakeSnapshot,
} from './index.js';
const DAY_MS = 24 * 60 * 60 * 1000;
const GENERATED_MS = Date.UTC(2026, 0, 2, 12);
const feature = (id, lon, lat, mag, time) => ({
id,
type: 'Feature',
geometry: { type: 'Point', coordinates: [lon, lat, 10] },
properties: { mag, place: `Place ${id}`, time },
});
// The USGS all_day feed: one fresh event, one exactly on the window edge
// and one older than the feed's own 24 h window.
const FIXED_SAMPLE = {
type: 'FeatureCollection',
metadata: { generated: GENERATED_MS },
features: [
feature('us-fresh', 10, 20, 4.1, GENERATED_MS - 60_000),
feature('us-edge', 11, 21, 3.2, GENERATED_MS - DAY_MS),
feature('us-expired', 12, 22, 5.5, GENERATED_MS - DAY_MS - 1),
],
};
const WITH_DUPLICATE = {
...FIXED_SAMPLE,
features: [
...FIXED_SAMPLE.features,
feature('us-fresh', 10.5, 20.5, 4.4, GENERATED_MS - 30_000),
],
};
function layerWith(payloads) {
const replaced = [];
const labelSets = [];
const queue = [...payloads];
const layer = createEarthquakesLayer({
source: {
async getSnapshot() {
const rows = normalizeEarthquakeSnapshot(queue.shift());
if (!rows) throw new Error('Malformed USGS response');
return rows;
},
},
overlayHost: {
setEntries(_source, entries) {
labelSets.push(entries.map((entry) => entry.id));
},
setVisible() {},
clearSource() {},
},
rendererFactory: () => ({
setVisible() {},
replace(discs) {
replaced.push(discs.map((disc) => disc.stableId));
},
destroy() {},
}),
});
return { layer, replaced, labelSets };
}
test('edge:earthquakes: an expired record is dropped and a duplicate never forks the ID set', async () => {
assert.deepEqual(
normalizeEarthquakeSnapshot(FIXED_SAMPLE).map((row) => row.stableId),
['us-fresh', 'us-edge'],
);
// A duplicate ID is a malformed feed: it is rejected whole so the last good
// snapshot (one disc per ID) stays on screen with the source error shown.
assert.equal(normalizeEarthquakeSnapshot(WITH_DUPLICATE), null);
const { layer, replaced, labelSets } = layerWith([
FIXED_SAMPLE,
WITH_DUPLICATE,
]);
layer.init(null, { engine: {} });
layer.enable();
assert.equal(await layer.update(), true);
assert.equal(await layer.update(), false);
const ids = ['us-fresh', 'us-edge'];
assert.deepEqual(replaced, [ids]);
assert.deepEqual(labelSets.at(-1).toSorted(), ids.toSorted());
assert.deepEqual(
layer.getAnalystRecords().map((row) => row.id),
ids,
);
assert.equal(layer.getStats().count, 2);
assert.match(layer.getStats().error, /Malformed/);
layer.destroy();
});
test('edge:earthquakes: near the horizon the label of the same ID is kept in front and culled behind', () => {
const engine = createFakeEngine();
// 1000 km over (0, 0) looking east at the limb, which lies ~30.2° away.
engine.camera.setView({
destination: geo.cartesian3.fromDegrees(0, 0, 1_000_000),
orientation: { heading: Math.PI / 2, pitch: -0.52, roll: 0 },
});
const occluder = {
isPointVisible: (position) => engine.projector.horizonVisible(position),
};
const viewport = engine.host.size();
const rows = normalizeEarthquakeSnapshot({
features: [
feature('us-front', 29.5, 0, 4.5, null),
feature('us-behind', 31.5, 0, 4.5, null),
],
});
const visible = rows
.map((row) =>
createEarthquakeOverlayEntry({
id: row.stableId,
position: geo.cartesian3.fromDegrees(row.lon, row.lat),
magnitude: row.mag,
accent: '#f00',
}),
)
.filter((entry) => {
const screen = engine.projector.worldToWindow(entry.position, {});
// Both anchors project inside the viewport; only the horizon separates them.
assert.ok(screen && screen.x > 0 && screen.x < viewport.width);
return isOverlayPointVisible(
entry,
entry.position,
screen,
viewport,
occluder,
);
})
.map((entry) => entry.id);
assert.deepEqual(visible, ['us-front']);
});