Files
TREK/server/tests/unit/nest/roadtrip-read-tools.test.ts
T
Maurice ed18c37903 fix: the findings of the final 4.3.0 audit
Every file the release touches was read once more, and what survived an
independent check against the code is fixed here, with a test for each.

Data and credentials
- A document sync connection edited to a new address no longer carries the
  stored token along: a blank form under another origin is refused, the same
  rule the probe route already had. Dawarich and AirTrail testConnection send
  the stored key only to the host it was stored for.
- The key rotation script now covers document_connections.secrets and
  trip_document_links.webhook_secret, which it had skipped.
- Turning a booked night into a pause in the road trip popup asks first and
  says that the booking and its expense go with it. Deleting a place says the
  same when a night is booked there, on the desktop and on the phone.
- A moved version marker over unchanged bytes no longer replaces the TREK file
  and its attachments; a real revision carries the attachments over.

Planner
- A drop in the day plan names the row it lands ahead of in the full day, so a
  hidden hotel stop no longer shifts it one slot early; the store sorts before
  it splices. Via re-anchoring, the booked-night guard and the sidebar's day
  membership read the stored day, the index space the server uses.
- A hotel stop placed mid-day re-pins the road trip vias of that day, and the
  booking session receives the new stop order too. The Public API and the iCal
  feed list a booked hotel once. A plugin can no longer write a stay against
  another trip's day.

Road trip and map
- The route overview paces its requests to the public routers and retries a
  rate limit, and it says which legs it could not route instead of quietly
  reporting a shorter trip. A click on a via handle no longer drops a second
  via; handles hide when zooming out. Read-only members cannot edit the driving
  limits. The phone shows a way back when no day is picked and prints the night
  drive departure in the chosen clock format.

Integrations and search
- Google transit keeps conventional trains when the train chip is on.
  TREK_PLACES_ENABLED=false stops the details and enrichment calls too, and
  accepts the whole boolean family. A caller-supplied description no longer
  lands in the instance-wide enrichment cache. Nominatim searches carry a
  timeout. An OSM place id is checked for shape before it reaches Overpass.
- Dawarich puts a stay on the trip whose dates hold it, the Atlas hand-off
  knows what the Atlas already shows, and a host change with a new key clears
  the old instance's state.
- Document sync: a webhook address pasted by hand works on the token alone,
  deleting a connection unregisters its subscriptions, Nextcloud under a
  sub-path connects, Synology answers a name collision before uploading and
  verifies a move into the bin, Paperless titles are capped at 128 characters,
  a DNS failure reads as unreachable rather than as a policy verdict, videos
  from the store are accepted like uploads, and remote_missing has a way out.
  Conflict buttons only for the owner, a refused choice is reported, a refused
  credential gets a Reconnect button, disconnecting asks first on the desktop
  as it does on the phone, and the folder picker no longer spins forever.

Release
- The server holds the release notice back from a bundle that cannot draw it,
  so the previous shell served from the service worker cache after an update
  no longer shows bare keys and no longer lets a click use the notice up.
- Import into an existing list gets the same body limit as a new list. Chat
  images say when the limit is reached and the new controls are translated.
  The transit backend switch reports a failed save. The Helm chart carries the
  Amap credentials in its Secret; the shipped templates document the Places
  API and Amap variables and the Overpass default. The wiki follows.
2026-09-20 13:54:31 +02:00

82 lines
5.3 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
import { HttpException } from '@nestjs/common';
import type { McpContext } from '../../../src/nest-mcp';
import { ChargingMcp } from '../../../src/nest/roadtrip/charging.mcp';
import { RoadtripHazardsMcp } from '../../../src/nest/roadtrip/roadtrip-hazards.mcp';
import { GoogleRouteMcp } from '../../../src/nest/roadtrip/google-route.mcp';
import { DayBoundariesMcp } from '../../../src/nest/roadtrip/day-boundaries.mcp';
const ctx = { userId: 5 } as McpContext;
describe('roadtrip read tools', () => {
it('checks trip access before querying charging and hazards', async () => {
const db = { canAccessTrip: vi.fn(() => false) };
const source = { read: vi.fn(async () => ({ sources: ['public'] })) };
const charging = new ChargingMcp(source as never, db as never, {} as never);
const hazards = new RoadtripHazardsMcp(source as never, db as never, {} as never);
expect((await charging.read({ tripId: 10, placeId: 2 }, ctx)).isError).toBe(true);
expect((await hazards.read({ tripId: 10 }, ctx)).isError).toBe(true);
expect(source.read).not.toHaveBeenCalled();
db.canAccessTrip.mockReturnValue(true);
expect(JSON.stringify(await charging.read({ tripId: 10, placeId: 2 }, ctx))).toContain('public');
expect(source.read).toHaveBeenCalledWith(10, 2);
expect(JSON.stringify(await hazards.read({ tripId: 10 }, ctx))).toContain('public');
});
it('passes reviewed Google stops and the authenticated user to the importer', async () => {
const routes = { preview: vi.fn(async () => ({ stops: [] })), import: vi.fn(() => ({ imported: 2 })) };
const auth = { isDemoUser: vi.fn(() => false) };
const tool = new GoogleRouteMcp(routes as never, auth as never, {} as never);
await tool.preview({ url: 'https://www.google.com/maps/dir/A/B' });
expect(routes.preview).toHaveBeenCalledWith('https://www.google.com/maps/dir/A/B');
const input = { tripId: 10, dayId: 1, stops: [{ name: 'A', lat: 1, lng: 2 }] };
expect(JSON.stringify(tool.import(input, ctx))).toContain('2');
expect(routes.import).toHaveBeenCalledWith(10, 5, input);
});
it('refuses the Google import for the demo account, like every other write tool', () => {
// The one non-admin write tool that had no gate: a demo session could write
// thirty places and their assignments onto the shared demo trip.
const routes = { preview: vi.fn(), import: vi.fn() };
const auth = { isDemoUser: vi.fn(() => true) };
const tool = new GoogleRouteMcp(routes as never, auth as never, {} as never);
const res = tool.import({ tripId: 10, dayId: 1, stops: [{ name: 'A', lat: 1, lng: 2 }] } as never, ctx);
expect(res.isError).toBe(true);
expect(routes.import).not.toHaveBeenCalled();
});
it('answers a refusal from the service with its reason, not with the exception class name', async () => {
// The services refuse with `{ error }` bodies the REST filter sends verbatim. Let
// through as exceptions, the SDK would show the assistant "Http Exception" and
// nothing else, so every tool on this surface answers them as error results.
const refuse = (error: string, status: number) => () => { throw new HttpException({ error }, status); };
const text = (res: { content: { text: string }[]; isError?: boolean }) => [res.isError, res.content[0].text];
const db = { canAccessTrip: vi.fn(() => true) };
const charging = new ChargingMcp({ read: refuse('Place not found', 404) } as never, db as never, {} as never);
expect(text(await charging.read({ tripId: 10, placeId: 2 }, ctx))).toEqual([true, 'Place not found']);
const auth = { isDemoUser: vi.fn(() => false) };
const routes = { preview: refuse('Use a Google Maps directions link.', 400), import: refuse('Permission denied', 403) };
const google = new GoogleRouteMcp(routes as never, auth as never, {} as never);
expect(text(await google.preview({ url: 'https://www.google.com/maps/place/A' }))).toEqual([true, 'Use a Google Maps directions link.']);
expect(text(google.import({ tripId: 10, dayId: 1, stops: [{ name: 'A', lat: 1, lng: 2 }] } as never, ctx))).toEqual([true, 'Permission denied']);
const realtime = { broadcast: vi.fn() };
const guards = { hasTripPermission: vi.fn(() => true) };
const boundaries = new DayBoundariesMcp({ save: refuse('Stop not found', 404) } as never, db as never, auth as never, guards as never, realtime as never, {} as never);
const boundary = { day_number: 1, from_assignment_id: 11, to_assignment_id: 12, fraction: 0.4 };
expect(text(await boundaries.save({ tripId: 10, dayNumber: 1, boundary }, ctx))).toEqual([true, 'Stop not found']);
expect(realtime.broadcast).not.toHaveBeenCalled();
});
it('does not expose manual boundaries to nonmembers', async () => {
const boundaries = { list: vi.fn(() => [{ day_number: 1 }]) };
const db = { canAccessTrip: vi.fn(() => false) };
const tool = new DayBoundariesMcp(boundaries as never, db as never, {} as never, {} as never, {} as never, {} as never);
expect((await tool.list({ tripId: 10 }, ctx)).isError).toBe(true);
expect(boundaries.list).not.toHaveBeenCalled();
db.canAccessTrip.mockReturnValue(true);
expect(JSON.stringify(await tool.list({ tripId: 10 }, ctx))).toContain('day_number');
expect(boundaries.list).toHaveBeenCalledWith(10);
});
});