fix(maps): name the index as the source, and stop it being asked twice

Attribution first, because this branch argues the point itself: the card names
the sources with the comment that naming them is a licence obligation rather
than decoration, and the copy beside it promises that every field says where it
came from. The POI path then stamped Overture rows as OpenStreetMap. Overture is
not OpenStreetMap — it carries OSM among other sources under other licences — so
that is a wrong attribution rather than a rounded one. The wire contract keeps
`source` an open string and nothing on the client switches on it, so saying
`trek-places` costs nothing. The MCP tool description no longer calls itself an
OpenStreetMap tool either, and says which source answered.

Adding one place cost two round trips to the index. The details lookup fetches
the place and its answer carries the description; toPlaceRecord dropped that
field, so the enrichment fetched the same place again a moment later to read it.
It is carried through now and read from what the caller already has, with the
second lookup left as the fallback for when there is nothing to read.

That description's source URL becomes an href on the client and was taken on
`typeof === 'string'` alone. It now goes through the same allow-list a place's
website goes through — the file already does this for menu_url, with the comment
explaining why — so anything but http(s) loses the link and keeps the text.

The instance token was hashed from raw APP_URL, which the shipped compose file
leaves commented out. Every default install therefore sent the same token, and a
token every caller shares is not a caller: one instance running a large import
would rate-limit all the others, who would fall back to Nominatim with nothing
to point at. getAppUrl() falls through to ALLOWED_ORIGINS and then to the port,
so unconfigured instances still differ.

Two client-side leaks. A pick made out of the offline cache was recorded into
the shadow corpus, where it moved the two figures the corpus exists to
measure — and offline is a setting, so the network is usually reachable and the
row landed. And the prefetch never re-checked the session after its request came
back: a logout in that window repoints the handle at the anonymous database, so
one person's trip area was written where the next person's offline search reads.

The cache path also ignored the abort signal, so an answer for a keystroke two
keystrokes old could overwrite a newer suggestion list. It rejects the way both
surfaces already know to swallow.

Left alone, and said in a comment rather than hidden: the index cannot localise.
The Overpass path picks name:<lang> and falls back to int_name; the service has
no language parameter at all, so a German reader exploring Tokyo gets the
Japanese primary names on this path.
This commit is contained in:
Maurice
2026-09-07 11:49:39 +02:00
committed by Maurice
parent b0aa7f8d95
commit ed5769fc89
14 changed files with 254 additions and 26 deletions
+18
View File
@@ -7,6 +7,7 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import 'fake-indexeddb/auto'
import { offlineDb, clearAll } from '../db/offlineDb'
import { setAuthed } from './authGate'
import {
AREA_PLACE_LIMIT,
cachedToPlaceRecord,
@@ -42,6 +43,9 @@ function apiRow(name: string, over: Record<string, unknown> = {}) {
beforeEach(async () => {
await clearAll()
// The prefetch re-checks this after its request comes back, so a suite that
// never signs in would exercise the abandon path and nothing else.
setAuthed(true)
areaMock.mockReset()
areaMock.mockResolvedValue({ results: [apiRow("L'Osteria"), apiRow('Café Central')], truncated: false })
await offlineDb.syncMeta.put({
@@ -180,6 +184,20 @@ describe('searchCachedPlaces', () => {
expect(found?.name).toBe("L'Osteria")
})
it('FE-PLACEPRE-018: a logout while the request is in flight leaves the database alone', async () => {
// The handle repoints at the anonymous database on logout, so writing the
// answer after that seeds one person's trip area into the next person's
// offline search. A shared tablet is all it takes.
await clearAll()
areaMock.mockImplementation(async () => {
setAuthed(false)
return { results: [apiRow('Nach dem Logout')], truncated: false }
})
await expect(prefetchPlacesForTrip(7, TRIP_PLACES, true)).resolves.toBe(0)
expect(await offlineDb.areaPlaces.count()).toBe(0)
})
it('FE-PLACEPRE-017: an id the cache does not hold is a miss, not somebody else record', async () => {
// A miss has to stay a miss: answering the wrong place would be worse than
// the failure it replaces.
+8
View File
@@ -11,6 +11,7 @@
* trip's area actually changes. A trip to Rostock costs roughly a megabyte.
*/
import { mapsApi } from '../api/client'
import { isAuthed } from './authGate'
import { offlineDb, type CachedAreaPlace } from '../db/offlineDb'
import type { Place } from '../types'
import { computeBbox } from './tilePrefetcher'
@@ -120,6 +121,13 @@ export async function prefetchPlacesForTrip(
const area = await mapsApi.area(bbox, AREA_PLACE_LIMIT)
if (area.unavailable) return 0
// Checked after the await, not only before it: the area request has a long
// timeout, and a logout in the meantime deletes the user's database and
// repoints the handle at the anonymous one. Writing then would seed one
// person's trip area into the next person's offline search — the same
// reason cacheFilesForTrip and the tile prefetch re-check here.
if (!isAuthed()) return 0
const now = Date.now()
const rows = (area.results || [])
.map((r) => toCached(tripId, r as AreaRecord, now))