fix(traffic): flag stale cached TomTom tiles in get_traffic_flow (#1239)

Report stale traffic tiles and their fetch time, and release pending freshness metadata when tile requests fail or are cancelled.

Contribution by @quanticsoul4772.
This commit is contained in:
quanticsoul4772 authored and GitHub committed 2026-10-25 08:26:26 -07:00
1 parent f6e7f63a63
commit 6bbf9b94c4
8 files changed
+299 -18

No files matched your search

+11
View File
@@ -473,11 +473,22 @@ export const getTrafficFlow = defineTool({
: `No live traffic is reported in ${area.label}.`) +
(flow.partial
? ' Some map tiles did not load, so these figures are partial.'
: '') +
// Past the daily TomTom budget, or while TomTom fails, the proxy
// serves its last copy of a tile however old it is.
(flow.stale
? ' Some tiles are cached copies' +
(isoTime(flow.oldestTileAt)
? `, the oldest from ${isoTime(flow.oldestTileAt)}`
: '') +
', so traffic may be out of date.'
: ''),
data: {
view: suggestView(services, { area, layers: ['traffic'] }),
area: area.label,
partial: flow.partial,
stale: flow.stale === true,
oldest_tile_at: isoTime(flow.oldestTileAt),
speed_pct_of_free_flow: speedPct,
measured_km: round(measuredKm, 1),
congested_km: round(congestedKm, 1),
+41
View File
@@ -555,6 +555,47 @@ test('traffic counts only roads inside a radius area and reports missing tiles',
assert.match(partial.summary, /Some map tiles did not load/);
});
test('traffic says when the proxy served cached tiles, and how old the oldest is', async () => {
const road = [
{
coords: [
[-0.2, 0],
[0.2, 0],
],
trafficLevel: 0.9,
},
];
const call = (detail) =>
composeCatalog({
tools: coreTools,
services: {
traffic: {
getStatus: async () => ({ hasKey: true }),
fetchFlowDetail: async () => ({
segments: road,
partial: false,
...detail,
}),
},
},
}).call('get_traffic_flow', { area: { lat: 0, lon: 0, radius_km: 10 } });
const oldest = Date.UTC(2026, 9, 16, 8);
const stale = await call({ stale: true, oldestTileAt: oldest });
assert.equal(stale.data.stale, true);
assert.equal(stale.data.oldest_tile_at, '2026-10-16T08:00:00.000Z');
assert.match(
stale.summary,
/cached copies, the oldest from 2026-10-16T08:00:00\.000Z, so traffic may be out of date\./,
);
const live = await call({ stale: false, oldestTileAt: oldest });
assert.equal(live.data.stale, false);
assert.doesNotMatch(live.summary, /out of date/);
// A source that can't tell (no freshness fields) isn't reported as stale.
const unknown = await call({});
assert.equal(unknown.data.stale, false);
assert.equal(unknown.data.oldest_tile_at, null);
});
test('a whole-world bike-share search names every system it skipped', async () => {
const empty = { data: { stations: [] } };
const result = await composeCatalog({