mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
The satellites layer now sorts every object into Stations, Imaging, Telecom, Starlink, Probes or Debris, each with a chip and a live count on the layer row. Stations and Imaging show by default; the Starlink chip is the former DENSE catalog switch. Hidden classes keep their points, so a toggle needs no reload, and they leave the detection overlay and the voice position lists. A class comes, strongest evidence first, from CelesTrak SATCAT (object type and status, served by a new /api/celestrak-satcat/<group> proxy route and cached for a day), the bundled UCS Satellite Database pack (operator, owner country and purpose), name patterns for later launches, and the CelesTrak group. The core catalog also reads the resource, weather, planet, sar and science groups. Payloads with no evidence of life launched 20 or more years ago are filed as debris. The UCS pack, its build script and its data credit are added.
188 lines
5.5 KiB
JavaScript
188 lines
5.5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { twoline2satrec } from 'satellite.js';
|
|
import { createSatelliteSource } from './source.js';
|
|
import { createSatellitesLayer } from './index.js';
|
|
|
|
test('satellite sources confine catalog groups and reject a cancelled body', async () => {
|
|
const controller = new AbortController();
|
|
let requests = 0;
|
|
const source = createSatelliteSource({
|
|
fetchImpl: async (url) => {
|
|
requests++;
|
|
assert.equal(url, '/api/celestrak/stations');
|
|
return {
|
|
ok: true,
|
|
status: 200,
|
|
text: async () => {
|
|
controller.abort();
|
|
return 'late catalog';
|
|
},
|
|
};
|
|
},
|
|
});
|
|
await assert.rejects(
|
|
source.readGroup('../active'),
|
|
/Unknown satellite group/,
|
|
);
|
|
assert.equal(requests, 0);
|
|
await assert.rejects(
|
|
source.readGroup('stations', { signal: controller.signal }),
|
|
{ name: 'AbortError' },
|
|
);
|
|
});
|
|
|
|
test('satellite factories keep control state separate and construct without requests', () => {
|
|
const source = {
|
|
readGroup() {
|
|
assert.fail('construction fetched a catalog');
|
|
},
|
|
};
|
|
const services = Object.fromEntries(
|
|
[
|
|
'picking',
|
|
'focus',
|
|
'readout',
|
|
'overlays',
|
|
'context',
|
|
'render',
|
|
'layerState',
|
|
].map((key) => [key, {}]),
|
|
);
|
|
services.layerState.isExplicitLayerStateOrigin = () => false;
|
|
const first = createSatellitesLayer({ source, services });
|
|
const second = createSatellitesLayer({ source, services });
|
|
first.setParams({ showPoints: false });
|
|
assert.equal(first.getParams().showPoints, false);
|
|
assert.equal(second.getParams().showPoints, true);
|
|
assert.notEqual(first.getStats(), second.getStats());
|
|
});
|
|
|
|
test('satellite pass prediction methods report no-tle on cold catalog and coerce IDs', () => {
|
|
const source = { readGroup() {} };
|
|
const services = Object.fromEntries(
|
|
[
|
|
'picking',
|
|
'focus',
|
|
'readout',
|
|
'overlays',
|
|
'context',
|
|
'render',
|
|
'layerState',
|
|
].map((key) => [key, {}]),
|
|
);
|
|
services.layerState.isExplicitLayerStateOrigin = () => false;
|
|
const layer = createSatellitesLayer({ source, services });
|
|
|
|
// Cold catalog (no satellites loaded yet)
|
|
assert.deepEqual(layer.getNextIssPass({ latDeg: 30, lonDeg: -97 }), {
|
|
status: 'no-tle',
|
|
});
|
|
assert.deepEqual(
|
|
layer.getNextSatellitePass(25544, { latDeg: 30, lonDeg: -97 }),
|
|
{ status: 'no-tle' },
|
|
);
|
|
|
|
// String NORAD ID coercion
|
|
assert.deepEqual(
|
|
layer.getNextSatellitePass('25544', { latDeg: 30, lonDeg: -97 }),
|
|
{ status: 'no-tle' },
|
|
);
|
|
|
|
// Invalid / non-finite ID handling
|
|
assert.deepEqual(
|
|
layer.getNextSatellitePass(NaN, { latDeg: 30, lonDeg: -97 }),
|
|
{ status: 'no-tle' },
|
|
);
|
|
assert.deepEqual(
|
|
layer.getNextSatellitePass(null, { latDeg: 30, lonDeg: -97 }),
|
|
{ status: 'no-tle' },
|
|
);
|
|
|
|
// Populated catalog: verify numeric and string coercion succeed
|
|
const L1 =
|
|
'1 25544U 98067A 08264.51782528 -.00002182 00000-0 -11606-4 0 2927';
|
|
const L2 =
|
|
'2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537';
|
|
const satrec = twoline2satrec(L1, L2);
|
|
layer._setTrackedSatelliteRefreshStateForTest({
|
|
noradId: 25544,
|
|
name: 'ISS (ZARYA)',
|
|
satrec,
|
|
});
|
|
|
|
const FROM_MS = 1221868800000;
|
|
const numericResult = layer.getNextSatellitePass(25544, {
|
|
latDeg: 30.2672,
|
|
lonDeg: -97.7431,
|
|
fromMs: FROM_MS,
|
|
});
|
|
assert.equal(numericResult.status, 'ok');
|
|
assert.ok(numericResult.pass);
|
|
|
|
const stringResult = layer.getNextSatellitePass('25544', {
|
|
latDeg: 30.2672,
|
|
lonDeg: -97.7431,
|
|
fromMs: FROM_MS,
|
|
});
|
|
assert.equal(stringResult.status, 'ok');
|
|
assert.deepEqual(stringResult, numericResult);
|
|
|
|
const issResult = layer.getNextIssPass({
|
|
latDeg: 30.2672,
|
|
lonDeg: -97.7431,
|
|
fromMs: FROM_MS,
|
|
});
|
|
assert.equal(issResult.status, 'ok');
|
|
assert.deepEqual(issResult, numericResult);
|
|
|
|
layer._setTrackedSatelliteRefreshStateForTest({
|
|
noradId: 25544,
|
|
name: 'ISS (ZARYA)',
|
|
satrec,
|
|
neighbours: [
|
|
{ noradId: 10, name: 'STARLINK ONE', satrec },
|
|
{ noradId: 11, name: 'STARLINK TWO', satrec },
|
|
],
|
|
});
|
|
assert.equal(layer.resolveSatelliteForPass('25544').noradId, 25544);
|
|
assert.equal(layer.resolveSatelliteForPass('iss (zarya)').noradId, 25544);
|
|
assert.equal(layer.resolveSatelliteForPass('starlink').status, 'ambiguous');
|
|
assert.equal(layer.resolveSatelliteForPass('starlink').totalMatches, 2);
|
|
assert.equal(layer.resolveSatelliteForPass('STARLINK ONE').noradId, 10);
|
|
assert.equal(layer.resolveSatelliteForPass('missing').status, 'not-found');
|
|
layer._clearDenseCatalogStateForTest();
|
|
assert.equal(layer.resolveSatelliteForPass('25544').status, 'not-found');
|
|
|
|
// Non-existent satellite ID in populated catalog
|
|
assert.deepEqual(
|
|
layer.getNextSatellitePass(99999, {
|
|
latDeg: 30.2672,
|
|
lonDeg: -97.7431,
|
|
fromMs: FROM_MS,
|
|
}),
|
|
{ status: 'no-tle' },
|
|
);
|
|
});
|
|
|
|
test('a SATCAT read says when the proxy served its last copy', async () => {
|
|
const headers = (cache) => ({
|
|
get: (name) => (name === 'x-satcat-cache' ? cache : null),
|
|
});
|
|
let cache = 'STALE-ERROR';
|
|
const source = createSatelliteSource({
|
|
fetchImpl: async (url) => {
|
|
assert.equal(url, '/api/celestrak-satcat/visual');
|
|
return {
|
|
ok: true,
|
|
status: 200,
|
|
headers: headers(cache),
|
|
text: async () => 'OBJECT_NAME,NORAD_CAT_ID,OBJECT_TYPE',
|
|
};
|
|
},
|
|
});
|
|
assert.equal((await source.readSatcat('visual')).stale, true);
|
|
cache = 'HIT';
|
|
assert.equal((await source.readSatcat('visual')).stale, false);
|
|
});
|