Devarim 17:18 — the king writes his copy from before the priests, not from
memory. scripts/build_mesorah.py takes one open-licence version per work
per language from the Sefaria export (bucket sefaria-export, catalogue of
2026-10-02; Public Domain / CC0 / CC-BY / CC-BY-SA only, checked in every
file; no CC-BY-NC — the Bavli is Wikisource's) and lays it down beside
L1: mesorah/works/<slug>/{he,en}.json, index.json, integrity.sha256,
build_report.json. 128 works (Rashi, Onkelos, Ramban, Ibn Ezra, Sforno
on the Torah; all of Mishnah; 37 Bavli tractates; Bereshit and Shemot
Rabbah, Sifrei, Tanchuma), 256 files, 44.9 MiB, tree hash 7d5b3a6c…
computed as L1's (sorted relative path, then bytes; the two post-hash
files excluded). What is out, and why (licence), is in Terumah §E5.
Read, never fetched: korban_processor/mesorah.py finds citations as
written (Rashi on Devarim 6:5, Berakhot 2a, Mishnah Berakhot 1:1,
Bereshit Rabbah 1:1, Sifrei Devarim 32, Tanchuma Bereshit 1 …), resolves
each against the snapshot (complex works through their unnamed node,
Tanchuma by parashah), lists them as examination.mesorah_references, and
makes every passage found a given source for that examination — so a
claim about Rashi anchors in Rashi or does not. The Vav Pipeline couples
coupled(reference(R), mesorah(Work, [Address])) or not_in_mesorah; the
engine accepts mesorah/2 as a terminal and not_in_mesorah is Form 4.
VavPipeline.Mesorah pins the hash, re-reads the tree at startup and every
ten minutes, and /kodesh/health carries mesorah_hash. Mounted read-only at
/mnt/mesorah in the vav-pipeline and korban-processor images. L3
bedikot.mesorah (migration 20261013000002).
Also: the 1-in-12 Day6 serving failure of 2026-10-04 reproduced with seed
446116 — HaltMonitorTest left the system halted; it now resolves on exit
and the Day6 setup is defensive. Construction §3.11, Terumah §E5, Tamid
§1.1, bishearecha §IV, KOHEN, AGENTS. Doorpost 0638d4eb…. Elixir 604/0
(seeds 835592 and 446116), korban 294/1 skipped, Prolog bedikah 44/44,
L3 10/0.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
87 lines
4.3 KiB
Python
87 lines
4.3 KiB
Python
"""The second scroll, read (bishe'arecha §IV): citations found as written,
|
|
resolved against the snapshot, and given to the anchoring as sources."""
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
REPO = Path(__file__).resolve().parents[2]
|
|
os.environ.setdefault("MESORAH_MOUNT_POINT", str(REPO / "mesorah"))
|
|
|
|
from korban_processor import mesorah # noqa: E402
|
|
from korban_processor.bedikah import examine # noqa: E402
|
|
|
|
needs_scroll = pytest.mark.skipif(not mesorah.available(), reason="mesorah snapshot not built at MESORAH_MOUNT_POINT")
|
|
|
|
|
|
@needs_scroll
|
|
def test_citations_are_found_as_written_in_their_several_forms():
|
|
text = ("Rashi on Devarim 6:5 reads the verse one way; Ramban to Deut. 6:5 another. Onkelos Bereishit 1:1 renders it. "
|
|
"Mishnah Berakhot 1:1 opens with the evening Shema; Berakhot 2a asks why. Bereshit Rabbah 1:1 begins with wisdom. "
|
|
"Sifrei Devarim 32 comments. Bavli Shabbat 31a has Hillel.")
|
|
refs = {r.slug: r for r in mesorah.find_mesorah_references(text)}
|
|
assert refs["rashi_on_devarim"].address == (6, 5)
|
|
assert refs["ramban_on_devarim"].address == (6, 5)
|
|
assert refs["onkelos_bereishit"].address == (1, 1)
|
|
assert refs["mishnah_berakhot"].address == (1, 1)
|
|
assert refs["bavli_berakhot"].address == (3,) # 2a → daf index 3
|
|
assert refs["bavli_shabbat"].address == (61,) # 31a
|
|
assert refs["bereshit_rabbah"].address == (1, 1)
|
|
assert refs["sifrei_devarim"].address == (32,)
|
|
assert refs["rashi_on_devarim"].as_written == "Rashi on Devarim 6:5"
|
|
[t] = mesorah.find_mesorah_references("Midrash Tanchuma, Bereshit 1 opens the same way.")
|
|
assert t.slug == "midrash_tanchuma" and t.address == ("Bereshit", 1) and t.ref_id == "midrash_tanchuma_bereshit_1"
|
|
|
|
|
|
@needs_scroll
|
|
def test_complex_works_resolve_through_their_unnamed_node_and_tanchuma_through_its_parashah():
|
|
assert mesorah.resolve("ramban_on_bereishit", (1, 1))[0]
|
|
assert mesorah.resolve("ibn_ezra_on_bereishit", (1, 1))[0]
|
|
assert mesorah.resolve("sforno_on_bereishit", (1, 1))[0]
|
|
assert mesorah.resolve("midrash_tanchuma", ("Bereshit", 1))[0]
|
|
assert not mesorah.resolve("midrash_tanchuma", ("Nowhere", 1))[0]
|
|
|
|
|
|
@needs_scroll
|
|
def test_a_citation_the_scroll_has_resolves_to_text_and_one_it_lacks_does_not():
|
|
exists, texts = mesorah.resolve("rashi_on_devarim", (6, 5))
|
|
assert exists and "he" in texts and len(texts["he"]) > 20
|
|
assert "<" not in texts["he"] # tags stripped
|
|
exists, texts = mesorah.resolve("rashi_on_devarim", (99, 1))
|
|
assert not exists and texts == {}
|
|
exists, _ = mesorah.resolve("bavli_berakhot", (3,))
|
|
assert exists
|
|
|
|
|
|
@needs_scroll
|
|
def test_the_examination_lists_the_citations_and_anchors_a_claim_in_the_cited_passage():
|
|
he, _ = mesorah.resolve("rashi_on_bereishit", (1, 1))[1].get("he", ""), None
|
|
# Quote six consecutive words of Rashi on Bereishit 1:1 in the output: the claim must anchor in the passage.
|
|
words = he.split()
|
|
quote = " ".join(words[2:9])
|
|
out = f"Rashi on Bereishit 1:1 says: {quote}. This suggests the Torah opens with a question about where it should begin."
|
|
ex = examine(out, "claude", "")
|
|
refs = [r for r in ex.mesorah_references if r["work"] == "rashi_on_bereishit"]
|
|
assert refs and refs[0]["found"] and refs[0]["address"] == [1, 1] and "he" in refs[0]["languages"]
|
|
anchored = [a.source for c in ex.claims for a in c.anchors]
|
|
assert "mesorah:rashi_on_bereishit_1_1" in anchored
|
|
|
|
|
|
@needs_scroll
|
|
def test_a_citation_to_nothing_is_reported_not_invented():
|
|
ex = examine("Rashi on Devarim 99:1 explains this, which suggests the matter is settled.", "gpt", "")
|
|
assert ex.mesorah_references == [{"as_written": "Rashi on Devarim 99:1", "ref": "rashi_on_devarim_99_1", "work": "rashi_on_devarim", "address": [99, 1], "found": False, "languages": []}]
|
|
assert not any(a.source.startswith("mesorah:") for c in ex.claims for a in c.anchors)
|
|
|
|
|
|
def test_without_the_scroll_nothing_is_found_and_nothing_breaks(monkeypatch):
|
|
monkeypatch.setattr(mesorah, "MOUNT", "/nonexistent/mesorah")
|
|
mesorah._index.cache_clear()
|
|
mesorah._work.cache_clear()
|
|
try:
|
|
assert mesorah.find_mesorah_references("Rashi on Devarim 6:5 says so.") == []
|
|
assert mesorah.read("Berakhot 2a") == []
|
|
finally:
|
|
mesorah._index.cache_clear()
|
|
mesorah._work.cache_clear()
|