fix(shipwrecks): the page expires each source's wrecks by its own clock, from the age the proxy reports

The page compared the proxy's fetchedAt with its own clock, so a skewed
browser clock cleared or kept wrecks wrongly; a snapshot without a timestamp
never expired; and one old source cleared the other's fresh wrecks. The proxy
now reports each source's age on its own clock and its seven-day limit; the
page turns them into per-source deadlines when the snapshot arrives (seven
days from arrival when no age is given) and, on a failed refresh, removes only
the sources past theirs. A refused short refresh is logged.
This commit is contained in:
Sameh Khamis committed 2026-11-10 13:38:31 -08:00
1 parent 6e4dd6299e
commit 7704de5075
6 files changed
+119 -8

No files matched your search

+57
View File
@@ -291,3 +291,60 @@ test('a failed refresh marks the shown wrecks stale, and clears them after seven
assert.equal(h.layer.getStats().count, 0, 'expired wrecks leave the map');
assert.equal(h.markers.billboards.length, 0);
});
test('expiry runs on the page clock, per source, even without timestamps', async () => {
const DAY = 24 * 60 * 60 * 1000;
const down = () => new Error('Shipwrecks unavailable (HTTP 502)');
// A page clock far from the proxy's: only the reported ages count.
let clock = 5e12;
const h = harness({
now: () => clock,
snapshots: [
{
...snapshot([
wreck('fresh', { source: 'emodnet' }),
wreck('old', { source: 'wikidata' }),
]),
fetchedAt: null,
ages: { emodnet: 0, wikidata: 6.5 * DAY },
maxAgeMs: 7 * DAY,
},
down(),
down(),
down(),
],
});
h.layer.enable();
await h.layer.update();
clock += 0.25 * DAY;
await h.layer.update();
assert.equal(h.layer.getStats().count, 2, 'both still inside their limit');
clock += 0.5 * DAY;
await h.layer.update();
assert.deepEqual(
h.markers.billboards.map((billboard) => billboard.id),
['shipwreck:fresh'],
'only the source past its limit leaves',
);
assert.equal(h.layer.getStats().stale, true);
clock += 7 * DAY;
await h.layer.update();
assert.equal(h.layer.getStats().count, 0);
});
test('a snapshot with no timestamp or ages still expires seven days after it arrived', async () => {
const DAY = 24 * 60 * 60 * 1000;
let clock = 100;
const h = harness({
now: () => clock,
snapshots: [
{ ...snapshot([wreck('a')]), fetchedAt: null },
new Error('down'),
],
});
h.layer.enable();
await h.layer.update();
clock += 8 * DAY;
await h.layer.update();
assert.equal(h.layer.getStats().count, 0);
});