Files
Vito 6f02277a1c fix: small cleanup from the audit true-up (#662) (#665)
* refactor(api): one bounded JSON body reader for the API and images.py (#662)

images.py kept its own copy of the chunked, capped JSON object reader.
Both now use py/api/json_body.py; images.py keeps its 1 MiB cap and its
raising form for the thumbnail job.

* fix(api): refuse malformed bodies on the legacy prompt routes with a 400 (#662)

PUT /prompts/{id}, PUT /prompts/{id}/rating, POST and DELETE
/prompts/{id}/tags, POST /prompts/tags, PUT /tags/{tag}, POST /tags/merge
and POST /bulk/delete|tags|category read the body with the bounded JSON
reader /save uses and check field types, so a body that is not a JSON
object, or a field such as {"text": 123}, is a 400 instead of a 500.
A prompt id may still be a number or its text, as the legacy page sends
it; a boolean is refused (prompt_ids [true] deleted prompt 1).
POST /jobs/image-tags refuses a mode that is no text instead of a 500.

* refactor(inspect): both resolvers read PROVEN_VALUE_CATEGORIES (#662)

proves_value hard-coded the four tables in Python and in the browser.
Semantics.proves_value now reads the constant (class-keyed categories by
class, the rest by output slot), the browser resolver loops over its
mirrored copy in local-resolver-support.mjs, and
tests/test_proven_value_parity.py fails when that copy drifts. A test
patches the constant to show the resolver follows it.

* refactor: remove the write-only preview batch count and the test-only node search (#662)

AutoThumbnailWorker set self._batch in four places and never read it.
PromptManagerBase._search_prompts had no caller but its own tests: the
node UIs search through GET /prompt_manager/search. Prompt search itself
stays covered by the database and route tests.

* fix(tools): open libraries through the shared read-only URI helper (#662)

review_image_links, repair_foreign_links (twice) and workflow_text_digests
built their own file: URIs, which SQLite refuses for a library on a
Windows network share (file://server/share/...). They now use
database/sqlite_uri.readonly_uri; repair_foreign_links opens its own
read-write backup by path. The guard in tests/test_sqlite_uri.py scans
tools/ too and also catches a conditional ?mode=ro suffix.

* ci: bound the publish and Viewer.js update jobs by measured limits (#662)

publish.yml and viewerjs-update.yml had no timeout-minutes, and the
workflow guard listed only four workflows. The guard now reads every
workflow and recomputes both new limits from their comments: publish
5 min from its last three green runs; the Viewer.js update 18 min, from
an estimate of its never-run update path (the three measured nightly
runs found no release and give the 5-minute floor).

* docs: correct the redesign plan's CI and PR rules, renumber the second D205 (#662)

docs/application-redesign.md named a Python 3.10-3.13 matrix with macOS,
asked for PR screenshots and said Overview links the legacy metadata
page. It now names the 3.12 floor and the current Linux/Windows split,
asks for visual changes in words, and says the metadata page is reached
by address or from the legacy admin page. TESTING.md used D205 for both
#431 (saved instructions) and #620 (Library sorts); #620's entry is
D206 now.
2026-11-21 09:46:31 -08:00

42 lines
1.4 KiB
Python

"""Every read-only SQLite open uses one URI helper (#620).
pathlib writes a Windows network path as ``file://server/share/x.db``, which
SQLite refuses. A reader that builds its own URI breaks backups, restores,
library moves or history reads for a library on a network share.
"""
import re
import sys
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from database.sqlite_uri import readonly_uri # noqa: E402
class TestReadonlyUri(unittest.TestCase):
def test_a_network_path_has_an_empty_authority(self):
self.assertEqual(
readonly_uri(r"\\server\share\Comfy UI\prompts.db", windows=True),
"file:////server/share/Comfy%20UI/prompts.db?mode=ro",
)
def test_no_reader_builds_its_own_uri(self):
offenders = []
# #662: the repair and review tools open libraries too.
for folder in ("database", "py", "utils", "tools"):
for path in (ROOT / folder).rglob("*.py"):
if path.name == "sqlite_uri.py":
continue
text = path.read_text(encoding="utf-8")
# Also ``as_uri() + ("?mode=ro" if ... else "")``.
if re.search(r"as_uri\(\)\s*\+\s*\(?\s*[\"']\?mode=ro", text):
offenders.append(path.relative_to(ROOT).as_posix())
self.assertEqual(offenders, [])
if __name__ == "__main__":
unittest.main()