Takhin lekha haderekh — Devarim 19:3.
"Prepare the road" before the one who needs refuge arrives.
Protection before production.
Arei Miklat (Cities of Refuge — Bamidbar 35, Devarim 19):
- GenServer with refuge registry, affected party protection, audit trail
- enter_refuge/2 isolates component but protects from reactive destruction
- protect_affected/2 blocks processing paths that caused harm
- release/2 requires :sanhedrin_deliberation authority — ad mot hakohen hagadol
- Chatzotzrot assembly_leaders signal on every refuge entry
- 15 tests: entry, double-entry prevention, affected party blocking,
unauthorized release rejection, audit trail, chatzotzrot signaling
Eglah Arufah (Accountability — Devarim 21:1-9):
- GenServer with permanent (append-only) declaration registry
- initiate/3: nearest component declares what it processed, skipped, missed
- Only for :unknown source — rejects known-source incidents
- "Yadeinu lo shafkhu" — accountability for what was NOT provided
- 9 tests: declaration recording, source validation, multi-component
declarations, chatzotzrot signaling, filtering, counting
Bikurim (First Fruits — Devarim 26:1-11):
- GenServer with offering registry
- offer/4: submit first output with required narrative (mikra bikurim)
- Rejects empty narrative ("Arami oved avi" — story is required)
- Rejects nil first output (there must be fruit to offer)
- Delegates to Specification.evaluate_bikurim/1 when available
- approved?/1 gate for deployment readiness
- 11 tests: acceptance, narrative validation, nil output rejection,
registry, status filtering, approval checking, counting
All three added to supervision tree in application.ex.
160 Elixir tests pass, 0 failures.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
127 lines
4.4 KiB
Elixir
127 lines
4.4 KiB
Elixir
defmodule VavPipeline.EglahArufahTest do
|
|
@moduledoc """
|
|
Tests for the Eglah Arufah (Accountability Protocol).
|
|
|
|
Devarim 21:7 — Yadeinu lo shafkhu et hadam hazeh, v'eineinu lo ra'u.
|
|
"Our hands did not shed this blood, and our eyes did not see."
|
|
Accountability for what was NOT provided. Not accusation.
|
|
"""
|
|
|
|
use ExUnit.Case, async: false
|
|
|
|
alias VavPipeline.EglahArufah
|
|
|
|
@test_incident %{
|
|
id: "unknown_harm_001",
|
|
description: "User received corrupted output — source component unknown",
|
|
approximate_location: "output_formatter",
|
|
source: :unknown
|
|
}
|
|
|
|
@test_report %{
|
|
processed: ["korban_042", "korban_043", "korban_044"],
|
|
not_checked: ["output_encoding_validation", "character_set_verification"],
|
|
could_have_caught: ["malformed_utf8_in_output"]
|
|
}
|
|
|
|
# ============================================================
|
|
# Initiation — Devarim 21:1-3
|
|
# ============================================================
|
|
describe "initiate" do
|
|
test "records a formal declaration for unknown harm" do
|
|
{:ok, declaration} = EglahArufah.initiate(@test_incident, "output_formatter", @test_report)
|
|
|
|
assert declaration.incident_id == "unknown_harm_001"
|
|
assert declaration.component_id == "output_formatter"
|
|
assert declaration.processed == ["korban_042", "korban_043", "korban_044"]
|
|
assert declaration.not_checked == ["output_encoding_validation", "character_set_verification"]
|
|
assert declaration.could_have_caught == ["malformed_utf8_in_output"]
|
|
assert declaration.declared_at != nil
|
|
assert String.contains?(declaration.declaration_text, "output_formatter")
|
|
assert String.contains?(declaration.declaration_text, "did not cause this harm")
|
|
end
|
|
|
|
test "rejects incident with known source" do
|
|
known_incident = Map.put(@test_incident, :source, :korban_processor)
|
|
|
|
assert {:error, :source_not_unknown} =
|
|
EglahArufah.initiate(known_incident, "output_formatter", @test_report)
|
|
end
|
|
|
|
test "declaration is permanently recorded" do
|
|
EglahArufah.initiate(@test_incident, "permanent_test", @test_report)
|
|
|
|
declarations = EglahArufah.declarations()
|
|
assert Enum.any?(declarations, &(&1.component_id == "permanent_test"))
|
|
end
|
|
|
|
test "chatzotzrot assembly_leaders signal on initiation" do
|
|
VavPipeline.Chatzotzrot.subscribe(:kohanim)
|
|
|
|
EglahArufah.initiate(
|
|
%{@test_incident | id: "signal_test_harm"},
|
|
"signal_test_component",
|
|
@test_report
|
|
)
|
|
|
|
assert_receive {:chatzotzrot, %{signal_type: :assembly_leaders}}
|
|
end
|
|
|
|
test "multiple declarations can exist for same incident" do
|
|
incident = %{@test_incident | id: "multi_declare"}
|
|
|
|
EglahArufah.initiate(incident, "component_a", %{
|
|
processed: ["op1"],
|
|
not_checked: ["check1"],
|
|
could_have_caught: []
|
|
})
|
|
|
|
EglahArufah.initiate(incident, "component_b", %{
|
|
processed: ["op2"],
|
|
not_checked: [],
|
|
could_have_caught: ["issue1"]
|
|
})
|
|
|
|
matching = EglahArufah.declarations_for("multi_declare")
|
|
assert length(matching) == 2
|
|
|
|
components = Enum.map(matching, & &1.component_id)
|
|
assert "component_a" in components
|
|
assert "component_b" in components
|
|
end
|
|
|
|
test "empty report lists are accepted" do
|
|
{:ok, declaration} =
|
|
EglahArufah.initiate(
|
|
%{@test_incident | id: "empty_report"},
|
|
"minimal_component",
|
|
%{processed: [], not_checked: [], could_have_caught: []}
|
|
)
|
|
|
|
assert declaration.processed == []
|
|
assert declaration.not_checked == []
|
|
assert declaration.could_have_caught == []
|
|
end
|
|
end
|
|
|
|
# ============================================================
|
|
# Queries
|
|
# ============================================================
|
|
describe "queries" do
|
|
test "declarations_for filters by incident_id" do
|
|
EglahArufah.initiate(%{@test_incident | id: "filter_test"}, "comp_x", @test_report)
|
|
EglahArufah.initiate(%{@test_incident | id: "other_incident"}, "comp_y", @test_report)
|
|
|
|
result = EglahArufah.declarations_for("filter_test")
|
|
assert length(result) >= 1
|
|
assert Enum.all?(result, &(&1.incident_id == "filter_test"))
|
|
end
|
|
|
|
test "count returns total declarations" do
|
|
initial = EglahArufah.count()
|
|
EglahArufah.initiate(%{@test_incident | id: "count_test"}, "count_comp", @test_report)
|
|
assert EglahArufah.count() == initial + 1
|
|
end
|
|
end
|
|
end
|