feat(transit): let an admin route transit search through Google

Transitous has no GTFS coverage for much of Asia, so a search between two
Osaka subway stops finds nothing — the stops are not in the feed at all.
Add Google as an optional backend behind an admin setting, reusing the
install's existing Places key, and fall back to Transitous whenever no
key resolves.

Uses the Routes API rather than the legacy Directions endpoint the
request named: every other Google call here already speaks the
v1/X-Goog-Api-Key family, and Google closed the legacy endpoint to Cloud
projects created after March 2025.

Google returns walking as turn-by-turn navigation steps where MOTIS
returns one leg per walking segment, so consecutive walk steps are
coalesced into a single leg — otherwise a finely-sliced walk pushed a
real journey past the 20-leg cap and the whole itinerary was dropped.

Both responses now name the backend that answered. The fallback is
silent by design, which left an empty result ambiguous between "no data
here" and "the provider you picked never ran", and the admin panel warns
when Google is selected but no key resolves — or when only the admin's
own key is set, which serves them and nobody else.

Cost shaped the implementation, since Google bills where Transitous does
not: both field masks are cut to the cheapest SKU tier that still
answers the question, cache TTLs are longer than the Transitous path's,
and route alternatives ride along inside the already-billed request.

Addresses #1699
This commit is contained in:
Konstantinos Thermos
2026-09-03 19:35:23 +03:00
committed by Maurice
parent 8e2840b29d
commit 2a0ceb2687
72 changed files with 2065 additions and 35 deletions
@@ -47,6 +47,8 @@ const addonsStub = () => ({
updatePlacesEnrich: vi.fn((enabled: boolean) => ({ enabled })),
getCollabFeatures: vi.fn(() => ({ chat: false })),
updateCollabFeatures: vi.fn(() => ({ features: { chat: true }, changed: true })),
getTransitProvider: vi.fn(() => ({ provider: 'transitous', googleKeySource: null })),
updateTransitProvider: vi.fn((provider: string) => ({ provider, googleKeySource: null })),
}) as unknown as AddonsService;
// The MCP-token routes read TokenService now, not AdminService. Stubbed via a
@@ -278,6 +280,20 @@ describe('AdminController feature toggles', () => {
expect(writeAudit).toHaveBeenCalledWith(expect.objectContaining({ action: 'admin.places_enrich' }));
});
it('ADMIN-TOGGLE-002c transit-provider reads and writes through the addons domain and is audited (#1699)', () => {
const addons = addonsStub();
const c = adminCtl(svc(), undefined, addons);
expect(c.getTransitProvider(user)).toEqual({ provider: 'transitous', googleKeySource: null });
expect(c.updateTransitProvider(user, { provider: 'google' }, req)).toEqual({ provider: 'google', googleKeySource: null });
// The acting admin's id drives key resolution — the panel warns about the
// key THEY would search with.
expect(addons.getTransitProvider).toHaveBeenCalledWith(user.id);
expect(addons.updateTransitProvider).toHaveBeenCalledWith('google', user.id);
expect(writeAudit).toHaveBeenCalledWith(
expect.objectContaining({ action: 'admin.transit_provider', details: { provider: 'google' } }),
);
});
it('ADMIN-TOGGLE-003 collab-features invalidates MCP sessions only when a flag flipped (#1414)', () => {
const invalidateMcpSessions = vi.fn();
const c = adminCtl(svc({ invalidateMcpSessions } as Partial<AdminService>));