From aaac2cc3b2dcbb44a2563d93ce1462159875a3fd Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Tue, 17 Nov 2026 11:34:55 -0800 Subject: [PATCH] fix(paths): Needs review and tagging take a backslash name too (#646) Needs review built its own image entries without the POSIX mark, so Open and Info still failed there for a name holding a backslash (Codex P2). The review target now carries path_style like the Images listing, and imageOf passes it on. The capture store, which tagging and review read through, refused every backslash; it now refuses one only on Windows. Before this, such a file could not be tagged and never reached Needs review. --- py/api/review.py | 3 +++ tests/js/workspace-review-image.test.js | 25 +++++++++++++++++++++++++ tests/test_api_annotations.py | 11 +++++++++++ tests/test_api_review.py | 17 +++++++++++++++++ tests/test_media_capture.py | 15 ++++++++++++++- utils/media_capture.py | 8 ++++++-- web/js/workspace/review.mjs | 2 ++ 7 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 tests/js/workspace-review-image.test.js diff --git a/py/api/review.py b/py/api/review.py index 43903265..32832ab1 100644 --- a/py/api/review.py +++ b/py/api/review.py @@ -273,6 +273,9 @@ class ReviewRoutesMixin: "root_scope": self._gallery_root_scope(roots[index], index), "path": relative, } + if "\\" in relative: + # #646: the mark the Images listing sets (POSIX only). + target["path_style"] = "posix" # The Images listing's media URL for the same file (formatting only). url = ( "/prompt_manager/images/serve/" diff --git a/tests/js/workspace-review-image.test.js b/tests/js/workspace-review-image.test.js new file mode 100644 index 00000000..bdae93e2 --- /dev/null +++ b/tests/js/workspace-review-image.test.js @@ -0,0 +1,25 @@ +// #646: Needs review hands the viewer and inspector the same identity the Images listing does, the POSIX mark +// for a name holding a backslash included. +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { imageOf } from '../../web/js/workspace/review.mjs'; +import { inspectPath } from '../../web/js/workspace/inspection-state.mjs'; + +const scope = 'a'.repeat(64); +const item = target => ({ filename: 'a.png', target, url: '/u', thumbnail_url: null, is_video: false }); + +test('a review item keeps the POSIX mark of a name holding a backslash', () => { + const path = 'm.safetensors\\2026-11-17/a.png'; + const image = imageOf(item({ root_index: 0, root_scope: scope, path, path_style: 'posix' })); + assert.equal(image.path_style, 'posix'); + assert.equal(inspectPath(image), `/prompt_manager/images/inspect/m.safetensors%5C2026-11-17/a.png?root=0&root_scope=${scope}`); +}); + +test('a review item without the mark, or with another value, carries none', () => { + for (const path_style of [undefined, 'windows', 'POSIX']) { + const image = imageOf(item({ root_index: 0, root_scope: scope, path: 'a\\b.png', path_style })); + assert.equal(Object.hasOwn(image, 'path_style'), false); + assert.throws(() => inspectPath(image), /Invalid inspection identity/); + } + assert.equal(Object.hasOwn(imageOf(item({ root_index: 0, root_scope: scope, path: 'p/a.png' })), 'path_style'), false); +}); diff --git a/tests/test_api_annotations.py b/tests/test_api_annotations.py index 6dc3f1f6..4326a6c8 100644 --- a/tests/test_api_annotations.py +++ b/tests/test_api_annotations.py @@ -404,6 +404,17 @@ class TestObserve(AnnotationAPITestCase): self.assertEqual(response.headers["Content-Type"], "video/mp4") self.assertEqual(await response.read(), clip.read_bytes()) + @unittest.skipIf(os.sep == "\\", "a backslash cannot be in a Windows name") + async def test_a_backslash_inside_a_name_can_be_tagged_on_posix(self): + # #646: a Windows-style filename_prefix makes such a folder on POSIX. + path = "m.safetensors\\2026-11-17/a.png" + make_png(self.output_dir / "m.safetensors\\2026-11-17" / "a.png") + observed = await self.observe_ok(path) + self.assertEqual(observed["target"]["path"], path) + status, body = await self.put_tags(self.save_body(observed, ["forest"])) + self.assertEqual(status, 200, body) + self.assertEqual((await self.observe_ok(path))["tags"], ["forest"]) + async def test_observe_maps_capture_outcomes_to_codes(self): make_png(self.output_dir / "sub" / "a.png") outside = make_png(self.comfy_dir / "outside.png") diff --git a/tests/test_api_review.py b/tests/test_api_review.py index 0e19c6ed..23e3d685 100644 --- a/tests/test_api_review.py +++ b/tests/test_api_review.py @@ -14,6 +14,7 @@ import os import posixpath import sqlite3 import threading +import unittest from pathlib import Path from unittest.mock import patch @@ -452,6 +453,22 @@ class TestQueueReads(ReviewRoutesTestCase): ) +class TestBackslashNames(ReviewRoutesTestCase): + """#646: a review item in a folder whose name holds a backslash (POSIX).""" + + @unittest.skipIf(os.sep == "\\", "a backslash cannot be in a Windows name") + async def test_the_target_carries_the_posix_mark(self): + self._require_routes() + self._record(self._ambiguous("m.safetensors\\2026-11-17/a.png")) + self._record(self._ambiguous("plain/b.png", color=(0, 255, 0))) + items = {item["filename"]: item for item in (await self._list())["items"]} + marked = items["a.png"]["target"] + self.assertEqual(marked["path"], "m.safetensors\\2026-11-17/a.png") + self.assertEqual(marked["path_style"], "posix") + self.assertFalse(items["a.png"]["unavailable"]) + self.assertNotIn("path_style", items["b.png"]["target"]) + + class TestDecisions(ReviewRoutesTestCase): async def test_apply_candidate_links_pair_and_records_decision_atomically(self): self._require_routes() diff --git a/tests/test_media_capture.py b/tests/test_media_capture.py index e4790f1e..1f57b2c2 100644 --- a/tests/test_media_capture.py +++ b/tests/test_media_capture.py @@ -135,6 +135,18 @@ class CaptureStoreTestCase(unittest.TestCase): # -- exact bytes and identity ------------------------------------------- + @unittest.skipIf(os.sep == "\\", "a backslash cannot be in a Windows name") + def test_a_backslash_inside_a_name_is_captured_on_posix(self): + # #646: a Windows-style filename_prefix makes such a folder on POSIX. + data = png_bytes(2, 2, b"backslash") + self.write("m.safetensors\\2026-11-17/a.png", data) + store = self.make_store() + cap = self.capture(store, "m.safetensors\\2026-11-17/a.png") + try: + self.assertEqual(Path(cap.path).read_bytes(), data) + finally: + store.release(cap.token) + def test_capture_hashes_and_copies_exact_bytes_owner_only(self): source_bytes = png_bytes(3, 2, os.urandom(40)) source = self.write("a.png", source_bytes) @@ -212,7 +224,8 @@ class CaptureStoreTestCase(unittest.TestCase): "", "/a.png", "C:/a.png", - "a\\b.png", + # #646: a backslash separates folders only on Windows. + *(["a\\b.png"] if os.sep == "\\" else []), "a\x00.png", "notes.txt", "folder", diff --git a/utils/media_capture.py b/utils/media_capture.py index c978305b..3d3a1f3e 100644 --- a/utils/media_capture.py +++ b/utils/media_capture.py @@ -659,12 +659,16 @@ def header_dimensions(path: str) -> tuple[int, int]: def _relative_parts(relative) -> tuple[list[str], str]: - """Split a safe relative POSIX media path; anything else is denied.""" + """Split a safe relative POSIX media path; anything else is denied. + + A backslash is denied on Windows, where it separates folders; on POSIX it + is part of a name (#646), and ``_resolve`` still checks the joined path. + """ if not isinstance(relative, str) or not relative: raise CaptureDenied("Invalid file path") if len(relative) > MAX_RELATIVE_LENGTH or "\x00" in relative: raise CaptureDenied("Invalid file path") - if "\\" in relative or relative.startswith("/"): + if ("\\" in relative and os.sep == "\\") or relative.startswith("/"): raise CaptureDenied("Invalid file path") parts = relative.split("/") for part in parts: diff --git a/web/js/workspace/review.mjs b/web/js/workspace/review.mjs index ac959a06..afaebdc2 100644 --- a/web/js/workspace/review.mjs +++ b/web/js/workspace/review.mjs @@ -73,6 +73,8 @@ const isDisabled = button => button.getAttribute('aria-disabled') === 'true'; export function imageOf(item) { const target = item.target ?? {}; return { filename: item.filename, root_index: target.root_index, root_scope: target.root_scope, path: target.path, + // #646: a POSIX server's mark for a name holding a backslash, as the Images listing sends it. + ...(target.path_style === 'posix' ? { path_style: 'posix' } : {}), url: item.url, thumbnail_url: item.thumbnail_url ?? null, is_video: item.is_video === true, media_type: item.is_video ? 'video' : 'image' }; }