fix(diagnostics): fresh-session + quote-fold in fiction_wing_probe

Two bugs R42 (brokkr-smithy-dev) surfaced on first live-index contact:

1. Session-reuse degradation. run_yardstick/run_term reused one mimir
   session across terms; mimir returns EMPTY search_library results after
   a session's first query (Worldtree #391), silently scoring every later
   term a false-MISS. Fixed by making search_library and reference_knowledge
   self-session (fresh session per call) so no caller can re-hoist it. Live
   yardstick now reproduces all four anchors HIT top-10. Fresh-session-per-
   query is the pinned arm-2 protocol; folded into the conventions docstring.

2. Curly-vs-ASCII apostrophe. _on_target substring-matched raw ASCII while
   the b170 extraction stores U+2019, so possessive-named subjects
   false-MISSed. _on_target now NFKC-normalizes + quote-folds both sides
   (NFKC alone does not fold U+2019, so the explicit fold is load-bearing).

Adds tests/test_fiction_wing_probe.py covering the apostrophe fold both
directions with a negative control.
This commit is contained in:
vh
2026-08-04 17:00:52 -07:00
parent e8e1d90915
commit 2111b1e824
2 changed files with 73 additions and 12 deletions
+33
View File
@@ -0,0 +1,33 @@
"""Unit tests for the fiction-wing probe harness's pure helpers.
Only the network-free helpers are covered here; the live retrieval paths
(search_library / reference_knowledge) are exercised by running the harness
against a live Worldtree index, not by pytest.
"""
import sys
from pathlib import Path
_DIAG = Path(__file__).resolve().parent.parent / "docs" / "diagnostics"
sys.path.insert(0, str(_DIAG))
from fiction_wing_probe import _on_target # noqa: E402
CURLY = "’" # noqa: RUF001 - the b170 extraction's default apostrophe
def test_on_target_matches_curly_apostrophe_excerpt():
# Excerpt stores the curly apostrophe; keyword is ASCII. Must still match.
excerpt = f"Mr. Darcy{CURLY}s letter to Elizabeth explains his conduct."
assert _on_target(excerpt, ["darcy's letter"])
def test_on_target_matches_ascii_excerpt_against_curly_keyword():
# Symmetric: ASCII excerpt, curly-quoted keyword. Fold both sides.
excerpt = "Mrs. Gardiner's letter arrived the next morning."
assert _on_target(excerpt, [f"gardiner{CURLY}s letter"])
def test_on_target_still_rejects_absent_subject():
# Negative control: folding must not make unrelated excerpts match.
excerpt = "A passage about dungeons, crawlers, and monsters."
assert not _on_target(excerpt, ["darcy's letter"])