From dc977fdb6ba2ecc374e60fad5a70efeb7aa09db0 Mon Sep 17 00:00:00 2001 From: paula-alves Date: Tue, 3 Nov 2026 12:21:34 +0000 Subject: [PATCH] fix(app): guard USB auto-ingest against a shell status without files (BIT-32038) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The auto-ingest effect in useUsbCamera read status.files.filter directly, guarded only by status?.tether. The Rust side always serializes files as an array, but nothing on the TS side enforces that invariant on the IPC boundary, and a status shape missing files (e.g. a stale/partial Tauri response) crashed with "undefined is not an object (evaluating 'i.files.filter')" during the passive-effects flush, matching the desktop error loop report. Default to an empty array like the render path at UsbCameraButton already does. Paperclip-Agent: José Alves (urlKey jos-alves; id 11179220-3cec-4f0f-880d-2771ff64fce8) Paperclip-Issue: BIT-32038 Paperclip-Run: 68339729-e8a7-47bb-ac2b-20ba0f3189dd --- apps/app/src/library/UsbCamera.test.tsx | 16 ++++++++++++++++ apps/app/src/library/UsbCamera.tsx | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/app/src/library/UsbCamera.test.tsx b/apps/app/src/library/UsbCamera.test.tsx index fe07002..d2d11c9 100644 --- a/apps/app/src/library/UsbCamera.test.tsx +++ b/apps/app/src/library/UsbCamera.test.tsx @@ -2,6 +2,7 @@ import { render, renderHook, screen, waitFor } from "@testing-library/react"; import type { EventSummary } from "@photoreport/sdk"; import { describe, expect, it, vi } from "vitest"; import type { Invoke } from "./LocalFtp.js"; +import { prefs } from "../platform.js"; import type { UploadStatus } from "./uploads.js"; import { UsbCameraButton, type UsbStatus, inEventWindow, useUsbCamera, withSidecars } from "./UsbCamera.js"; @@ -86,6 +87,21 @@ describe("usb tether", () => { expect(withSidecars(["IMG_0002.JPG"], camera.files)).toEqual(["IMG_0002.JPG"]); }); + it("does not crash auto-ingest when the shell status omits files", async () => { + vi.spyOn(prefs, "get").mockReturnValue("1"); + const invoke = vi.fn(async (cmd: string) => { + if (cmd === "camera_status") return { supported: true, tether: true, devices: [] } as unknown as UsbStatus; + if (cmd === "camera_take") return []; + return null; + }) as unknown as Invoke; + const add = () => {}; + const { result } = renderHook(() => + useUsbCamera(add, true, { id: "ev1", title: "Portugal x Suíça", date: "2026-11-04", ingestFrom: "2026-11-04T18:00:00Z", ingestUntil: "2026-11-04T23:00:00Z" }, invoke), + ); + await waitFor(() => expect(result.current.status?.tether).toBe(true)); + vi.restoreAllMocks(); + }); + it("only treats shots inside the event ingest window as auto-eligible", () => { const from = "2026-11-03T18:00:00.000Z"; const until = "2026-11-03T23:00:00.000Z"; diff --git a/apps/app/src/library/UsbCamera.tsx b/apps/app/src/library/UsbCamera.tsx index 16e5c77..933b668 100644 --- a/apps/app/src/library/UsbCamera.tsx +++ b/apps/app/src/library/UsbCamera.tsx @@ -174,12 +174,13 @@ export function useUsbCamera(add: Add, enabled: boolean, target: FtpTarget | nul // New tethered shots inside the event window only — never the rest of the card / other days. useEffect(() => { if (!autoIngest || !status?.tether || !target?.ingestFrom || !target.ingestUntil) return; - const due = status.files.filter( + const files = status.files ?? []; + const due = files.filter( (f) => /\.jpe?g$/i.test(f.name) && f.isNew && !f.imported && inEventWindow(f, target.ingestFrom, target.ingestUntil) && !autoAsked.current.has(f.name), ); if (!due.length) return; for (const f of due) autoAsked.current.add(f.name); - void importFiles(withSidecars(due.map((f) => f.name), status.files)); + void importFiles(withSidecars(due.map((f) => f.name), files)); }, [autoIngest, status, target, importFiles]); return { status, outdated, counts, setTether, syncClock, importFiles, refresh, autoIngest, setAutoIngest };