From 535503b73d2f88c230fce1c5a555fb9066f335cd Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 30 Nov 2026 14:46:20 +0100 Subject: [PATCH] fix(journey): keep photo deletes out of the assistant and never let the capture reader block an upload delete_journey_photos removes uploaded files for good and has no undo; its generic approval card could only list ids, so the assistant is not offered it. External MCP clients keep the tool. A HEIC upload no longer fails when the lazily loaded capture reader cannot be loaded: the photo goes up without its capture, as before. The upload schema's doc comment is back on the schema it describes. --- client/src/utils/convertHeic.test.ts | 11 ++++++++++- client/src/utils/convertHeic.ts | 18 ++++++++++++++++-- .../src/nest/assistant/assistant-tool-offer.ts | 1 + .../assistant/assistant-tools.service.test.ts | 8 +++++++- shared/src/journey/journey.schema.ts | 16 ++++++++-------- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/client/src/utils/convertHeic.test.ts b/client/src/utils/convertHeic.test.ts index 761f878f4..b5b9ea082 100644 --- a/client/src/utils/convertHeic.test.ts +++ b/client/src/utils/convertHeic.test.ts @@ -1,4 +1,4 @@ -// FE-W4HEIC-001 to FE-W4HEIC-010 +// FE-W4HEIC-001 to FE-W4HEIC-011 import { describe, it, expect, vi, beforeEach } from 'vitest' const isHeic = vi.fn(async (_f: File) => true) @@ -117,4 +117,13 @@ describe('normalizeJourneyPhotos', () => { expect(readHeicCapture).not.toHaveBeenCalled() expect(captureFields(out)).toEqual([]) }) + + it('FE-W4HEIC-011: a reader that fails costs the capture, never the upload', async () => { + readHeicCapture.mockRejectedValue(new Error('chunk failed to load')) + + const [out] = await normalizeJourneyPhotos([new File(['x'], 'c.heic')]) + + expect(out.name).toBe('c.jpg') + expect((out as CapturedFile).capture).toBeUndefined() + }) }) diff --git a/client/src/utils/convertHeic.ts b/client/src/utils/convertHeic.ts index 52577cfb0..2484e55b8 100644 --- a/client/src/utils/convertHeic.ts +++ b/client/src/utils/convertHeic.ts @@ -1,3 +1,4 @@ +import type { PhotoCapture } from './heicCapture' import type { CapturedFile } from './photoCapture' function looksLikeHeic(file: File): boolean { @@ -23,6 +24,20 @@ export async function normalizeImageFile(file: File): Promise { return (await convertHeic(file)) ?? file } +/** + * The HEIC's capture time and place, or null. The reader is a chunk of its own: + * when it cannot be loaded the photo still goes up, only without them. + */ +async function readCapture(file: File): Promise { + try { + const { readHeicCapture } = await import('./heicCapture') + return await readHeicCapture(file) + } catch { + // A chunk that failed to load costs the capture, never the upload. + return null + } +} + /** * A journey photo made ready to upload. A HEIC is converted like any other image, * but its capture time and place are read first and travel on the converted file @@ -32,8 +47,7 @@ export async function normalizeImageFile(file: File): Promise { */ async function normalizeJourneyPhoto(file: File): Promise { if (!looksLikeHeic(file)) return file - const { readHeicCapture } = await import('./heicCapture') - const capture = await readHeicCapture(file) + const capture = await readCapture(file) const converted: CapturedFile | null = await convertHeic(file) if (!converted) return file if (capture) converted.capture = capture diff --git a/server/src/nest/assistant/assistant-tool-offer.ts b/server/src/nest/assistant/assistant-tool-offer.ts index d45775fdf..2532e3373 100644 --- a/server/src/nest/assistant/assistant-tool-offer.ts +++ b/server/src/nest/assistant/assistant-tool-offer.ts @@ -62,6 +62,7 @@ export const ASSISTANT_DENIED_TOOLS: Readonly> = { add_journey_contributor: 'changes who can see the journey', update_journey_contributor_role: 'changes who can see the journey', remove_journey_contributor: 'changes who can see the journey', + delete_journey_photos: 'deletes uploaded photos for good, with no way back, and its card could only name their ids', invite_to_collection: 'invites a person; the model could pick whom', send_vacay_invite: 'invites a person; the model could pick whom', share_vacay_calendar: 'shares a calendar with a person', 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 3dec1022e..576b31541 100644 --- a/server/tests/unit/nest/assistant/assistant-tools.service.test.ts +++ b/server/tests/unit/nest/assistant/assistant-tools.service.test.ts @@ -142,7 +142,13 @@ 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 ['delete_trip', 'create_share_link', 'enable_trip_calendar_feed', 'import_places_from_url']) { + for (const name of [ + 'delete_trip', + 'create_share_link', + 'enable_trip_calendar_feed', + 'import_places_from_url', + 'delete_journey_photos', + ]) { expect(isOfferedTool(name), name).toBe(false); } for (const name of ['delete_place', 'list_upcoming_reservations', 'send_collab_message', 'toggle_vacay_entry']) { diff --git a/shared/src/journey/journey.schema.ts b/shared/src/journey/journey.schema.ts index 4f7b3899d..7e77d466f 100644 --- a/shared/src/journey/journey.schema.ts +++ b/shared/src/journey/journey.schema.ts @@ -366,14 +366,6 @@ export type JourneyEntryCreateRequest = z.infer; -/** - * Multipart field alongside the uploaded files. - * - * `.optional()` is not decoration: a multipart request with files and no text - * fields arrives with NO body at all, and the handler answers 'No files - * uploaded' for the empty case. Without this the pipe would answer - * 'body: Invalid input: expected object' first and the message would change. - */ /** * When and where an uploaded photo was taken, as the client read it from a HEIC * before converting it to a JPEG that no longer carries it (#3120). Multipart @@ -390,6 +382,14 @@ export const journeyPhotoCaptureFieldsSchema = z.object({ }); export type JourneyPhotoCaptureFields = z.infer; +/** + * Multipart field alongside the uploaded files. + * + * `.optional()` is not decoration: a multipart request with files and no text + * fields arrives with NO body at all, and the handler answers 'No files + * uploaded' for the empty case. Without this the pipe would answer + * 'body: Invalid input: expected object' first and the message would change. + */ export const journeyEntryPhotoUploadRequestSchema = z .looseObject({ caption: z.unknown().optional(),