mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
3f38621024
A trip can now turn a trip addon (lists, costs, documents, collab, road trip, tours) on or off for itself, whatever the instance switch says. No row in the new trip_addon_overrides table means the trip follows the instance; a row is the owner's choice. Going back to the instance setting deletes the row, and no addon data is touched either way. - GET/PUT /api/trips/:tripId/addons[/:addonId] (every member reads, the owner writes) and the MCP tools get_trip_addons and set_trip_addon, on the shared tripAddons contract; tripAddons:changed tells the members. - Every trip-scoped addon surface asks the trip: REST through TripAddonGuard, MCP through a per-call gate on the named or pinned trip, plugin RPC and events, the share link, the offline bundle, reminders, doc sync, the assistant (tools, keep_attached_file), booking costs, the trip summary prompt, and the cross-trip tour reads (library, Atlas stats, collection save). - Routes without a trip open while the addon is on in any of the user's trips. Switching an addon on that the instance has off ends the members' MCP sessions so they reconnect with its tools. - A copied trip takes its owner's choices along. Behaviour changes: an anonymous call to an addon route that is off now gets 401 instead of 404, and with an instance switch off the packing, todo and files plugin RPC methods, the files MCP tools, todo reminder mails, core plugin events, plugin view contributions, the share link's lists, costs and chat sections and the offline bundle's lists follow it.
113 lines
5.1 KiB
TypeScript
113 lines
5.1 KiB
TypeScript
/**
|
|
* P7: a route file attached in the trip chat, as the assistant proposes it:
|
|
* refused where tours are off, one held import per track (the GPX text on the
|
|
* held call only), the tracks the trip has or no import takes named in the
|
|
* read step and not proposed, at most a step's worth.
|
|
*/
|
|
import { AddonsService } from '../../../../src/nest/addons/addons.service';
|
|
import {
|
|
foundPlaceArgs,
|
|
IMPORT_TOUR_FILE_TOOL,
|
|
MAX_WRITES_PER_STEP,
|
|
READ_TOUR_FILE_TOOL,
|
|
writeToolOf,
|
|
} from '../../../../src/nest/assistant/assistant-tools.constants';
|
|
import { AssistantTourFileService } from '../../../../src/nest/assistant/assistant-tour-file.service';
|
|
import { DomainError } from '../../../../src/nest/common/domain-error';
|
|
import { TourFileReadService, type TourFileTrack } from '../../../../src/nest/tours/tour-file-read.service';
|
|
import { Test } from '@nestjs/testing';
|
|
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
// AST-TOUR-FILE-001 to AST-TOUR-FILE-005
|
|
|
|
const track = (name: string, over: Partial<TourFileTrack> = {}): TourFileTrack => ({
|
|
name,
|
|
gpx: `<gpx><trk><name>${name}</name></trk></gpx>`,
|
|
point_count: 120,
|
|
distance_km: 8.24,
|
|
has_heights: true,
|
|
duplicate: false,
|
|
...over,
|
|
});
|
|
|
|
function file(name: string): Express.Multer.File {
|
|
return { originalname: name, buffer: Buffer.from('<gpx/>'), size: 6 } as Express.Multer.File;
|
|
}
|
|
|
|
async function make(tracks: TourFileTrack[], opts: { tours?: boolean; whole?: boolean } = {}) {
|
|
const read = vi.fn(async () => ({ tracks, whole: opts.whole === true }));
|
|
const isEnabledForTrip = vi.fn(async () => opts.tours !== false);
|
|
const moduleRef = await Test.createTestingModule({
|
|
providers: [
|
|
AssistantTourFileService,
|
|
{ provide: TourFileReadService, useValue: { read } },
|
|
{ provide: AddonsService, useValue: { isEnabledForTrip } },
|
|
],
|
|
}).compile();
|
|
return { service: moduleRef.get(AssistantTourFileService), read, isEnabledForTrip };
|
|
}
|
|
|
|
describe('AssistantTourFileService', () => {
|
|
it('AST-TOUR-FILE-001: names its read step and the error of a file without a track', async () => {
|
|
const { service } = await make([]);
|
|
expect(service.readTool).toBe(READ_TOUR_FILE_TOOL);
|
|
expect(service.emptyCode).toBe('no_tracks_found');
|
|
});
|
|
|
|
it('AST-TOUR-FILE-002: refuses a route file where tours are off', async () => {
|
|
const { service, isEnabledForTrip } = await make([], { tours: false });
|
|
await expect(service.ensureReadable(7, 3, file('a.gpx'))).rejects.toBeInstanceOf(DomainError);
|
|
expect(isEnabledForTrip).toHaveBeenCalledWith(3, 'tours');
|
|
await expect((await make([])).service.ensureReadable(7, 3, file('a.gpx'))).resolves.toBeUndefined();
|
|
});
|
|
|
|
it('AST-TOUR-FILE-003: proposes one hike per track, the GPX text kept on the held call only', async () => {
|
|
const { service, read } = await make([track('Saturday'), track('Sunday')]);
|
|
const { found, proposals } = await service.propose(7, 5, file('weekend.gpx'));
|
|
expect(read).toHaveBeenCalledWith(5, expect.any(Buffer), 'weekend.gpx');
|
|
expect(proposals).toHaveLength(2);
|
|
expect(proposals[0]).toEqual({
|
|
toolName: IMPORT_TOUR_FILE_TOOL,
|
|
args: {
|
|
via: 'import_tour_gpx',
|
|
file_name: 'weekend.gpx',
|
|
tour_type: 'hike',
|
|
track_name: 'Saturday',
|
|
gpx: '<gpx><trk><name>Saturday</name></trk></gpx>',
|
|
},
|
|
shownArgs: { via: 'import_tour_gpx', file_name: 'weekend.gpx', tour_type: 'hike', track_name: 'Saturday' },
|
|
});
|
|
expect(found).toEqual({
|
|
tracks: [
|
|
{ name: 'Saturday', distance_km: 8.2, points: 120, has_heights: true },
|
|
{ name: 'Sunday', distance_km: 8.2, points: 120, has_heights: true },
|
|
],
|
|
});
|
|
});
|
|
|
|
it('AST-TOUR-FILE-004: names a track the trip has or no import takes, and proposes neither', async () => {
|
|
const { service } = await make([track('Known', { duplicate: true }), track('Huge', { gpx: null }), track('New')]);
|
|
const { found, proposals } = await service.propose(7, 5, file('mixed.kml'));
|
|
expect(proposals.map((proposal) => proposal.args.track_name)).toEqual(['New']);
|
|
expect(found.tracks).toEqual([
|
|
expect.objectContaining({ name: 'Known', skipped: 'already_in_trip' }),
|
|
expect.objectContaining({ name: 'Huge', skipped: 'too_large' }),
|
|
expect.objectContaining({ name: 'New' }),
|
|
]);
|
|
expect(found.proposed).toBe(1);
|
|
});
|
|
|
|
it('AST-TOUR-FILE-005: holds at most a step of tracks, runs each through import_tour_gpx with what it takes', async () => {
|
|
const many = Array.from({ length: MAX_WRITES_PER_STEP + 3 }, (_, index) => track(`Leg ${index}`));
|
|
const { service } = await make(many, { whole: true });
|
|
const { found, proposals } = await service.propose(7, 5, file('legs.gpx'));
|
|
expect(proposals).toHaveLength(MAX_WRITES_PER_STEP);
|
|
expect(found.whole_file).toBe(true);
|
|
const args = proposals[0]?.args ?? {};
|
|
expect(writeToolOf(IMPORT_TOUR_FILE_TOOL, args)).toBe('import_tour_gpx');
|
|
expect(foundPlaceArgs(args)).toEqual({ gpx: args.gpx, file_name: 'legs.gpx', tour_type: 'hike' });
|
|
expect(writeToolOf(IMPORT_TOUR_FILE_TOOL, { ...args, via: 'delete_place' })).toBe(IMPORT_TOUR_FILE_TOOL);
|
|
});
|
|
});
|