fix: report stale transit feeds and drop expired positions

get_transit_vehicles returned positions from a feed the proxy served from
its error cache, and hour-old fixes, as current. It now applies the transit
layer's rules: a feed is stale when the proxy says so or the operator has
not answered recently, and fixes older than the vehicle limit are dropped
and counted.
This commit is contained in:
Sameh Khamis committed 2026-10-02 15:21:36 -07:00
1 parent 61974848fe
commit 853c60583f
3 files changed
+96 -6

No files matched your search

+35 -1
View File
@@ -177,6 +177,8 @@ const vehicles = [
},
{ id: 'v3', lat: 30.5, lon: -97.6, routeId: '1' },
];
// One minute after v1's fix.
const clock = { now: () => Date.UTC(2026, 0, 1, 0, 1) };
const transit = (
snapshot = { ok: true, status: 200, json: async () => ({ vehicles }) },
) => ({
@@ -197,7 +199,7 @@ test('transit vehicles come from nearby feeds and can be limited to a route', as
const source = transit();
const catalog = composeCatalog({
tools: coreTools,
services: { transit: source },
services: { transit: source, clock },
});
const all = await catalog.call('get_transit_vehicles', { area: downtown });
assert.equal(
@@ -223,6 +225,7 @@ test('transit vehicles come from nearby feeds and can be limited to a route', as
assert.deepEqual(all.data.feeds, [
{
name: 'CapMetro',
status: 'current',
operator: 'Capital Metro',
attribution: 'Capital Metro',
license: 'Open data',
@@ -370,3 +373,34 @@ test('traffic reports a missing key, empty areas and areas that are too wide', a
/too large for traffic detail/,
);
});
test('transit marks stale feeds and drops expired positions', async () => {
const headers = new Headers({ 'x-gev-cache': 'STALE-ERROR' });
const snapshot = (extra) => ({
ok: true,
status: 200,
headers,
json: async () => ({
vehicles: [
vehicles[0],
{ ...vehicles[0], id: 'old', timestamp: 1767225600 - 3600 },
],
...extra,
}),
});
const result = await composeCatalog({
tools: coreTools,
services: { transit: transit(snapshot()), clock },
}).call('get_transit_vehicles', { area: downtown });
assert.deepEqual(
result.data.rows.map((row) => row.id),
['v1'],
);
assert.equal(result.data.expired_positions_dropped, 1);
assert.equal(result.data.stale, true);
assert.equal(result.data.feeds[0].status, 'stale');
assert.equal(
result.summary,
'1 transit vehicle in 2 km around 30.267, -97.743 (1 feed stale; positions may be out of date).',
);
});