Files
bikoret/korban_processor/test/test_zerikah.py
T
Scott KarpandClaude Fable 5.1 ad27d3c037 tablet 58: the tool's answer is given — tool results are sources; markers on word boundaries
The sugya reply came back lo_tov — golden_calf on two sentences the
builder had just read from tool output (the Mishnah's reasons, from the
second scroll; the commit and pod, from its own tools). The gate's
sources were only the user turns' text and document blocks; a
tool_result block and a tool turn — what the model was GIVEN (tablet
49) — were not counted. And "shorashim-675b…" was vital because the
insight markers matched "Rashi" inside it.

- Shape.sources: Anthropic tool_result blocks (string or blocks) inside
  a user turn, and OpenAI role "tool" turns, are sources; the query is
  still the last user turn. gate_test: both shapes.
- zerikah._INSIGHT_MARKERS: \b…\b. test_zerikah: the pod name is not
  Rashi; "Rashi reads" and "The Mishnah records" are; "Rambanovich" and
  "talmudic_engine" are not.
- Tablet 58 in the Broken Tablets.

Elixir 643/0, korban 294/0. Doorpost pin unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-21 20:56:25 +00:00

202 lines
7.4 KiB
Python

"""
Tests for zerikah — extract vital content.
BUILD_KORBAN.md Verification §2:
Feed it a stripped response. Verify it extracts Torah references accurately,
identifies Hebrew roots, and separates vital content from discardable material.
Architecture §3.5: zerikah extracts Torah references, Hebrew text, root
analysis, novel insights, logical propositions. Records discards.
"""
from korban_processor.korban import Korban, OfferingType, Provenance
from korban_processor.zerikah import (
zerikah,
is_vital,
extract_torah_references,
extract_hebrew_words,
extract_roots,
split_sentences,
)
from test.fixtures import CLEAN_TORAH_RESPONSE, LATIN_TORAH_RESPONSE
def make_korban(content: str) -> Korban:
return Korban(
raw_content=content,
provenance=Provenance.CLAUDE,
offering_type=OfferingType.OLAH,
source_query="test query",
)
class TestIsVital:
def test_torah_reference_is_vital(self):
assert is_vital("Genesis 1:1 begins the Torah.")
def test_bereishit_reference_is_vital(self):
assert is_vital("Bereishit 1:1 opens with creation.")
def test_exodus_reference_is_vital(self):
assert is_vital("Exodus 3:14 reveals the divine name.")
def test_hebrew_text_is_vital(self):
assert is_vital("The word בְּרֵאשִׁית opens the Torah.")
def test_root_notation_is_vital(self):
assert is_vital("The root ר-א-ש means head or beginning.")
def test_rashi_reference_is_vital(self):
assert is_vital("Rashi explains this verse in his commentary.")
def test_gematria_mention_is_vital(self):
assert is_vital("The gematria of this word is 613.")
def test_binyan_mention_is_vital(self):
assert is_vital("The verb is in the piel binyan, indicating intensity.")
def test_means_insight_is_vital(self):
assert is_vital("The root means 'to create from nothing' in this context.")
def test_indicates_insight_is_vital(self):
assert is_vital("This word indicates a continuous action.")
def test_generic_filler_not_vital(self):
assert not is_vital("There are many perspectives on this topic.")
def test_empty_sentence_not_vital(self):
assert not is_vital("")
def test_whitespace_only_not_vital(self):
assert not is_vital(" ")
class TestExtractTorahReferences:
def test_extracts_genesis(self):
refs = extract_torah_references("See Genesis 1:1 and Genesis 2:3.")
assert len(refs) == 2
assert any("Genesis 1:1" in r for r in refs)
assert any("Genesis 2:3" in r for r in refs)
def test_extracts_bereishit(self):
refs = extract_torah_references("Bereishit 1:1 is the first verse.")
assert len(refs) == 1
assert "Bereishit 1:1" in refs[0]
def test_extracts_exodus(self):
refs = extract_torah_references("Exodus 3:14 reveals Ehyeh asher Ehyeh.")
assert len(refs) >= 1
def test_extracts_multiple_books(self):
text = "Genesis 1:1, Exodus 3:14, Leviticus 19:18, Numbers 15:38, Deuteronomy 6:4."
refs = extract_torah_references(text)
assert len(refs) == 5
def test_no_refs_returns_empty(self):
refs = extract_torah_references("This is general commentary without citations.")
assert refs == []
class TestExtractHebrewWords:
def test_extracts_hebrew_word(self):
words = extract_hebrew_words("The word בְּרֵאשִׁית opens Torah.")
assert len(words) >= 1
assert any("בר" in w or "בְּר" in w for w in words)
def test_extracts_multiple_hebrew_words(self):
words = extract_hebrew_words("בְּרֵאשִׁית בָּרָא אֱלֹהִים")
assert len(words) >= 3
def test_no_hebrew_returns_empty(self):
words = extract_hebrew_words("No Hebrew here, only Latin script.")
assert words == []
class TestExtractRoots:
def test_extracts_dash_separated_root(self):
roots = extract_roots("The root ר-א-ש means head.")
assert len(roots) >= 1
def test_extracts_dot_separated_root(self):
roots = extract_roots("The root ר.א.ש means head.")
assert len(roots) >= 1
def test_no_roots_returns_empty(self):
roots = extract_roots("No roots mentioned here.")
assert roots == []
class TestZerikah:
def test_returns_vital_and_discarded(self):
korban = make_korban(CLEAN_TORAH_RESPONSE)
vital, discarded = zerikah(CLEAN_TORAH_RESPONSE, korban)
assert isinstance(vital, str)
assert isinstance(discarded, list)
def test_vital_content_contains_torah_refs(self):
"""BUILD_KORBAN verification §2: extracts Torah references accurately."""
korban = make_korban(CLEAN_TORAH_RESPONSE)
vital, _ = zerikah(CLEAN_TORAH_RESPONSE, korban)
assert "Genesis 1:1" in vital or "Bereishit" in vital
def test_vital_content_contains_hebrew(self):
"""BUILD_KORBAN verification §2: identifies Hebrew roots."""
korban = make_korban(CLEAN_TORAH_RESPONSE)
vital, _ = zerikah(CLEAN_TORAH_RESPONSE, korban)
# The fixture has Hebrew text
assert "בְּרֵאשִׁית" in vital or "ר-א-ש" in vital
def test_vital_content_contains_rashi(self):
korban = make_korban(CLEAN_TORAH_RESPONSE)
vital, _ = zerikah(CLEAN_TORAH_RESPONSE, korban)
assert "Rashi" in vital
def test_latin_torah_refs_are_vital(self):
"""BUILD_KORBAN verification §2: separates vital from discardable."""
korban = make_korban(LATIN_TORAH_RESPONSE)
vital, _ = zerikah(LATIN_TORAH_RESPONSE, korban)
assert "Genesis 1:1" in vital
assert "Exodus 3:14" in vital
def test_empty_content_returns_empty_vital(self):
korban = make_korban(".")
vital, discarded = zerikah("", korban)
assert vital == ""
assert discarded == []
def test_all_filler_rejected(self):
"""
If nothing is vital, zerikah returns empty vital content.
BUILD_KORBAN.md §5: the offering without vital organs is rejected.
"""
filler = "There are many perspectives. People disagree. Context matters."
korban = make_korban(filler)
vital, discarded = zerikah(filler, korban)
assert vital == ""
assert len(discarded) > 0
def test_stateless_between_calls(self):
"""Kiyyor principle: second call unaffected by first."""
k1 = make_korban(CLEAN_TORAH_RESPONSE)
k2 = make_korban(LATIN_TORAH_RESPONSE)
vital1a, _ = zerikah(CLEAN_TORAH_RESPONSE, k1)
vital2, _ = zerikah(LATIN_TORAH_RESPONSE, k2)
vital1b, _ = zerikah(CLEAN_TORAH_RESPONSE, k1)
# Same input → same output, regardless of what was processed between
assert vital1a == vital1b
class TestInsightMarkersOnWordBoundaries:
"""Tablet 58: a marker is a word, not a substring. "shorashim" is not Rashi."""
def test_pod_name_is_not_rashi(self):
assert not is_vital("It lives at specs/sugya.md, commit dc938058, pod shorashim-675b48f47-v4x9c.")
def test_rashi_as_a_word_is_vital(self):
assert is_vital("Rashi reads the verse as a question.")
assert is_vital("The Mishnah records the opinion that lost.")
def test_embedded_markers_are_not_words(self):
assert not is_vital("The surname Rambanovich is not a source.")
assert not is_vital("The talmudic_engine container restarted.")