Files
bikoret/vav_pipeline/test/halt_monitor_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

157 lines
5.0 KiB
Elixir

defmodule VavPipeline.HaltMonitorTest do
@moduledoc """
Tests for the HaltMonitor — esh tamid.
Vayikra 6:6 — Esh tamid tukad al hamizbe'ach, lo tikhbeh.
"A perpetual fire shall be kept burning on the altar; it shall not go out."
Operations spec §2.1, Step 5:
The system does not run without the halt monitor.
"""
use ExUnit.Case, async: false
alias VavPipeline.HaltMonitor
setup do
# A halt raised here must not outlive the test: the next file's
# /peah/ask would answer 503 HALT_* (the 1-in-12 Day6 failure of
# 2026-10-04, found by seed 446116 on 2026-10-13).
on_exit(fn -> if HaltMonitor.halted?(), do: HaltMonitor.resolve("halt_monitor_test exit") end)
# Resolve any existing halt from a previous test
if HaltMonitor.halted? do
HaltMonitor.resolve("test cleanup")
end
:ok
end
# ============================================================
# Alive check — esh tamid verification
# ============================================================
describe "esh tamid" do
test "monitor is alive" do
assert HaltMonitor.alive?()
end
test "status is :running when no halt" do
assert HaltMonitor.status() == :running
end
test "halted? returns false when running" do
refute HaltMonitor.halted?()
end
end
# ============================================================
# Halt detection — three cardinal sins
# ============================================================
describe "halt!" do
test "avodah_zarah halts the system" do
assert :halted = HaltMonitor.halt!(:avodah_zarah, "external model treated as Torah")
assert HaltMonitor.halted?()
{:halted, event} = HaltMonitor.status()
assert event.condition == :avodah_zarah
assert event.reason == "external model treated as Torah"
assert event.resolved == false
end
test "shfichut_damim halts the system" do
assert :halted = HaltMonitor.halt!(:shfichut_damim, "user data deletion attempted")
assert HaltMonitor.halted?()
{:halted, event} = HaltMonitor.status()
assert event.condition == :shfichut_damim
end
test "gilui_arayot halts the system" do
assert :halted = HaltMonitor.halt!(:gilui_arayot, "L1/L3 boundary collapsed")
assert HaltMonitor.halted?()
{:halted, event} = HaltMonitor.status()
assert event.condition == :gilui_arayot
end
test "halt records detected_at timestamp" do
HaltMonitor.halt!(:avodah_zarah, "timestamp test")
{:halted, event} = HaltMonitor.status()
assert event.detected_at != nil
assert %DateTime{} = event.detected_at
end
test "halt records component" do
HaltMonitor.halt!(:avodah_zarah, "component test", "korban_processor")
{:halted, event} = HaltMonitor.status()
assert event.component == "korban_processor"
end
end
# ============================================================
# Resolution
# ============================================================
describe "resolve" do
test "resolving a halt resumes the system" do
HaltMonitor.halt!(:avodah_zarah, "test halt for resolution")
assert HaltMonitor.halted?()
{:ok, :resumed} = HaltMonitor.resolve("Investigation complete — false positive")
refute HaltMonitor.halted?()
assert HaltMonitor.status() == :running
end
test "resolving when not halted returns error" do
assert {:error, :not_halted} = HaltMonitor.resolve("nothing to resolve")
end
end
# ============================================================
# Audit log — permanent record
# ============================================================
describe "audit log" do
test "halt events are recorded in audit log" do
initial_count = length(HaltMonitor.audit_log())
HaltMonitor.halt!(:avodah_zarah, "audit test 1")
HaltMonitor.resolve("resolved 1")
HaltMonitor.halt!(:shfichut_damim, "audit test 2")
HaltMonitor.resolve("resolved 2")
log = HaltMonitor.audit_log()
assert length(log) >= initial_count + 2
end
test "audit log preserves halt details" do
HaltMonitor.halt!(:gilui_arayot, "audit detail test", "specification_module")
HaltMonitor.resolve("test cleanup")
log = HaltMonitor.audit_log()
event = Enum.find(log, &(&1.reason == "audit detail test"))
assert event != nil
assert event.condition == :gilui_arayot
assert event.component == "specification_module"
end
end
# ============================================================
# Chatzotzrot integration — war signal on halt
# ============================================================
describe "chatzotzrot war signal" do
test "halt sounds the war signal" do
VavPipeline.Chatzotzrot.subscribe(:kohanim)
HaltMonitor.halt!(:avodah_zarah, "chatzotzrot test")
# War signal should be received by kohanim subscribers
assert_receive {:chatzotzrot, %{signal_type: :war, pattern: :teruah_teruah}}
VavPipeline.Chatzotzrot.unsubscribe(:kohanim)
end
end
end