feat(vessels): key vessels by their source's stable id, and share a selected vessel

AIS Vessels are keyed by the id their live source gives, with the MMSI as an
attribute: an MMSI can be shared, spoofed or reused, so two vessels with one
MMSI are now two vessels. Looking a vessel up or selecting it by MMSI still
finds it.

A share link made while a vessel is selected opens that vessel. A UUID vessel
id travels as 16 bytes in a new thing field (13). A shared thing that is not
reporting now says so in a sentence per kind, with its id (ICAO, NORAD, MMSI
or vessel UUID) on a second line.
This commit is contained in:
Sameh Khamis committed 2026-11-10 18:12:53 -08:00
1 parent 57ff81f723
commit cbbf55cacd
74 files changed
+2481 -586

No files matched your search

+50
View File
@@ -5,8 +5,10 @@ import { LiveSourceError } from '../../sources/live/contract.js';
import { createVesselSource } from '../../sources/live/standalone.js';
import { AISSTREAM_CACHE_MAX } from '../../../server/providers/vessels/ais-store.js';
// An AIS source's vessel: keyed by its MMSI, which it also reports.
const vessel = (id, latitude, longitude, extra = {}) => ({
id,
mmsi: id,
reference: id,
latitude,
longitude,
@@ -79,6 +81,7 @@ test('vessels in an area are nearest first and filterable by type', async () =>
['366999712', '538001234'],
);
assert.deepEqual(all.data.rows[0], {
id: '366999712',
mmsi: '366999712',
name: 'GOLDEN BEAR',
imo: '9123456',
@@ -164,6 +167,53 @@ test('vessel tracks are ordered and drop untimed positions', async () => {
);
});
test('vessels sharing an MMSI are found as two, each by its own id', async () => {
const shared = [
vessel('hull-a', 37.81, -122.41, { mmsi: '366999712', name: 'A' }),
vessel('hull-b', 37.79, -122.42, {
mmsi: '366999712',
name: 'B',
reference: 'track:hull-b',
}),
vessel('hull-c', 37.8, -122.4, { mmsi: undefined, name: 'C' }),
];
const tracks = [];
const catalog = composeCatalog({
tools: coreTools,
services: {
vessels: {
getSnapshot: async () => ({ records: shared, freshness: 'current' }),
getTrack: async (reference) => {
tracks.push(reference);
return { records: [] };
},
},
},
});
const found = await catalog.call('find_vessel', { mmsi: '366999712' });
assert.deepEqual(
found.data.rows.map((row) => [row.id, row.mmsi]),
[
['hull-a', '366999712'],
['hull-b', '366999712'],
],
);
const area = await catalog.call('vessels_in_area', { area: bay });
assert.deepEqual(
area.data.rows.find((row) => row.id === 'hull-c').mmsi,
null,
'a vessel with no MMSI says so',
);
const track = await catalog.call('get_vessel_track', { id: 'hull-b' });
assert.deepEqual(tracks, ['track:hull-b'], "asked by the vessel's reference");
assert.equal(track.data.id, 'hull-b');
assert.equal(track.summary, 'No recent track is available for hull-b.');
await assert.rejects(
catalog.call('get_vessel_track', { id: 'hull-b', mmsi: '366999712' }),
/exactly one/,
);
});
test('a missing AIS key surfaces as an unavailable feed', async () => {
const keyless = {
getSnapshot: async () => {