From 9b06bb88923807f23045fe3535783be938a75c5f Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 30 Nov 2026 14:37:34 +0100 Subject: [PATCH] fix(journey): keep the GPX day import out of the assistant and cover the set-based upsert The in-app assistant would be offered import_journey_gpx_days, whose only input is GPX text the model would have to write itself; a recorded route has to come from a real file, so the tool is denied there like upload_trip_file. External MCP clients keep it. JourneyRecordedDaysRepository.upsertDays had no repository test: add one for the empty list, a multi-row insert and a replace that keeps the id and the first time and leaves the other source's day alone. --- .../nest/assistant/assistant-tool-offer.ts | 1 + .../JourneyRecordedDays.repository.test.ts | 37 +++++++++++++++++++ .../assistant/assistant-tools.service.test.ts | 6 ++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/server/src/nest/assistant/assistant-tool-offer.ts b/server/src/nest/assistant/assistant-tool-offer.ts index 2532e3373..edb6ac302 100644 --- a/server/src/nest/assistant/assistant-tool-offer.ts +++ b/server/src/nest/assistant/assistant-tool-offer.ts @@ -86,6 +86,7 @@ export const ASSISTANT_DENIED_TOOLS: Readonly> = { import_places_from_url: 'fetches an address the model chooses', read_trip_file: 'would send documents such as passports to the AI provider', upload_trip_file: 'writes a file the model made up', + import_journey_gpx_days: 'keeps a recorded route, which must come from a real file, never one the model writes', create_category: 'changes the categories of every user', update_category: 'changes the categories of every user', delete_category: 'changes the categories of every user', diff --git a/server/tests/unit/db/repositories/JourneyRecordedDays.repository.test.ts b/server/tests/unit/db/repositories/JourneyRecordedDays.repository.test.ts index da40d000f..f5796e481 100644 --- a/server/tests/unit/db/repositories/JourneyRecordedDays.repository.test.ts +++ b/server/tests/unit/db/repositories/JourneyRecordedDays.repository.test.ts @@ -179,4 +179,41 @@ describe('JourneyRecordedDaysRepository', () => { expect(await days.deleteDay(j.id, '2026-05-14', 'gpx')).toBe(true); expect(await days.findDay(j.id, '2026-05-14', 'dawarich')).toMatchObject({ source: 'dawarich' }); }); + + it('JRDAYS-009: several days kept in one write replace only their own source and date, keeping id and first time', async () => { + const { user, journey: j } = await journey(); + await days.upsertDays([]); + expect(await countRows(t, JourneyRecordedDays, {})).toBe(0); + + const dawarichId = await days.upsertDay(day(j.id, user.id)); + await days.upsertDays([ + day(j.id, user.id, { source: 'gpx', content_hash: 'g'.repeat(64) }), + day(j.id, user.id, { source: 'gpx', local_date: '2026-05-15', content_hash: 'k'.repeat(64) }), + ]); + const first = await days.findDay(j.id, '2026-05-14', 'gpx'); + const longAgo = dbNow(new Date('2020-01-01T00:00:00Z')); + await updateRows(t, JourneyRecordedDays, { id: first?.id ?? 0 }, { created_at: longAgo, updated_at: longAgo }); + + await days.upsertDays([ + day(j.id, null, { source: 'gpx', content_hash: 'h'.repeat(64), point_count: 3, distance_m: null, truncated: 1 }), + ]); + + const replaced = await days.findDay(j.id, '2026-05-14', 'gpx'); + expect(replaced).toMatchObject({ + id: first?.id, + content_hash: 'h'.repeat(64), + point_count: 3, + distance_m: null, + truncated: 1, + imported_by: null, + created_at: longAgo, + }); + expect(replaced?.updated_at).not.toBe(longAgo); + expect(await days.findDay(j.id, '2026-05-14', 'dawarich')).toMatchObject({ + id: dawarichId, + content_hash: 'a'.repeat(64), + }); + expect(await days.findDay(j.id, '2026-05-15', 'gpx')).toMatchObject({ content_hash: 'k'.repeat(64) }); + expect(await countRows(t, JourneyRecordedDays, {})).toBe(3); + }); }); diff --git a/server/tests/unit/nest/assistant/assistant-tools.service.test.ts b/server/tests/unit/nest/assistant/assistant-tools.service.test.ts index 576b31541..5f33bdd5b 100644 --- a/server/tests/unit/nest/assistant/assistant-tools.service.test.ts +++ b/server/tests/unit/nest/assistant/assistant-tools.service.test.ts @@ -142,13 +142,15 @@ describe('the assistant tool catalog', () => { it('ASTTOOL-003: every registered tool that shares, invites or publishes is denied or only takes back', () => { expect(checkDenylist(listed.keys())).toEqual([]); - for (const name of [ + const denied = [ 'delete_trip', 'create_share_link', 'enable_trip_calendar_feed', 'import_places_from_url', 'delete_journey_photos', - ]) { + 'import_journey_gpx_days', + ]; + for (const name of denied) { expect(isOfferedTool(name), name).toBe(false); } for (const name of ['delete_place', 'list_upcoming_reservations', 'send_collab_message', 'toggle_vacay_entry']) {