feat(tours): complete planner follow-up scope

This commit completes the reviewed Tours follow-up scope after the Tours MVP was merged into dev.

Included feature blocks:

- RC-01: identify Tours in PLAN day rows and show compact Tour facts;
- RC-06: search for a city or address in TOUR-PLANNER without hidden writes;
- RC-07: reorder Tour waypoints in the left sidebar;
- RC-08: drag Tour waypoints on Leaflet, MapLibre and Mapbox with stable viewport, history and routing behavior;
- RS-01: persist Tour descriptions and HTTPS information links with local provider classification;
- RS-02: persist breaks/additional time and calculated or manually adjusted planned Tour duration without changing scheduling semantics.
The implementation preserves:

- ordinary Place and Legacy Track behavior;
- Tours-off fallback behavior;
- existing GPX/import behavior;
- Tour assignment and deletion behavior;
- calculated routing duration as a separate value;
- existing Tour provenance fields;
- keyboard/list alternatives for waypoint editing.
Not included:

- PR1-09 trip-wide Tour summary;
- Wanderer integration;
- GPX import changes;
- new Tour types;
- Tour-to-Day drag-and-drop;
- further roadmap or Post-Release features.
Validation:

- focused RC-01/RC-06/RC-07/RC-08/RS-01/RS-02 tests passed;
- affected shared/server/client typechecks passed;
- migration and generated DB type checks passed;
- scoped ESLint passed;
- staged diff checks passed;
- owner manual tests passed for all six feature blocks.
This commit is contained in:
elmocito
2026-10-09 13:52:11 +02:00
committed by Maurice
parent af9f013c5e
commit 57ea219a43
56 changed files with 4315 additions and 462 deletions
@@ -11,6 +11,8 @@ describe('known migrations', () => {
const known = knownMigrationNames();
expect(known.has('Migration20200101000000_baseline_schema')).toBe(true);
expect(known.has('Migration20200101042000_tours')).toBe(true);
expect(known.has('Migration20200101042900_tour_planned_total_duration')).toBe(true);
expect(known.has('Migration20200101043000_tour_break_additional_duration')).toBe(true);
expect(known.size).toBe(fs.readdirSync(path.join(__dirname, '../../../src/db/migrations')).length);
});
@@ -40,6 +40,8 @@ const UNNUMBERED = [
'Migration20200101042600_a_session_row_per_sign_in',
'Migration20200101042700_timestamps_stored_in_one_spelling',
'Migration20200101042800_an_email_the_account_typed_in_itself',
'Migration20200101042900_tour_planned_total_duration',
'Migration20200101043000_tour_break_additional_duration',
];
// The last step the positional runner ever had; planLegacyBaseline refuses a
// schema_version past it.
File diff suppressed because it is too large Load Diff
@@ -49,6 +49,8 @@ const METRICS = {
elevation_gain: 420,
elevation_loss: 380,
duration: 150,
planned_duration_minutes: 125,
break_additional_minutes: 35,
match_confidence: 1,
max_hiking_difficulty: 3,
};
@@ -57,7 +59,8 @@ describe('ToursRepository reads', () => {
it('TOURREPO-001: listForTrip projects the facet with its place name and both flags, newest first, never another trip', async () => {
const { trip, other } = fixture();
const older = createPlace(testDb, trip.id, { name: 'Older' });
const newer = createPlace(testDb, trip.id, { name: 'Newer' });
const newer = createPlace(testDb, trip.id, { name: 'Newer', description: 'Lake ridge' });
testDb.prepare('UPDATE places SET website = ? WHERE id = ?').run('https://www.komoot.com/tour/42', newer.id);
const plain = createPlace(testDb, trip.id, { name: 'Not a tour' });
const foreign = createPlace(testDb, other.id, { name: 'Foreign' });
createTour(testDb, older.id, { created_at: '2026-01-01 10:00:00', distance: 5, match_confidence: 0.3 });
@@ -70,11 +73,15 @@ describe('ToursRepository reads', () => {
{
place_id: newer.id,
name: 'Newer',
description: 'Lake ridge',
website: 'https://www.komoot.com/tour/42',
tour_type: 'hike',
distance: null,
elevation_gain: null,
elevation_loss: null,
duration: null,
planned_duration_minutes: null,
break_additional_minutes: null,
difficulty: null,
wanderer_ref: null,
match_confidence: null,
@@ -85,11 +92,15 @@ describe('ToursRepository reads', () => {
{
place_id: older.id,
name: 'Older',
description: null,
website: null,
tour_type: 'hike',
distance: 5,
elevation_gain: null,
elevation_loss: null,
duration: null,
planned_duration_minutes: null,
break_additional_minutes: null,
difficulty: null,
wanderer_ref: null,
match_confidence: 0.3,
@@ -164,6 +175,8 @@ describe('ToursRepository writes', () => {
expect(await repo.findInTrip(trip.id, place.id)).toEqual({
place_id: place.id,
name: 'Drawn',
description: null,
website: null,
...METRICS,
difficulty: null,
wanderer_ref: null,
@@ -182,13 +195,34 @@ describe('ToursRepository writes', () => {
expect(await repo.updateInTrip(trip.id, place.id, METRICS)).toBe(true);
expect(await repo.findInTrip(trip.id, place.id)).toMatchObject(METRICS);
const {
planned_duration_minutes: _omitted,
break_additional_minutes: _omittedBreaks,
...routeOnlyUpdate
} = METRICS;
expect(await repo.updateInTrip(trip.id, place.id, routeOnlyUpdate)).toBe(true);
expect(await repo.findInTrip(trip.id, place.id)).toMatchObject({
duration: 150,
planned_duration_minutes: 125,
break_additional_minutes: 35,
});
});
it('TOURREPO-008: listRowsForTrip and insertCopy carry every column, created_at included, onto the copied place', async () => {
const { trip, other } = fixture();
const source = createPlace(testDb, trip.id);
createTour(testDb, source.id, { created_at: '2026-03-04 05:06:07', distance: 3.5, max_hiking_difficulty: 4 });
await updateRows(t, Tours, { place: source.id }, { difficulty: 'T3', wanderer_ref: 'w-1' });
await updateRows(
t,
Tours,
{ place: source.id },
{
difficulty: 'T3',
wanderer_ref: 'w-1',
planned_duration_minutes: 95,
break_additional_minutes: 30,
},
);
const rows = await repo.listRowsForTrip(trip.id);
expect(rows).toEqual([
@@ -199,6 +233,8 @@ describe('ToursRepository writes', () => {
elevation_gain: null,
elevation_loss: null,
duration: null,
planned_duration_minutes: 95,
break_additional_minutes: 30,
difficulty: 'T3',
wanderer_ref: 'w-1',
match_confidence: null,
@@ -0,0 +1,57 @@
import { createMigrationOrm, migrateTo, pendingNames, rawExec, rawQuery } from '../../helpers/migration-step';
import type { MikroORM } from '@mikro-orm/sqlite';
import { describe, expect, it } from 'vitest';
const TARGET = 'Migration20200101043000_tour_break_additional_duration';
async function ormBeforeTarget(): Promise<MikroORM> {
const orm = await createMigrationOrm();
const names = await pendingNames(orm);
const index = names.indexOf(TARGET);
expect(index).toBeGreaterThan(0);
await migrateTo(orm, names[index - 1]);
return orm;
}
describe('Tour breaks/additional-duration migration', () => {
it('adds nullable breaks without changing calculated or overridden Tour values', async () => {
const orm = await ormBeforeTarget();
try {
await rawExec(
orm,
"INSERT INTO users (id, username, email, password_hash) VALUES (1, 'owner', 'owner@test', 'x')",
);
await rawExec(orm, "INSERT INTO trips (id, user_id, title) VALUES (10, 1, 'Alps')");
await rawExec(orm, "INSERT INTO places (id, trip_id, name) VALUES (100, 10, 'Ridge walk')");
await rawExec(
orm,
"INSERT INTO tours (place_id, tour_type, duration, planned_duration_minutes) VALUES (100, 'hike', 83, 125)",
);
await migrateTo(orm, TARGET);
expect(
await rawQuery(
orm,
'SELECT duration, planned_duration_minutes, break_additional_minutes FROM tours WHERE place_id = 100',
),
).toEqual([{ duration: 83, planned_duration_minutes: 125, break_additional_minutes: null }]);
await rawExec(orm, 'UPDATE tours SET break_additional_minutes = 35 WHERE place_id = 100');
expect(
await rawQuery(
orm,
'SELECT duration, planned_duration_minutes, break_additional_minutes FROM tours WHERE place_id = 100',
),
).toEqual([{ duration: 83, planned_duration_minutes: 125, break_additional_minutes: 35 }]);
await expect(
rawExec(orm, 'UPDATE tours SET break_additional_minutes = 1441 WHERE place_id = 100'),
).rejects.toThrow(/CHECK/);
await expect(rawExec(orm, 'UPDATE tours SET break_additional_minutes = -1 WHERE place_id = 100')).rejects.toThrow(
/CHECK/,
);
} finally {
await orm.close(true);
}
}, 30000);
});
@@ -0,0 +1,48 @@
import { createMigrationOrm, migrateTo, pendingNames, rawExec, rawQuery } from '../../helpers/migration-step';
import type { MikroORM } from '@mikro-orm/sqlite';
import { describe, expect, it } from 'vitest';
const TARGET = 'Migration20200101042900_tour_planned_total_duration';
async function ormBeforeTarget(): Promise<MikroORM> {
const orm = await createMigrationOrm();
const names = await pendingNames(orm);
const index = names.indexOf(TARGET);
expect(index).toBeGreaterThan(0);
await migrateTo(orm, names[index - 1]);
return orm;
}
describe('Tour planned-duration migration', () => {
it('adds a nullable bounded column without changing existing Tour rows', async () => {
const orm = await ormBeforeTarget();
try {
await rawExec(
orm,
"INSERT INTO users (id, username, email, password_hash) VALUES (1, 'owner', 'owner@test', 'x')",
);
await rawExec(orm, "INSERT INTO trips (id, user_id, title) VALUES (10, 1, 'Alps')");
await rawExec(orm, "INSERT INTO places (id, trip_id, name) VALUES (100, 10, 'Ridge walk')");
await rawExec(orm, "INSERT INTO tours (place_id, tour_type, duration) VALUES (100, 'hike', 83)");
await migrateTo(orm, TARGET);
expect(await rawQuery(orm, 'SELECT duration, planned_duration_minutes FROM tours WHERE place_id = 100')).toEqual([
{ duration: 83, planned_duration_minutes: null },
]);
await rawExec(orm, 'UPDATE tours SET planned_duration_minutes = 125 WHERE place_id = 100');
expect(await rawQuery(orm, 'SELECT duration, planned_duration_minutes FROM tours WHERE place_id = 100')).toEqual([
{ duration: 83, planned_duration_minutes: 125 },
]);
await expect(
rawExec(orm, 'UPDATE tours SET planned_duration_minutes = 1441 WHERE place_id = 100'),
).rejects.toThrow(/CHECK/);
await expect(rawExec(orm, 'UPDATE tours SET planned_duration_minutes = -1 WHERE place_id = 100')).rejects.toThrow(
/CHECK/,
);
} finally {
await orm.close(true);
}
}, 30000);
});
@@ -214,6 +214,9 @@ describe('Tours GPX atomic persistence and postcommit publication', () => {
has_waypoints: false,
caution: true,
match_confidence: 0.3,
duration: null,
planned_duration_minutes: null,
break_additional_minutes: null,
});
expect(result.tours[1]).toMatchObject({
name: 'Ridge',
@@ -246,8 +249,19 @@ describe('Tours GPX atomic persistence and postcommit publication', () => {
(await findRows(await sharedTestOrm(testDb), Tours, {}, { place: 'asc' })).map((tour) => ({
place_id: tour.place_id,
tour_type: tour.tour_type,
duration: tour.duration,
planned_duration_minutes: tour.planned_duration_minutes,
break_additional_minutes: tour.break_additional_minutes,
})),
).toEqual(rows.map((row) => ({ place_id: row.id, tour_type: 'hike' })));
).toEqual(
rows.map((row) => ({
place_id: row.id,
tour_type: 'hike',
duration: null,
planned_duration_minutes: null,
break_additional_minutes: null,
})),
);
expect(await count('tour_waypoints')).toBe(0);
expect(seen).toEqual([
@@ -324,6 +324,8 @@ describe('Real ToursService update trip boundary (stubbed repositories)', () =>
lat: 48,
lng: 11,
route_geometry: JSON.stringify(input.route_geometry),
...(input.description !== undefined ? { description: input.description } : {}),
...(input.website !== undefined ? { website: input.website } : {}),
});
expect(f.toursRepo.updateInTrip).toHaveBeenCalledExactlyOnceWith(
7,
@@ -141,6 +141,8 @@ describe('ToursService planner contracts (mock-only; SQLite rollback semantics a
lat: 48,
lng: 11,
route_geometry: JSON.stringify(request.route_geometry),
description: request.description ?? null,
website: request.website ?? null,
});
expect(setup.toursRepo.insertTour).toHaveBeenCalledExactlyOnceWith({
place_id: 42,
@@ -149,6 +151,8 @@ describe('ToursService planner contracts (mock-only; SQLite rollback semantics a
elevation_gain: 50,
elevation_loss: 20,
duration: 60,
planned_duration_minutes: null,
break_additional_minutes: null,
match_confidence: 1,
max_hiking_difficulty: 2,
});
@@ -236,6 +240,8 @@ describe('ToursService planner contracts (mock-only; SQLite rollback semantics a
lat: 49,
lng: 12,
route_geometry: JSON.stringify(update.route_geometry),
...(update.description !== undefined ? { description: update.description } : {}),
...(update.website !== undefined ? { website: update.website } : {}),
});
expect(setup.toursRepo.updateInTrip).toHaveBeenCalledExactlyOnceWith(7, 42, {
tour_type: 'hike',
+135 -1
View File
@@ -37,6 +37,8 @@ vi.mock('../../../src/db/database', async () => {
const request: TourCreateRequest = {
name: 'Ridge walk',
description: 'A quiet ridge above the lake.',
website: 'https://www.komoot.com/tour/42',
tour_type: 'hike',
route_geometry: [
[48, 11, 600],
@@ -49,6 +51,8 @@ const request: TourCreateRequest = {
],
max_hiking_difficulty: 2,
duration_seconds: 3600,
planned_duration_minutes: 90,
break_additional_minutes: 25,
};
/** Two waypoints on the same sequence: the UNIQUE(place_id, sequence) index rejects the second one. */
@@ -99,6 +103,24 @@ afterAll(() => {
});
describe('ToursService planner creation', () => {
it.each([
'http://example.org/route',
'javascript:alert(1)',
'data:text/plain,route',
'file:///route.gpx',
'https://user:secret@example.org/route',
])('rejects invalid informational website %s before creating rows', async (website) => {
const parsed = tourCreateRequestSchema.safeParse({ ...request, website });
expect(parsed.success).toBe(false);
await expect(service.createTour(tripId, { ...request, website } as TourCreateRequest)).rejects.toThrow();
expect(await count(Places)).toBe(0);
expect(await count(Tours)).toBe(0);
});
it('safely reports malformed website input through schema safeParse', () => {
expect(tourCreateRequestSchema.safeParse({ ...request, website: 'not a url' }).success).toBe(false);
});
it('TOURS-SVC-001: atomically stores full geometry, derived metrics, and ordered control points', async () => {
const writeStates: boolean[] = [];
broadcast.mockImplementation(() => {
@@ -123,18 +145,36 @@ describe('ToursService planner creation', () => {
lat: 48,
lng: 11,
transport_mode: 'walking',
duration_minutes: 60,
});
expect(place).toMatchObject({
description: 'A quiet ridge above the lake.',
website: 'https://www.komoot.com/tour/42',
});
expect(JSON.parse(String(place.route_geometry))).toEqual(request.route_geometry);
expect(tour).toMatchObject({ tour_type: 'hike', match_confidence: 1, max_hiking_difficulty: 2 });
expect(tour).toMatchObject({
tour_type: 'hike',
match_confidence: 1,
max_hiking_difficulty: 2,
planned_duration_minutes: 90,
break_additional_minutes: 25,
});
expect(tour.distance).toBeGreaterThan(0);
expect(tour.elevation_gain).toBe(50);
expect(tour.elevation_loss).toBe(20);
expect(tour.duration).toBe(60);
expect(result.tour.duration).toBe(60);
expect(result.tour.planned_duration_minutes).toBe(90);
expect(result.tour.break_additional_minutes).toBe(25);
expect(points).toEqual([
{ role: 'start', sequence: 0 },
{ role: 'end', sequence: 1 },
]);
expect(result.tour).toMatchObject({ name: 'Ridge walk', planned: false, has_waypoints: true, caution: false });
expect(result.tour).toMatchObject({
description: 'A quiet ridge above the lake.',
website: 'https://www.komoot.com/tour/42',
});
expect(result.waypoints).toEqual(request.waypoints);
expect(broadcast).toHaveBeenNthCalledWith(1, tripId, 'tours:changed', { placeIds: [placeId] }, 'socket-1');
expect(broadcast).toHaveBeenNthCalledWith(
@@ -176,6 +216,35 @@ describe('ToursService planner creation', () => {
expect(result.tour.duration).toBeNull();
});
it('RS-02: leaves planned total empty when omitted and preserves the calculated duration', async () => {
const { planned_duration_minutes: _omitted, ...withoutPlannedDuration } = request;
const result = await service.createTour(tripId, withoutPlannedDuration);
expect(result.tour.duration).toBe(60);
expect(result.tour.planned_duration_minutes).toBeNull();
});
it.each([-1, 1.5, 1441])('RS-02: rejects invalid breaks %s before writing Tour rows', async (breakMinutes) => {
await expect(
service.createTour(tripId, { ...request, break_additional_minutes: breakMinutes } as TourCreateRequest),
).rejects.toThrow();
expect(await count(Places)).toBe(0);
expect(await count(Tours)).toBe(0);
});
it('RS-02: rejects overlong automatic totals but permits a bounded manual override', async () => {
const tooLong = {
...request,
duration_seconds: 1430 * 60,
break_additional_minutes: 11,
planned_duration_minutes: null,
};
await expect(service.createTour(tripId, tooLong)).rejects.toThrow();
const overridden = await service.createTour(tripId, { ...tooLong, planned_duration_minutes: 1200 });
expect(overridden.tour.duration).toBe(1430);
expect(overridden.tour.planned_duration_minutes).toBe(1200);
expect(overridden.tour.break_additional_minutes).toBe(11);
});
it('TOURS-SVC-010: a type the catalogue holds but has not enabled is a 400 without a write', async () => {
// The contract only lets `hike` through today; this pins what happens the
// day it lets more keys in before the planner offers them.
@@ -285,6 +354,8 @@ describe('ToursService updates', () => {
const update: TourCreateRequest = {
...request,
name: 'Updated ridge walk',
description: 'Updated description',
website: 'https://alltrails.com/trail/42',
route_geometry: [
[49, 12, 700],
[49.02, 12.04, 760],
@@ -295,10 +366,13 @@ describe('ToursService updates', () => {
{ lat: 49.02, lng: 12.04, role: 'end', sequence: 2 },
],
duration_seconds: 2700.5,
planned_duration_minutes: 110,
break_additional_minutes: 40,
};
it('TOURS-SVC-005: atomically updates route data and replaces persisted control points', async () => {
const created = await service.createTour(tripId, request);
testDb.prepare('UPDATE places SET duration_minutes = 35 WHERE id = ?').run(created.tour.place_id);
broadcast.mockReset();
const writeStates: boolean[] = [];
broadcast.mockImplementation(() => {
@@ -312,22 +386,30 @@ describe('ToursService updates', () => {
const storedPlace = await firstPlace();
expect({
name: storedPlace.name,
description: storedPlace.description,
website: storedPlace.website,
lat: storedPlace.lat,
lng: storedPlace.lng,
transport_mode: storedPlace.transport_mode,
duration_minutes: storedPlace.duration_minutes,
}).toEqual({
name: 'Updated ridge walk',
description: 'Updated description',
website: 'https://alltrails.com/trail/42',
lat: 49,
lng: 12,
transport_mode: 'walking',
duration_minutes: 35,
});
const storedTour = await firstTour();
expect({
duration: storedTour.duration,
planned_duration_minutes: storedTour.planned_duration_minutes,
elevation_gain: storedTour.elevation_gain,
elevation_loss: storedTour.elevation_loss,
}).toEqual({
duration: 45,
planned_duration_minutes: 110,
elevation_gain: 60,
elevation_loss: 0,
});
@@ -348,6 +430,58 @@ describe('ToursService updates', () => {
expect(writeStates).toEqual([false, false]);
});
it('preserves description and website when an older Tour update omits optional metadata', async () => {
const created = await service.createTour(tripId, request);
const {
description: _description,
website: _website,
planned_duration_minutes: _planned,
break_additional_minutes: _breaks,
...legacyUpdate
} = update;
const result = await service.updateTour(tripId, String(created.tour.place_id), legacyUpdate);
expect(result.tour).toMatchObject({ description: request.description, website: request.website });
expect(result.tour.planned_duration_minutes).toBe(request.planned_duration_minutes);
expect(result.tour.break_additional_minutes).toBe(request.break_additional_minutes);
expect(testDb.prepare('SELECT description, website FROM places WHERE id = ?').get(created.tour.place_id)).toEqual({
description: request.description,
website: request.website,
});
});
it('clears planned total duration only when an update explicitly sends null', async () => {
const created = await service.createTour(tripId, request);
const result = await service.updateTour(tripId, String(created.tour.place_id), {
...update,
planned_duration_minutes: null,
});
expect(result.tour.duration).toBe(45);
expect(result.tour.planned_duration_minutes).toBeNull();
});
it('RS-01: updates informational fields without overwriting Place or Wanderer provenance', async () => {
const created = await service.createTour(tripId, request);
testDb.prepare('UPDATE places SET source = ? WHERE id = ?').run('gpx-import:source-42', created.tour.place_id);
testDb
.prepare('UPDATE tours SET wanderer_ref = ? WHERE place_id = ?')
.run('wanderer:trail-42', created.tour.place_id);
const metadataUpdate = { ...update, description: 'Updated details', website: 'https://outdooractive.com/route/42' };
await service.updateTour(tripId, String(created.tour.place_id), metadataUpdate);
expect(
testDb.prepare('SELECT description, website, source FROM places WHERE id = ?').get(created.tour.place_id),
).toEqual({
description: 'Updated details',
website: 'https://outdooractive.com/route/42',
source: 'gpx-import:source-42',
});
expect(testDb.prepare('SELECT wanderer_ref FROM tours WHERE place_id = ?').get(created.tour.place_id)).toEqual({
wanderer_ref: 'wanderer:trail-42',
});
});
it('TOURS-SVC-006: rolls an invalid waypoint replacement back to the previous saved tour', async () => {
const created = await service.createTour(tripId, request);
broadcast.mockReset();