fix(maps): stop pois() dropping opening hours and reporting a narrowing as none

The index-first branch hardcoded opening_hours: null while the payload it maps
carries them, and search_pois advertises "opening hours wherever OSM carries
them". It also capped the radius at 20km and then answered clamped: false, so a
wide viewport came back narrowed and said it was not - the same field the
Overpass path fills honestly.

The three red MCP cases were the same code telling the truth from the other
side: they stub Overpass one level below the facade, so pois() ran for real,
and because trekPlacesEnabled() fails open on a database with no row, a unit
test was sending live requests to places.liketrek.com from CI. That is what
answered with 50 places instead of the stubbed one. The index client is now
mocked in that suite, with the gate left open so the cases still run on the
shipping configuration, and the index-first path gets cases of its own here and
in a new maps.pois suite: field mapping, the empty and the failing index both
dropping through to Overpass, and an outage under both providers still reaching
the caller as an error rather than an empty list.

maps.service.test.ts drove pois() with no stub at all and leaked the same way.
This commit is contained in:
Maurice
2026-09-06 23:35:17 +02:00
committed by Maurice
parent 65eebec53f
commit 0991fa538b
4 changed files with 457 additions and 13 deletions
+12 -13
View File
@@ -651,18 +651,13 @@ export class MapsService {
const lng = (bbox.west + bbox.east) / 2;
// Half the diagonal, so the circle covers the viewport corners rather
// than leaving the edges of the map empty.
const radius = Math.min(
20000,
Math.max(
300,
Math.round(
(Math.hypot(
(bbox.north - bbox.south) * 111_320,
(bbox.east - bbox.west) * 111_320 * Math.cos((lat * Math.PI) / 180),
) / 2),
),
),
const wanted = Math.round(
Math.hypot(
(bbox.north - bbox.south) * 111_320,
(bbox.east - bbox.west) * 111_320 * Math.cos((lat * Math.PI) / 180),
) / 2,
);
const radius = Math.min(20000, Math.max(300, wanted));
const found = await trekPlacesNearby(lat, lng, {
radius,
limit: 50,
@@ -685,13 +680,17 @@ export class MapsService {
address: p.address?.freeform ?? null,
website: p.contact?.website ?? null,
phone: p.contact?.phone ?? null,
opening_hours: null,
opening_hours: p.hours?.osm ?? null,
// The index has no cuisine field, so this null is the truth
// rather than a field being dropped on the way through.
cuisine: null,
source: 'openstreetmap' as const,
})),
source: 'openstreetmap' as const,
truncated: found.length >= 50,
clamped: false,
// A wide viewport is narrowed here too, and the caller is told so
// for the same reason the Overpass path tells it.
clamped: radius < wanted,
};
}
} catch (err: unknown) {