* 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.
58 lines
2.2 KiB
Python
58 lines
2.2 KiB
Python
"""The browser resolver proves values from the same categories as the server.
|
|
|
|
#662 (N1): ``PROVEN_VALUE_CATEGORIES`` (utils/inspection_semantics.py) names
|
|
the semantics tables whose outputs always hold a value (#657). The Python
|
|
resolver reads it through ``Semantics.proves_value``; the browser resolver
|
|
(web/js/workspace/local-resolver.mjs) reads its copy in
|
|
local-resolver-support.mjs. This fails when the two copies drift apart.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import shutil
|
|
import subprocess # nosec B404 - fixed local Node command, no shell
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from utils import inspection_semantics # noqa: E402
|
|
|
|
SUPPORT = ROOT / "web" / "js" / "workspace" / "local-resolver-support.mjs"
|
|
PRINT_CONSTANTS = (
|
|
"const m = await import(process.argv[1]);"
|
|
"console.log(JSON.stringify({categories: [...m.PROVEN_VALUE_CATEGORIES],"
|
|
" byClass: [...m.PROVEN_BY_CLASS]}));"
|
|
)
|
|
|
|
|
|
class TestProvenValueParity(unittest.TestCase):
|
|
def browser_constants(self):
|
|
node = shutil.which("node")
|
|
if node is None: # pragma: no cover - CI runners and dev hosts ship Node
|
|
if os.environ.get("CI"):
|
|
self.fail("Node.js is required in CI for the resolver parity test")
|
|
self.skipTest("Node.js is not installed")
|
|
completed = subprocess.run( # nosec B603
|
|
[node, "--input-type=module", "-e", PRINT_CONSTANTS, SUPPORT.as_uri()],
|
|
capture_output=True,
|
|
timeout=60,
|
|
check=False,
|
|
)
|
|
self.assertEqual(completed.returncode, 0, completed.stderr.decode("utf-8"))
|
|
return json.loads(completed.stdout)
|
|
|
|
def test_the_browser_proves_the_same_categories_keyed_the_same_way(self):
|
|
found = self.browser_constants()
|
|
proven = inspection_semantics.PROVEN_VALUE_CATEGORIES
|
|
self.assertEqual(set(found["categories"]), set(proven))
|
|
self.assertEqual(len(found["categories"]), len(proven))
|
|
by_class = proven & set(inspection_semantics._CLASS_CATEGORIES)
|
|
self.assertEqual(set(found["byClass"]), by_class)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|