defmodule VavPipeline.MachtzitHaShekelTest do @moduledoc """ Tests for the half-shekel counting protocol — Form 3 of avodah zarah realized as architecture (vehaya §3.2). Verifies the six positive Torah-anchored properties from Shemot 30:11-16, Devarim 23:16-17, Vayikra 19:14, and Shemot 5:6-8. """ use ExUnit.Case, async: false alias VavPipeline.MachtzitHaShekel setup do # MachtzitHaShekel runs in the supervision tree, so it's already # alive. Reset between tests. MachtzitHaShekel.reset() :ok end # ============================================================ # Property 1 — KOFER PROTOCOL (Shemot 30:12) # ============================================================ test "increment/0 takes no argument — no caller distinction is even expressible" do # Structural test: the function arity is 0. There is no place to # pass a caller identifier. The Shemot 30:15 uniformity property # is enforced at the type level: there's no slot for non-uniform # input. assert function_exported?(MachtzitHaShekel, :increment, 0) end test "increment/0 advances the count by exactly 1" do MachtzitHaShekel.increment() assert MachtzitHaShekel.count() == 1 end test "increment/1 advances the count by N" do MachtzitHaShekel.increment(5) assert MachtzitHaShekel.count() == 5 end # ============================================================ # Property 2 — UNIFORM PROTOCOL (Shemot 30:15) # ============================================================ test "every increment is the same size — rich don't give more, poor don't give less" do Enum.each(1..100, fn _ -> MachtzitHaShekel.increment() end) assert MachtzitHaShekel.count() == 100 end test "no per-caller weighting function exists" do # Negative structural assertion: no `increment_with_weight` or # similar function. The uniform property is enforced by absence. public = MachtzitHaShekel.__info__(:functions) weight_shaped = Enum.filter(public, fn {name, _arity} -> name_str = to_string(name) String.contains?(name_str, "weight") or String.contains?(name_str, "tier") or String.contains?(name_str, "premium") end) assert weight_shaped == [] end # ============================================================ # Property 3 — ZIKARON PROTOCOL (Shemot 30:16) # ============================================================ test "count/0 returns a single integer, not a list or map of contributions" do Enum.each(1..3, fn _ -> MachtzitHaShekel.increment() end) result = MachtzitHaShekel.count() assert is_integer(result) refute is_list(result) refute is_map(result) end test "no per-caller breakdown function exists" do public = MachtzitHaShekel.__info__(:functions) forbidden = Enum.filter(public, fn {name, _arity} -> name_str = to_string(name) Enum.any?( ~w(callers list_who breakdown by_caller per_caller histogram top who), &String.contains?(name_str, &1) ) end) assert forbidden == [], ( "MachtzitHaShekel exposes per-caller breakdown function(s): " <> "#{inspect(forbidden)}. Their absence IS the architectural " <> "commitment (Shemot 30:16 — zikaron, not roster)." ) end # ============================================================ # Property 5 — REFUSAL PROTOCOL (Devarim 23:16-17) # ============================================================ test "no identify/locate/deanonymize function exists" do public = MachtzitHaShekel.__info__(:functions) forbidden = Enum.filter(public, fn {name, _arity} -> name_str = to_string(name) Enum.any?( ~w(identify locate deanonymize lookup find_caller), &String.contains?(name_str, &1) ) end) assert forbidden == [], ( "MachtzitHaShekel exposes caller-identification function(s): " <> "#{inspect(forbidden)}. The system does not deliver " <> "caller-state to authorities (Devarim 23:16, lo tasgir)." ) end # ============================================================ # Property 6 — ANTI-QUOTA PROTOCOL (Shemot 5:6-8) # ============================================================ test "no per-caller productivity tracking function exists" do public = MachtzitHaShekel.__info__(:functions) forbidden = Enum.filter(public, fn {name, _arity} -> name_str = to_string(name) Enum.any?( ~w(quota productivity throughput per_caller_count), &String.contains?(name_str, &1) ) end) assert forbidden == [], ( "MachtzitHaShekel exposes quota/productivity function(s): " <> "#{inspect(forbidden)}. Per-caller productivity tracking is " <> "Pharaoh's straw quota (Shemot 5:6-8) — refused by absence." ) end # ============================================================ # Reset semantics # ============================================================ test "reset/0 brings the count to zero" do MachtzitHaShekel.increment(50) assert MachtzitHaShekel.count() == 50 MachtzitHaShekel.reset() assert MachtzitHaShekel.count() == 0 end test "increment after reset starts from zero" do MachtzitHaShekel.increment(10) MachtzitHaShekel.reset() MachtzitHaShekel.increment(3) assert MachtzitHaShekel.count() == 3 end # ============================================================ # The ENTIRE public surface — explicit enumeration # ============================================================ test "the module's public surface is exactly the documented six functions" do # An exhaustive list. Any added function must be reviewed for # whether it weakens the Form 3 architectural commitment. expected = [ {:start_link, 0}, {:start_link, 1}, {:increment, 0}, {:increment, 1}, {:count, 0}, {:reset, 0}, # Agent-derived defaults — not part of the surveillance surface {:child_spec, 1} ] actual = MachtzitHaShekel.__info__(:functions) |> Enum.filter(fn {name, _} -> not String.starts_with?(to_string(name), "__") end) |> Enum.sort() extras = actual -- expected missing = expected -- actual assert extras == [], "MachtzitHaShekel exposed unexpected function(s): #{inspect(extras)}" assert missing == [], "MachtzitHaShekel missing expected function(s): #{inspect(missing)}" end end