Files
bikoret/vav_pipeline/test/mesorah_test.exs
T
Scott KarpandClaude Fable 5.1 5e325d36cc the second scroll: the mesorah snapshot, pinned and read (bishe'arecha step 6)
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>
2026-10-13 19:13:36 +00:00

73 lines
2.9 KiB
Elixir

defmodule VavPipeline.MesorahTest do
@moduledoc """
The second scroll (bishe'arecha §IV): pinned, hashed, read-only; its
citations coupled like verses.
"""
use ExUnit.Case, async: false
import Plug.Test
alias VavPipeline.{Bedikah, Mesorah}
alias VavPipeline.BigdeiKodesh.Router
@opts Router.init([])
test "the tree on disk hashes to the builder's integrity.sha256 and to the pin" do
root = Mesorah.root()
assert File.dir?(root), "mesorah snapshot not built at #{root}"
{:ok, hash} = Mesorah.compute_tree_hash(root)
assert hash == File.read!(Path.join(root, "integrity.sha256")) |> String.trim()
assert hash == Mesorah.expected_hash()
assert :ok = Mesorah.verify_integrity()
end
test "the index names every work with its version, licence and hash; every licence is open" do
index = Mesorah.index()
assert map_size(index["works"]) >= 100
for {_slug, w} <- index["works"], {_lang, v} <- w["versions"] do
assert v["license"] in ["Public Domain", "PD", "CC0", "CC-BY", "CC-BY-SA"], w["title"]
assert String.length(v["sha256"]) == 64
end
assert index["works"]["rashi_on_devarim"]["schema"]["sectionNames"] == ["Chapter", "Verse", "Comment"]
end
test "a changed byte is a different scroll" do
temp = Path.join(System.tmp_dir!(), "mesorah_test_#{System.unique_integer([:positive])}")
File.mkdir_p!(Path.join(temp, "works/x"))
File.write!(Path.join(temp, "works/x/he.json"), "{\"text\":[\"a\"]}")
File.write!(Path.join(temp, "index.json"), "{}")
{:ok, h1} = Mesorah.compute_tree_hash(temp)
File.write!(Path.join(temp, "works/x/he.json"), "{\"text\":[\"b\"]}")
{:ok, h2} = Mesorah.compute_tree_hash(temp)
refute h1 == h2
File.rm_rf!(temp)
assert {:error, _} = Mesorah.compute_tree_hash(temp)
end
test "a citation the scroll has couples to the passage; one it lacks couples to nothing" do
examination = %{
"claims" => [],
"references" => [],
"roots" => [],
"hebrew" => [],
"mesorah_references" => [
%{"as_written" => "Rashi on Devarim 6:5", "ref" => "rashi_on_devarim_6_5", "work" => "rashi_on_devarim", "address" => [6, 5], "found" => true, "languages" => ["en", "he"]},
%{"as_written" => "Rashi on Devarim 99:1", "ref" => "rashi_on_devarim_99_1", "work" => "rashi_on_devarim", "address" => [99, 1], "found" => false, "languages" => []}
]
}
trace = Bedikah.coupling_trace(examination)
assert "coupled(reference(rashi_on_devarim_6_5), mesorah(rashi_on_devarim, [6,5]))" in trace
assert "coupled(reference(rashi_on_devarim_99_1), not_in_mesorah)" in trace
end
test "readiness carries the scroll's check" do
conn = conn(:get, "/kodesh/health") |> Router.call(@opts)
body = Jason.decode!(conn.resp_body)
assert body["checks"]["mesorah_hash"] in ["pass", "fail"]
assert body["checks"]["mesorah_hash"] == "pass"
end
end