fix(tours): open a saved ski tour as saved and keep what its router planned

A saved ski tour now opens with the line, heights, time, build and
planned legs it was saved with, read from the place this device keeps,
and nothing is asked of the piste router until a point, an option or the
discipline changes. Opened offline, while TREK Places is down or with
piste routing switched off, it no longer turns every leg straight, and a
rename saves the planned tour as it was. A kept line whose length is not
the tour's is another save's, and the tour is planned afresh.

- the save names the legs the router planned (ski_planned_legs, checked
  against the tour's own legs); get_tour_plan reports each leg routed or
  drawn from them instead of from the build alone, a tour that names none
  counting as planned only with the router's time
- copies keep ski_options in every path: in the trip, taken over, kept
  in a collection and made from one (collection_tours gets the column in
  the same unshipped migration)
- the route summary shows the data build, the km of runs, the height
  skied down on them and the lift rides, and the credit the server sends
  in place of a fixed one; a tour opened as saved says so
- answers refused while piste routing is off, or planned on an older kept
  copy, are not remembered, so they are asked again later
- terrain heights between known ones are filled in one walk along the line
- i18n: five summary keys in all 27 locales
This commit is contained in:
Maurice
2026-10-20 21:07:06 +02:00
parent 1d72fbd25f
commit ae699187f7
63 changed files with 1002 additions and 98 deletions
@@ -70,6 +70,7 @@ function snapshot(collectionId: number, savedBy: number | null, overrides: Parti
run_pace_seconds_per_km: null,
ski_discipline: null,
ski_technique: null,
ski_options: null,
boat_type: null,
water_context: null,
paddle_speed_kmh: null,
@@ -3,6 +3,7 @@
* tour one more column, `ski_options`: the JSON text of the piste router's
* options and the build its legs ran on. Every tour that was there keeps its
* columns and reads NULL in the new one; the column takes the server's JSON.
* A tour kept in a collection gets the same column.
*/
import { createMigrationOrm, migrateTo, pendingNames, rawExec, rawQuery } from '../../helpers/migration-step';
@@ -31,6 +32,9 @@ describe('the ski options column', () => {
const stored = JSON.stringify({ options: { max_difficulty: 'advanced' }, build: '2026-11-02' });
await rawExec(orm, 'UPDATE tours SET ski_options = ? WHERE place_id = 100', [stored]);
expect(await rawQuery(orm, 'SELECT ski_options FROM tours')).toEqual([{ ski_options: stored }]);
// A tour kept in a collection keeps the same column, so its copies keep the options.
const kept = "SELECT name FROM pragma_table_info('collection_tours') WHERE name = 'ski_options'";
expect(await rawQuery(orm, kept)).toEqual([{ name: 'ski_options' }]);
} finally {
await orm.close(true);
}
@@ -45,6 +45,7 @@ const row: CollectionTourRow = {
run_pace_seconds_per_km: null,
ski_discipline: null,
ski_technique: null,
ski_options: null,
boat_type: null,
water_context: null,
paddle_speed_kmh: null,
@@ -186,6 +187,20 @@ describe('collection tour helpers (LIB-03)', () => {
expect(kept.map((point) => point.linked_place_id)).toEqual([null, null]);
});
it('LIB3-HLP-007: a kept ski tour keeps its piste router options and build, and a copy of it takes them along', () => {
const skiOptions = JSON.stringify({ options: { max_difficulty: 'advanced' }, build: '2026-11-02' });
const ski = { ...row, tour_type: 'ski', bike_profile: null, ski_discipline: 'alpine', ski_options: skiOptions };
const snapshot = keptTourSnapshot(keptTourCopySource(ski, true), {
collectionId: 9,
userId: 1,
name: 'Kept',
tripTitle: 'Alps',
});
expect(snapshot).toMatchObject({ tour_type: 'ski', ski_discipline: 'alpine', ski_options: skiOptions });
expect(keptTourCopySource(ski, false).facet.ski_options).toBe(skiOptions);
expect(keptTourCopySource(row, false).facet.ski_options).toBeNull();
});
it('LIB3-HLP-006: a point that is no control point refuses the whole snapshot', () => {
const broken = keptTourCopySource({ ...row, waypoints: [{ lat: 147, lng: 11, role: 'start', sequence: 0 }] }, true);
expect(() => keptTourSnapshot(broken, { collectionId: 9, userId: 1, name: 'Kept', tripTitle: 'Coast' })).toThrow();
@@ -133,12 +133,17 @@ describe('tour plan read (MCP-T01)', () => {
],
},
});
expect(planLegs([point(0), free, point(2)], { recorded: false, drawn: true })).toEqual([
expect(planLegs([point(0), free, point(2)], { recorded: false, drawn: () => true })).toEqual([
expect.objectContaining({ kind: 'free', name: null, length_km: 1.11 }),
expect.objectContaining({ kind: 'free', name: null, length_km: 1.11 }),
]);
// A leg the piste router planned is routed, with no length of its own; the leg drawn straight keeps its line.
expect(planLegs([point(0), point(1), point(2)], { recorded: false, drawn: (leg) => leg === 1 })).toEqual([
expect.objectContaining({ kind: 'routed', length_km: null }),
expect.objectContaining({ kind: 'free', length_km: 1.11 }),
]);
// A ski track kept as recorded stays a track.
expect(planLegs([point(0), point(1)], { recorded: true, drawn: true })).toEqual([
expect(planLegs([point(0), point(1)], { recorded: true, drawn: () => true })).toEqual([
expect.objectContaining({ kind: 'track', length_km: null }),
]);
});
+69 -2
View File
@@ -709,7 +709,11 @@ describe('ToursMcp', () => {
const { member, trip } = fixture();
const orm = await createTestOrm(db);
const ski = await makePlace(orm, trip.id, { name: 'Down to the valley' });
const stored = { options: { ...DEFAULT_SKI_ROUTE_OPTIONS, max_difficulty: 'advanced' }, build: '2026-11-02' };
const stored = {
options: { ...DEFAULT_SKI_ROUTE_OPTIONS, max_difficulty: 'advanced' },
build: '2026-11-02',
planned_legs: [0],
};
await makeTour(orm, ski.id, {
tourTypeRef: 'ski',
max_hiking_difficulty: null,
@@ -722,7 +726,70 @@ describe('ToursMcp', () => {
]);
await orm.close();
const plan = read(await mcp.getTourPlan({ tripId: trip.id, placeId: ski.id }, ctx(member.id)));
expect(plan.tour).toMatchObject({ ski_options: stored.options, ski_route_build: '2026-11-02' });
expect(plan.tour).toMatchObject({
ski_options: stored.options,
ski_route_build: '2026-11-02',
ski_planned_legs: [0],
});
expect(plan.legs).toEqual([expect.objectContaining({ from_key: 'pk-top', to_key: 'pk-valley', kind: 'routed' })]);
});
it('TOURS-MCP-027: a ski tour planned in part names only the legs the router planned as routed, the rest drawn straight', async () => {
const { member, trip } = fixture();
const orm = await createTestOrm(db);
const partly = await makePlace(orm, trip.id, { name: 'Across the valley' });
const options = DEFAULT_SKI_ROUTE_OPTIONS;
await makeTour(orm, partly.id, {
tourTypeRef: 'ski',
max_hiking_difficulty: null,
ski_discipline: 'alpine',
ski_options: JSON.stringify({ options, build: '2026-11-02', planned_legs: [1] }),
});
await addTourWaypoints(orm, partly.id, [
{ lat: 46, lng: 7, station_key: 'pp-a' },
{ lat: 46.01, lng: 7, station_key: 'pp-b' },
{ lat: 46.02, lng: 7, station_key: 'pp-c' },
]);
// Saved without naming its legs: planned throughout only with the router's time kept.
const timed = await makePlace(orm, trip.id, { name: 'Timed' });
await makeTour(orm, timed.id, {
tourTypeRef: 'ski',
max_hiking_difficulty: null,
ski_discipline: 'alpine',
duration: 25,
ski_options: JSON.stringify({ options, build: '2026-11-02' }),
});
const untimed = await makePlace(orm, trip.id, { name: 'Untimed' });
await makeTour(orm, untimed.id, {
tourTypeRef: 'ski',
max_hiking_difficulty: null,
ski_discipline: 'alpine',
ski_options: JSON.stringify({ options, build: '2026-11-02' }),
});
for (const place of [timed, untimed]) {
await addTourWaypoints(orm, place.id, [
{ lat: 46, lng: 7, station_key: `${place.id}-a` },
{ lat: 46.01, lng: 7, station_key: `${place.id}-b` },
]);
}
await orm.close();
const plan = read(await mcp.getTourPlan({ tripId: trip.id, placeId: partly.id }, ctx(member.id)));
expect(plan.legs.map((leg: { kind: string }) => leg.kind)).toEqual(['free', 'routed']);
expect(plan.legs[0].length_km).toBeCloseTo(1.11, 1);
expect(plan.legs[1].length_km).toBeNull();
const kinds = async (placeId: number): Promise<string[]> => {
const other = read(await mcp.getTourPlan({ tripId: trip.id, placeId }, ctx(member.id)));
return other.legs.map((leg: { kind: string }) => leg.kind);
};
expect(await kinds(timed.id)).toEqual(['routed']);
expect(await kinds(untimed.id)).toEqual(['free']);
const listEntry = getEntry(ToursMcp as unknown as ClassRef, 'listTours');
expect(listEntry?.kind === 'tool' ? listEntry.options.description : '').toContain(
'ski_planned_legs: the legs it planned',
);
const planEntry = getEntry(ToursMcp as unknown as ClassRef, 'getTourPlan');
expect(planEntry?.kind === 'tool' ? planEntry.options.description : '').toContain(
'routed where the piste router planned it and free',
);
});
});