feat(tours): round hikes, other ways of a leg and wanderer trails through the assistant

The assistant can now search a round hike of about a wished length from one
point and the router's other ways for one leg of a hike, with the planner's
own search, and propose each one as a hike card to compare and take. It can
also search the user's wanderer trails, preview one as a card, import it and
check a wanderer tour against its source.

The round search, its loop geometry, the test whether two lines are one way,
the other ways among a router's offers and the pins that hold a chosen way
move to @trek/shared; the planner and the road trip use them from there.
This commit is contained in:
Maurice
2026-10-23 21:15:37 +02:00
parent 338548bf7f
commit 14196358fb
74 changed files with 3031 additions and 438 deletions
@@ -28,7 +28,7 @@ import { makePackingBag, makePackingItem } from '../../helpers/factories/packing
import { makeCategory, makePlace, makeTag } from '../../helpers/factories/places';
import { makeReservation } from '../../helpers/factories/reservations';
import { createRow, findRow, insertRow, updateRows } from '../../helpers/factories/rows';
import { setAddonEnabled, setCollabFeature } from '../../helpers/factories/settings';
import { setAddonEnabled, setAppSetting, setCollabFeature } from '../../helpers/factories/settings';
import { makeTodoItem } from '../../helpers/factories/todos';
import { makeTour } from '../../helpers/factories/tours';
import { addTripMember, makeTrip, readTripDays } from '../../helpers/factories/trips';
@@ -221,6 +221,8 @@ export async function openHarness(): Promise<ParityHarness> {
const orm = app.get(MikroORM);
await oneByOne(Object.values(ADDON_IDS), (addon) => setAddonEnabled(orm, addon, true));
await oneByOne(['chat', 'notes', 'polls', 'whatsnext'] as const, (feature) => setCollabFeature(orm, feature, true));
// The wanderer tools show only while wanderer is allowed under Tours.
await setAppSetting(orm, 'tours_wanderer_enabled', 'true');
// The photo search tools show only while a provider is on.
await updateRows(orm, PhotoProviders, { id: { $in: ['immich', 'synologyphotos'] } }, { enabled: 1 });
@@ -5,6 +5,8 @@ import { TourWaypoints } from '../../../src/db/entities/TourWaypoints.entity';
import { Tours } from '../../../src/db/entities/Tours.entity';
import { RoadtripRouterService } from '../../../src/nest/roadtrip/roadtrip-router.service';
import { proposalIdOf } from '../../../src/nest/tours/tour-change-proposal';
import { ToursWandererService } from '../../../src/nest/tours/tours-wanderer.service';
import { WandererService } from '../../../src/nest/wanderer/wanderer.service';
import { makeDayAssignment } from '../../helpers/factories/itinerary';
import { makePlace } from '../../helpers/factories/places';
import { createRow, deleteRows, updateRows } from '../../helpers/factories/rows';
@@ -192,6 +194,53 @@ const gpxOf = (s: Scene) =>
`<gpx><trk><name>Ridge ${s.n}</name><trkseg><trkpt lat="47.6" lon="11.3"><ele>800</ele></trkpt>` +
'<trkpt lat="47.61" lon="11.3"><ele>1000</ele></trkpt></trkseg></trk></gpx>';
/** The fingerprint of the wanderer trail a case's setup previewed, by the scene's number. */
const trailHashFor = new Map<number, string>();
function trailHash(s: Scene): string {
const hash = trailHashFor.get(s.n);
if (hash === undefined) throw new Error(`scene ${s.n}: the case's setup previewed no trail`);
return hash;
}
/** No wanderer instance in a test: the owner's own trail, found and downloaded as the connection would. */
function wandererTrail(app: INestApplication): () => void {
const wanderer = app.get(WandererService);
const summary = {
id: 'trail-1',
name: 'Kesselberg',
description: null,
location: 'Kochel',
distanceM: 2200,
durationS: 3600,
elevationGainM: 200,
elevationLossM: 0,
difficulty: 'moderate' as const,
public: false,
author: 'owner',
line: [],
externalUrl: 'https://wanderer.example/trail/view/trail-1',
};
const found = vi.spyOn(wanderer, 'findTrail').mockResolvedValue(summary);
const download = vi.spyOn(wanderer, 'download').mockResolvedValue({
instance: 'https://wanderer.example',
trail: { id: 'trail-1', name: 'Kesselberg', description: null, author: 'owner', updated: null } as never,
gpx:
'<gpx><trk><name>Kesselberg</name><trkseg><trkpt lat="47.6" lon="11.3"><ele>800</ele></trkpt>' +
'<trkpt lat="47.62" lon="11.3"><ele>1000</ele></trkpt></trkseg></trk></gpx>',
});
return () => {
found.mockRestore();
download.mockRestore();
};
}
/** The trail previewed first, as the traveller sees it before the import: its fingerprint is what the import takes. */
async function previewTrail(s: Scene, app: INestApplication): Promise<void> {
const preview = await app.get(ToursWandererService).preview(String(s.trip.id), s.owner.id, 'trail-1');
trailHashFor.set(s.n, preview.contentHash);
}
const roadtripDay = (s: Scene) => `/api/trips/${s.trip.id}/roadtrip/days/${s.days[0].id}`;
const tourPath = (s: Scene) => `/api/trips/${s.trip.id}/tours/${s.tourPlace.id}`;
@@ -365,6 +414,18 @@ export const toursRoadtrip: CaseGroup = {
twin: 'POST /api/trips/:tripId/tours/import/gpx with the file',
expect: ['tours:changed', 'place:created'],
},
{
tool: 'import_wanderer_trail',
setup: previewTrail,
args: (s) => ({ tripId: s.trip.id, trailId: 'trail-1', contentHash: trailHash(s) }),
rest: {
method: 'post',
path: (s) => `/api/trips/${s.trip.id}/tours/wanderer/import`,
body: (s) => ({ trailId: 'trail-1', contentHash: trailHash(s) }),
},
stub: wandererTrail,
expect: ['tours:changed', 'place:created'],
},
{
tool: 'save_tour_change',
needs: ['tour'],