mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 06:26:26 +00:00
77162aa8d5
The switch a road tripper keeps asking for has never worked. OSRM's `exclude` is the only
avoidance TREK has, and the two public hosts it ships with answer it HTTP 400 on every
leg: their car profile is built without excludable classes, and their own Lua says why
("no memory for classes on demo server"). So "drive this without the tolls" produced
nothing at all on a default install, and the fallback inside the alternatives bar quietly
gave up after one refusal per host.
FOSSGIS runs a public Valhalla on the whole planet next to that OSRM, keyless, and there
avoidance is a runtime weighting rather than a profile that has to be rebuilt. This adds
it as a second engine asked only the questions the first cannot answer, and puts three
switches under the road trip settings that change the road itself rather than offering an
alternative beside it. Paris to Lyon measured 465.8 km / 297 min with tolls against
492.0 km / 454 min without; Hamburg to Copenhagen comes back ferry-free at 469.8 km,
which OSRM cannot produce at all — where a ferry IS the crossing it answers NoRoute
rather than driving round.
Four things the docs would have got wrong, all measured against the live instance:
- `format=osrm` does not carry `has_toll`. That flag is the entire reason for doing this,
and it exists only in the native answer — which is also 5.7x smaller, because the OSRM
shape drags every intersection along. So the adapter translates instead of borrowing a
familiar envelope.
- Without a `radius` Valhalla refuses a point it cannot bind to a road, where OSRM still
snaps one. Vienna's Stephansdom, in a pedestrian zone, answers error 442 until a search
radius is allowed. TREK is full of such places, so every location carries one.
- Ten locations is a hard cap and a road trip day is bundled into one request. A day over
it is split into runs overlapping by one point, which is exact rather than approximate:
a measured six-stop day came back within two metres and under a second of the same day
asked whole.
- Its drive times run 5.4 % above OSRM's over ten European legs and 36 % above on one, and
those times feed the arrival clocks of a day. So a day is answered by one engine or by
neither, never by both, and a piece that will not answer loses the whole day rather than
half of it — the schedule chains leg times blindly and would otherwise print a complete,
plausible, silently wrong timetable.
Because the weighting can fail, the honest surface is the answer rather than the request.
`use_tolls: 0` still returns a tolled road where there is no untolled crossing, so what
the road actually turned out to be is read back per leg, and a day that could not avoid
what it was asked to avoid says so on its own header instead of wearing a label the road
disproves. The switches disable themselves, with a reason, on an instance pointed at its
own OSRM: that operator chose against public hosts, and a second one they never asked for
would undo the choice.
Two things that would have broken quietly and did not:
- The route cache keys on `profile:unit:coords` and is shared with the day planner, the
studio and the booking geometry. Without the avoidance in the key, flipping a switch
returns the old road out of cache in under a millisecond — and worse, an avoiding answer
stored under the plain key hands those other callers a road nobody drives.
- `snapped` is OSRM-only and carries the dashed kerb-to-door spur from #2273. Valhalla
echoes the coordinates it was given and never says where it bound them, but the ends of
a leg's line are exactly those points: measured against Füssen, its first vertex matches
OSRM's snapped location to the digit.
The alternatives bar gets the same engine, which finally makes its "no motorway" and "no
tolls" offers appear on a default install, plus a ferry-free one. `sameRoad` now compares
geometry rather than numbers there, because two engines' distances for the same road sit
kilometres apart and the old 200 m tolerance called that a discovery.
Desktop only, like the whole road trip mode: nothing under client/src/mobile renders it.
125 lines
4.8 KiB
TypeScript
125 lines
4.8 KiB
TypeScript
/**
|
||
* Who owns which setting, pinned.
|
||
*
|
||
* The lists grow and the mode does not: that is how this kind of switch drifts.
|
||
* A key added to ADMIN_SETTINGS_KEYS or DEFAULTABLE_USER_SETTING_KEYS belongs to
|
||
* neither set until somebody decides, and MANAGED-KEYS-001 is what makes that
|
||
* decision unavoidable rather than optional.
|
||
*
|
||
* Deliberately an assignment test, not an equality test. Pinning the locked list
|
||
* alone would pass forever while new keys quietly defaulted to "the admin may
|
||
* set it", which is the failure this is here to prevent.
|
||
*/
|
||
import { describe, it, expect } from 'vitest';
|
||
import { ADMIN_SETTINGS_KEYS } from '../../../src/nest/auth/auth.helpers';
|
||
import { DEFAULTABLE_USER_SETTING_KEYS } from '../../../src/nest/settings/settings.service';
|
||
import {
|
||
MANAGED_LOCKED_SETTING_KEYS,
|
||
MANAGED_LOCKED_PROFILE_KEYS,
|
||
MANAGED_CUSTOMER_KEYS,
|
||
isManagedLockedKey,
|
||
splitManagedKeys,
|
||
} from '../../../src/nest/common/managed';
|
||
|
||
const SOURCE_KEYS: string[] = [...ADMIN_SETTINGS_KEYS, ...DEFAULTABLE_USER_SETTING_KEYS];
|
||
const locked = new Set<string>(MANAGED_LOCKED_SETTING_KEYS);
|
||
const customer = new Set<string>(MANAGED_CUSTOMER_KEYS);
|
||
|
||
describe('managed key assignment', () => {
|
||
it('MANAGED-KEYS-001: every key from both source lists is assigned to exactly one set', () => {
|
||
const unassigned = SOURCE_KEYS.filter((k) => !locked.has(k) && !customer.has(k));
|
||
const both = SOURCE_KEYS.filter((k) => locked.has(k) && customer.has(k));
|
||
|
||
// Both in one assertion so the failure message names the offending key.
|
||
expect({ unassigned, both }).toEqual({ unassigned: [], both: [] });
|
||
});
|
||
|
||
it('MANAGED-KEYS-002: no customer entry outlives the key it describes', () => {
|
||
expect(MANAGED_CUSTOMER_KEYS.filter((k) => !SOURCE_KEYS.includes(k))).toEqual([]);
|
||
});
|
||
|
||
it('MANAGED-KEYS-003: the only locked names outside both source lists are the users columns', () => {
|
||
expect(MANAGED_LOCKED_SETTING_KEYS.filter((k) => !SOURCE_KEYS.includes(k)).slice().sort()).toEqual(
|
||
[...MANAGED_LOCKED_PROFILE_KEYS].sort(),
|
||
);
|
||
});
|
||
|
||
it('MANAGED-KEYS-004: neither set repeats itself', () => {
|
||
expect(locked.size).toBe(MANAGED_LOCKED_SETTING_KEYS.length);
|
||
expect(customer.size).toBe(MANAGED_CUSTOMER_KEYS.length);
|
||
});
|
||
|
||
it('MANAGED-KEYS-005: the locked list is pinned verbatim', () => {
|
||
expect([...MANAGED_LOCKED_SETTING_KEYS]).toEqual([
|
||
'carto_api_key',
|
||
'llm_api_key',
|
||
'llm_base_url',
|
||
'llm_model',
|
||
'llm_multimodal',
|
||
'llm_provider',
|
||
'mapbox_access_token',
|
||
'maps_api_key',
|
||
'oidc_login',
|
||
'oidc_registration',
|
||
'openweather_api_key',
|
||
'routing_base_url',
|
||
'smtp_from',
|
||
'smtp_host',
|
||
'smtp_pass',
|
||
'smtp_port',
|
||
'smtp_skip_tls_verify',
|
||
'smtp_user',
|
||
'unsplash_api_key',
|
||
'valhalla_base_url',
|
||
'webauthn_origins',
|
||
'webauthn_rp_id',
|
||
]);
|
||
});
|
||
|
||
it("MANAGED-KEYS-006: mapbox_access_token is the operator's, and reaches the browser by design", () => {
|
||
// The one locked key whose value is meant to be public: a managed instance
|
||
// ships the operator's pk.* token, injected when settings are read. Locked so
|
||
// a per-user save cannot land on top of it and break that user's map.
|
||
expect(isManagedLockedKey('mapbox_access_token')).toBe(true);
|
||
expect(customer.has('mapbox_access_token')).toBe(false);
|
||
});
|
||
});
|
||
|
||
describe('splitManagedKeys', () => {
|
||
it('MANAGED-KEYS-007: hands the body back untouched on a self-hosted install', () => {
|
||
const body = { smtp_host: 'mail.example.test', allow_registration: 'true' };
|
||
|
||
expect(splitManagedKeys(body, false)).toEqual({ allowed: body, blocked: [] });
|
||
});
|
||
|
||
it('MANAGED-KEYS-008: keeps the customer keys and reports the locked ones', () => {
|
||
// The admin settings tab saves SMTP and the registration toggles in one
|
||
// request. Refusing the request would take the toggles down with the SMTP.
|
||
const { allowed, blocked } = splitManagedKeys(
|
||
{ smtp_host: 'mail.example.test', smtp_pass: 'hunter2', allow_registration: 'true' },
|
||
true,
|
||
);
|
||
|
||
expect(allowed).toEqual({ allow_registration: 'true' });
|
||
expect(blocked).toEqual(['smtp_host', 'smtp_pass']);
|
||
});
|
||
|
||
it('MANAGED-KEYS-009: reports blocked names sorted, so a response body is stable', () => {
|
||
const { blocked } = splitManagedKeys(
|
||
{ webauthn_rp_id: 'x', llm_api_key: 'y', smtp_from: 'z' },
|
||
true,
|
||
);
|
||
|
||
expect(blocked).toEqual(['llm_api_key', 'smtp_from', 'webauthn_rp_id']);
|
||
});
|
||
|
||
it('MANAGED-KEYS-010: an unknown key is not the filter’s business', () => {
|
||
// Whatever rejects unknown keys today keeps rejecting them; this only ever
|
||
// removes names it was told to remove.
|
||
const { allowed, blocked } = splitManagedKeys({ not_a_setting: '1' }, true);
|
||
|
||
expect(allowed).toEqual({ not_a_setting: '1' });
|
||
expect(blocked).toEqual([]);
|
||
});
|
||
});
|