Name the Local area, say what each News section needs, and credit its sources

Local reads the area at the view centre (`/outline?at=`) and asks the feed
for its reports (`at`): the area is outlined faintly on the globe and named
at the top of the section ("News from Kazakhstan"; within 500 km at sea).
A disputed area is named as itself. A read that a newer look replaced, or
one left behind by a switch to Conflicts, is dropped, and a server without
the area route is asked once.

A section read from a key the server lacks says which key it needs
(503 `no_key`), that the key was refused (`key_rejected`) or that its
daily allowance is spent (`key_quota`); the other section keeps reading.
Liveuamap and World News API join the key registry.

Cards name the service a report came through ("via GDELT Project"), and
Liveuamap and Natural Earth are credited once their data shows. Economy is
a category of its own. Disputed-area labels are smaller and show the name
only; outlines keep up to 300 parts.
This commit is contained in:
Denis Groshev committed 2026-11-06 00:45:31 +01:00
1 parent fa736a7cd5
commit edb5837ae5
27 files changed
+1343 -154

No files matched your search

+52
View File
@@ -54,6 +54,8 @@ test('reads validated hotspots, feed and outlines from the same-origin routes',
assert.deepEqual((await source.getOutline('ua')).polygons, []);
await source.getCountryOutline('SD');
await source.getHotspots({ hours: 6 });
await source.getAreaOutline({ lat: 30.26666, lon: -97.7 });
await source.getFeed({ hotspot: 'all', at: { lat: 30.26666, lon: -97.7 } });
assert.deepEqual(
calls.map((c) => c.url),
[
@@ -62,6 +64,8 @@ test('reads validated hotspots, feed and outlines from the same-origin routes',
'/api/news/outline?hotspot=ua&v=4',
'/api/news/outline?country=SD&v=4',
'/api/news/hotspots?hours=6',
'/api/news/outline?at=30.27,-97.7&v=4',
'/api/news/feed?hotspot=all&at=30.27%2C-97.7',
],
);
for (const { url, init } of calls) {
@@ -112,6 +116,50 @@ test('malformed, failed and unconfigured reads reject; a server without news is
await assert.rejects(broken.getHotspots(), SyntaxError);
});
test('a section read from a key the server lacks names the key and is asked again', async () => {
const answer = (body) =>
createNewsSource({
fetchImpl: async () =>
new Response(JSON.stringify(body), {
status: 503,
headers: { 'Content-Type': 'application/json' },
}),
});
await assert.rejects(
answer({ error: 'no_key', key: 'liveuamap' }).getHotspots(),
(error) => {
assert.equal(error.keyRequired, true);
assert.equal(error.keyRejected, false);
assert.equal(error.keyId, 'liveuamap');
assert.equal(error.unavailable, false);
assert.equal(error.retryable, true);
return true;
},
);
await assert.rejects(
answer({ error: 'key_rejected', key: 'worldnewsapi' }).getFeed({
at: { lat: 51.13, lon: 71.43 },
}),
{ keyRequired: true, keyRejected: true, keyId: 'worldnewsapi' },
);
// The day's allowance spent: still the key's matter, back tomorrow.
await assert.rejects(
answer({ error: 'key_quota', key: 'worldnewsapi' }).getFeed(),
{
keyRequired: true,
keyRejected: false,
keyQuota: true,
keyId: 'worldnewsapi',
unavailable: false,
},
);
// A key name not in the registry's form is an ordinary failure.
await assert.rejects(
answer({ error: 'no_key', key: '<script>' }).getHotspots(),
(error) => error.keyRequired === undefined && error.code === 'http',
);
});
test('reads time out and follow the caller signal', async () => {
// AbortSignal.timeout does not hold the event loop open: the hanging fetch
// does, until its signal aborts, so the run cannot end before it.
@@ -174,6 +222,10 @@ test('the host allowlist admits the client routes and refuses anything else', ()
'/api/news/outline?hotspot=ua',
'/api/news/outline?hotspot=ua&v=2',
'/api/news/outline?country=ukraine&v=4',
'/api/news/outline?at=30.267,-97.7&v=4',
'/api/news/outline?at=30.27&v=4',
'/api/news/outline?at=30.27,-97.7&country=US&v=4',
'/api/news/feed?at=30.267,-97.7',
])
assert.equal(allowed(path), false, path);
});