- semichah: provenance tagging (6 sources, rejects empty/anonymous) - shechitah: strip preamble, self-reference, hedging, markdown, sycophancy - zerikah: extract Torah refs, Hebrew text, root analysis, insight markers - haktarah: transform prose to Prolog propositions (verse/3, root/2, claim/2, connection/3) - router: stateless routing — removed module-level _routing_log (kiyyor principle) - model_interface: outbound Claude API via httpx (Construction §3.4, HTTPS only) - hebrew_parser: nikkud/teamim stripping, consonant extraction, gematria, root identification All 5 BUILD_KORBAN.md verification tests pass. AGENTS.md: added structure_not_content.md to spec table, added Principle 6. build_log.md: recorded session, broken tablets #18-20, design decisions. Ka'asher tzivah Hashem et Moshe. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
193 lines
7.4 KiB
Python
193 lines
7.4 KiB
Python
"""
|
|
Tests for shechitah — terminate raw form.
|
|
|
|
BUILD_KORBAN.md Verification §1:
|
|
Feed it a Claude API response with heavy preamble, markdown, hedging,
|
|
and self-reference. Verify the output contains none of these and
|
|
preserves all Torah references and Hebrew analysis.
|
|
|
|
Architecture §3.5: The shechitah must be swift and complete.
|
|
A nick in the blade renders the shechitah invalid.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from korban_processor.korban import Korban, OfferingType, Provenance
|
|
from korban_processor.shechitah import (
|
|
shechitah,
|
|
strip_preamble,
|
|
strip_self_reference,
|
|
strip_hedging,
|
|
strip_markdown,
|
|
strip_closing,
|
|
clean_whitespace,
|
|
)
|
|
from test.fixtures import CLAUDE_HEAVY_PREAMBLE_RESPONSE, CLAUDE_EMPTY_OFFERING
|
|
|
|
|
|
def make_korban(content: str, prov: Provenance = Provenance.CLAUDE) -> Korban:
|
|
return Korban(
|
|
raw_content=content,
|
|
provenance=prov,
|
|
offering_type=OfferingType.OLAH,
|
|
source_query="test query",
|
|
)
|
|
|
|
|
|
class TestShechitahStripsAssistantVoice:
|
|
"""BUILD_KORBAN verification §1: strips preamble, markdown, hedging, self-reference."""
|
|
|
|
def test_strips_great_question_preamble(self):
|
|
content = "Great question! I'd be happy to help you. The root ר-א-ש means beginning."
|
|
result = shechitah(make_korban(content))
|
|
assert "Great question" not in result
|
|
assert "I'd be happy" not in result
|
|
|
|
def test_strips_sure_preamble(self):
|
|
content = "Sure! I can help with that. Genesis 1:1 begins with bereishit."
|
|
result = shechitah(make_korban(content))
|
|
assert "Sure!" not in result
|
|
assert "Genesis 1:1" in result
|
|
|
|
def test_strips_certainly_preamble(self):
|
|
content = "Certainly! Here is a breakdown: The word בְּרֵאשִׁית derives from ר-א-ש."
|
|
result = shechitah(make_korban(content))
|
|
assert "Certainly" not in result
|
|
|
|
def test_strips_self_reference_as_ai(self):
|
|
# Self-reference and Torah content are in separate sentences.
|
|
# "As an AI language model, my knowledge has limits." is stripped.
|
|
# "Genesis 1:1 begins the Torah." is preserved in the following sentence.
|
|
content = "As an AI language model, my knowledge has limits. Genesis 1:1 begins the Torah."
|
|
result = shechitah(make_korban(content))
|
|
assert "As an AI" not in result
|
|
assert "language model" not in result
|
|
assert "Genesis 1:1" in result
|
|
|
|
def test_strips_hedging_worth_noting(self):
|
|
content = "The root ר-א-ש means head. It's worth noting that interpretations vary."
|
|
result = shechitah(make_korban(content))
|
|
assert "worth noting" not in result
|
|
assert "ר-א-ש" in result
|
|
|
|
def test_strips_hedging_important_to_note(self):
|
|
content = "Bereishit 1:1 opens Torah. It is important to note that Rashi comments."
|
|
result = shechitah(make_korban(content))
|
|
assert "important to note" not in result
|
|
assert "Bereishit 1:1" in result
|
|
|
|
def test_strips_closing_let_me_know(self):
|
|
content = "The root ר-א-ש indicates beginning.\n\nLet me know if you have more questions!"
|
|
result = shechitah(make_korban(content))
|
|
assert "Let me know" not in result
|
|
assert "ר-א-ש" in result
|
|
|
|
def test_strips_closing_feel_free(self):
|
|
content = "Genesis 1:1 establishes divine creation.\n\nFeel free to ask more!"
|
|
result = shechitah(make_korban(content))
|
|
assert "Feel free" not in result
|
|
assert "Genesis 1:1" in result
|
|
|
|
|
|
class TestShechitahStripsMarkdown:
|
|
def test_strips_bold_markers(self):
|
|
result = strip_markdown("**The root** ר-א-ש means beginning.")
|
|
assert "**" not in result
|
|
assert "The root" in result
|
|
assert "ר-א-ש" in result
|
|
|
|
def test_strips_italic_markers(self):
|
|
result = strip_markdown("The word *bereishit* comes from ר-א-ש.")
|
|
assert "*" not in result
|
|
assert "bereishit" in result
|
|
|
|
def test_strips_header_markers(self):
|
|
result = strip_markdown("## Analysis of Bereishit 1:1\n\nThe root is ר-א-ש.")
|
|
assert "##" not in result
|
|
assert "Analysis of Bereishit 1:1" in result
|
|
|
|
def test_strips_bullet_markers(self):
|
|
result = strip_markdown("- The root ר-א-ש means head\n- Genesis 1:1 opens Torah")
|
|
assert result.lstrip().startswith("The root") or "The root" in result
|
|
assert "ר-א-ש" in result
|
|
|
|
def test_strips_numbered_list_markers(self):
|
|
result = strip_markdown("1. Genesis 1:1\n2. Exodus 3:14")
|
|
assert "1." not in result
|
|
assert "Genesis 1:1" in result
|
|
assert "Exodus 3:14" in result
|
|
|
|
def test_strips_code_blocks(self):
|
|
result = strip_markdown("The root is ר-א-ש.\n```\ncode block\n```\nMore text.")
|
|
assert "```" not in result
|
|
assert "code block" not in result
|
|
assert "ר-א-ש" in result
|
|
|
|
def test_strips_inline_code_keeps_text(self):
|
|
result = strip_markdown("The function `bereishit()` relates to ר-א-ש.")
|
|
assert "`" not in result
|
|
assert "bereishit()" in result
|
|
|
|
|
|
class TestShechitahPreservesTorah:
|
|
"""BUILD_KORBAN verification §1: preserves Torah references and Hebrew analysis."""
|
|
|
|
def test_preserves_torah_reference_bereishit(self):
|
|
korban = make_korban(CLAUDE_HEAVY_PREAMBLE_RESPONSE)
|
|
result = shechitah(korban)
|
|
assert "Genesis 1:1" in result or "Bereishit 1:1" in result
|
|
|
|
def test_preserves_hebrew_text(self):
|
|
korban = make_korban(CLAUDE_HEAVY_PREAMBLE_RESPONSE)
|
|
result = shechitah(korban)
|
|
assert "בְּרֵאשִׁית" in result
|
|
|
|
def test_preserves_root_notation(self):
|
|
korban = make_korban(CLAUDE_HEAVY_PREAMBLE_RESPONSE)
|
|
result = shechitah(korban)
|
|
assert "ר-א-ש" in result
|
|
|
|
def test_preserves_rashi_reference(self):
|
|
korban = make_korban(CLAUDE_HEAVY_PREAMBLE_RESPONSE)
|
|
result = shechitah(korban)
|
|
assert "Rashi" in result
|
|
|
|
def test_full_shechitah_strips_all_voice(self):
|
|
"""BUILD_KORBAN verification §1: comprehensive strip test."""
|
|
korban = make_korban(CLAUDE_HEAVY_PREAMBLE_RESPONSE)
|
|
result = shechitah(korban)
|
|
|
|
# Must not contain assistant voice
|
|
assert "Great question" not in result
|
|
assert "I'd be happy" not in result
|
|
assert "As an AI" not in result
|
|
assert "language model" not in result
|
|
assert "worth noting" not in result
|
|
assert "important to keep in mind" not in result
|
|
assert "Let me know" not in result
|
|
assert "I hope this helps" not in result
|
|
|
|
# Must preserve vital content
|
|
assert "בְּרֵאשִׁית" in result
|
|
assert "ר-א-ש" in result
|
|
assert "Rashi" in result
|
|
|
|
|
|
class TestShechitahStateless:
|
|
"""Kiyyor principle: each call is independent, no state between calls."""
|
|
|
|
def test_two_calls_identical_input_identical_output(self):
|
|
korban = make_korban(CLAUDE_HEAVY_PREAMBLE_RESPONSE)
|
|
result1 = shechitah(korban)
|
|
result2 = shechitah(korban)
|
|
assert result1 == result2
|
|
|
|
def test_second_call_unaffected_by_first(self):
|
|
k1 = make_korban("Great question! The root ר-א-ש means head. Genesis 1:1.")
|
|
k2 = make_korban("Sure! I can explain. Exodus 3:14 reveals Ehyeh asher Ehyeh.")
|
|
result1 = shechitah(k1)
|
|
result2 = shechitah(k2)
|
|
# Each result should only contain content from its own korban
|
|
assert "Exodus" not in result1
|
|
assert "Genesis" not in result2
|