From 1b973ebd13cfdf298bd7830e00637068ace0660c Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sat, 3 Oct 2026 08:39:11 -0400 Subject: [PATCH] fix(write-path): a search hit's excerpt under `snippet` no longer 500s the prior-art route (#4768) #4768 "Write-path prior-art route 500s when a nameless search hit carries its excerpt under `snippet`": _prior_art_line read item["snippet"] as a snippet record's field dict, but a search hit carries its matched passage there as a string. Read the name only from a dict. Co-Authored-By: Claude Opus 5.5 --- src/scribe/services/plugin_context.py | 5 ++++- tests/test_write_path_trigger.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/scribe/services/plugin_context.py b/src/scribe/services/plugin_context.py index 8572e8b..8c20748 100644 --- a/src/scribe/services/plugin_context.py +++ b/src/scribe/services/plugin_context.py @@ -1698,8 +1698,11 @@ def _prior_art_line(item: dict, marker: str, owner: str | None, foreign_lang: st """ # The NAME, not the composed title (#4364) — a snippet's title carries its # whole trigger and ran to kilobytes on this line, again on every repeat. + # `snippet` is a snippet record's field dict — but on a search hit it is + # the matched excerpt, a string, under the same key. + fields = item.get("snippet") title = ( - item.get("name") or (item.get("snippet") or {}).get("name") + item.get("name") or (fields.get("name") if isinstance(fields, dict) else None) or (item.get("title") or "(untitled)") ).replace("\n", " ").strip() mark = f"{marker} · {foreign_lang}" if foreign_lang else marker diff --git a/tests/test_write_path_trigger.py b/tests/test_write_path_trigger.py index 14ce8ab..4d1440d 100644 --- a/tests/test_write_path_trigger.py +++ b/tests/test_write_path_trigger.py @@ -956,6 +956,17 @@ def test_prior_art_line_keeps_language_and_attribution_together(): assert "· python" in both and "shared by alex" in both +def test_prior_art_line_takes_a_search_hit_whose_snippet_is_its_excerpt(): + """A search hit carries its matched passage as a STRING under `snippet` — + the key a snippet record uses for its field dict. Reading it as the dict + 500'd the write-path route on any nameless hit.""" + from scribe.services.plugin_context import _prior_art_line + hit = {"id": 7, "title": "Paging contract", "snippet": "…the cursor is opaque…"} + assert _prior_art_line(hit, "similar 0.61", None) == '> - #7 [similar 0.61] "Paging contract"' + record = {"id": 8, "title": "long composed title", "snippet": {"name": "paginate"}} + assert _prior_art_line(record, "similar 0.70", None) == '> - #8 [similar 0.70] "paginate"' + + # --- the route between them -------------------------------------------------- def test_route_reads_every_arg_the_hook_sends():