From 3fc66ddd27dc72c04c1be70e73cf804d80fa2976 Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Thu, 19 Nov 2026 17:39:06 -0800 Subject: [PATCH] fix(inspect): read the history review item only when Inspect asks The run-history reader locates the file under the scan roots inside the read, so an unambiguous or linked file costs no realpath of the output folders. The docstring names the linked-subfolder limit, and the newest pending item test pins the rowid tie-break. Refs #659 --- py/api/history.py | 34 +++++++++++++++++++-------------- tests/test_inspection_review.py | 8 ++++++++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/py/api/history.py b/py/api/history.py index ddc56565..d3bd5edc 100644 --- a/py/api/history.py +++ b/py/api/history.py @@ -719,24 +719,30 @@ class HistoryRoutesMixin: ) return OWN_CATEGORY_UNREAD - def _history_review(self, target) -> Callable | None: + def _history_review(self, target) -> Callable: """The ``review`` reader of a reported current file (#659, C4). Located as the scan locates it (``_review_location`` over the scan - roots, resolved like the canonical target); a file under no scan root - gives None. The read closes its - connection, as this route's other reads do. + roots, resolved like the canonical target), only when the inspector + asks; a file under no scan root reads None. A file reached through a + linked subfolder is keyed by its resolved path here, so an item the + scan stored under the linked spelling is not found (None, no choice). + The read closes its connection, as this route's other reads do. """ - # The target is canonical, so the roots are too (a linked output). - roots = _scan_roots( - [os.path.realpath(root) for root in self._get_all_output_dirs()] - ) - located = self._review_location(target, roots) - if located is None: - return None - return review_reader( - self.db, os.path.normcase(located[3]), self.logger, close=True - ) + + def read(size: int, mtime_ns: int) -> dict | None: + roots = _scan_roots( + [os.path.realpath(root) for root in self._get_all_output_dirs()] + ) + located = self._review_location(target, roots) + if located is None: + return None + locator = os.path.normcase(located[3]) + return review_reader(self.db, locator, self.logger, close=True)( + size, mtime_ns + ) + + return read async def _history_current( self, request: web.Request, kind: str diff --git a/tests/test_inspection_review.py b/tests/test_inspection_review.py index 33195812..12d57624 100644 --- a/tests/test_inspection_review.py +++ b/tests/test_inspection_review.py @@ -136,6 +136,14 @@ class TestReviewItemAt(ReviewItemsMixin, ImageAPITestCase): self.api.db.review_item_at(*self.stat(path)), {"state": "pending", "item_id": newest}, ) + # Recorded within one timestamp: the later insert is still the newest. + conn = self.api.db.model.get_connection() + with conn: + conn.execute("UPDATE media_review_items SET created_at=?", (NOW,)) + self.assertEqual( + self.api.db.review_item_at(*self.stat(path)), + {"state": "pending", "item_id": newest}, + ) async def test_decided_item_is_decided(self): path = png(self.output_dir / "a.png", prompt=two_samplers())