From ffd4b2caa31758de6eb82786e187db4b2356d5f5 Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Wed, 21 Oct 2026 03:47:11 -0700 Subject: [PATCH] fix(inspector): treat Unicode whitespace as a blank History recipe category --- tests/test_history_current.py | 45 +++++++++++++++++++++++++++++++++++ utils/inspection_response.py | 2 ++ 2 files changed, 47 insertions(+) diff --git a/tests/test_history_current.py b/tests/test_history_current.py index e7ce4e9..8d5c379 100644 --- a/tests/test_history_current.py +++ b/tests/test_history_current.py @@ -374,6 +374,51 @@ class CurrentLocationTests(unittest.TestCase): expected, ) + def test_gallery_blank_recipe_category_and_skipped_positive_tags_query(self): + mod = self.module("database.history_gallery") + db = PromptDatabase(str(self.base / "blank.db")) + self.addCleanup(db.close_all) + cases = ( + (" ", ["recipe"], 0), + ("\u3000", [], 1), + ("\u00a0 ", ["recipe"], 0), + ) + for index, (blank, recipe_tags, positive_tag_queries) in enumerate(cases): + with self.subTest(case=index): + text = f"blank owner {index}" + positive = db.save_prompt( + text, + prompt_hash=generate_prompt_hash(text), + category="Positive cat", + ) + db.set_prompt_tags(positive, ["positive"]) + pair = db.save_prompt_pair(text, "noise", tags=recipe_tags) + path = make_png(self.output / f"blank-{index}.png") + locator = os.path.normcase(str(path)) + image = db.link_image_to_prompt(positive, str(path)) + db.link_image_to_pair(pair, image, {"source": "fixture"}) + conn = db.model.get_connection() + # Legacy rows can hold a blank-looking category the writers now trim. + conn.execute( + "UPDATE prompt_pairs SET category=? WHERE id=?", (blank, pair) + ) + conn.commit() + statements = [] + conn.set_trace_callback(statements.append) + self.addCleanup(conn.set_trace_callback, None) + with db.recorded_history_snapshot(): + result = mod.read_history_gallery(conn, (locator,)) + conn.set_trace_callback(None) + library = result[locator]["library"] + self.assertEqual(library["category"], "Positive cat") + self.assertEqual(library["category_scope"], "positive") + tag_queries = [ + statement + for statement in statements + if "FROM prompt_tags pt" in statement + ] + self.assertEqual(len(tag_queries), positive_tag_queries, statements) + def test_host_root_failure_and_removal_do_not_search_another_root(self): make_png(self.output / "image.png") make_png(self.temp / "image.png") diff --git a/utils/inspection_response.py b/utils/inspection_response.py index ebb0100..84d4530 100644 --- a/utils/inspection_response.py +++ b/utils/inspection_response.py @@ -290,6 +290,8 @@ def _file_projection(file: dict, inspection: "InspectionRead | None") -> dict: def _blank(value: str | bytes | None) -> bool: + if isinstance(value, bytes): + value = value.decode("utf-8", "replace") return value is None or not value.strip()