"""Tests for #133 / FU-2 — the chair-decision active-learning seed gate.

Covers the PURE gate function db._chair_seed_label, which decides whether (and
with what is_holding label) a chair decision on a halacha should mint a gold-set
seed. The DB write (seed_goldset_from_chair) and the prior-panel-round filter
need a live Postgres and are exercised via the integration smoke test in the
task's testStrategy; here we lock down the policy offline.

The critical invariant under test: a seed is NEVER minted from a machine
reviewer (echo-chamber guard, #133) — only firm human keep/drop decisions.
"""

from __future__ import annotations

from legal_mcp.services import db


# ── firm decisions map to the coarse is_holding axis ──────────────────────────

def test_approved_is_keep():
    assert db._chair_seed_label("approved", "דפנה") is True


def test_published_is_keep():
    assert db._chair_seed_label("published", "דפנה") is True


def test_rejected_is_drop():
    assert db._chair_seed_label("rejected", "דפנה") is False


# ── non-firm statuses mint no seed (a snooze is not a judgment) ────────────────

def test_deferred_no_seed():
    assert db._chair_seed_label("deferred", "דפנה") is None


def test_pending_review_no_seed():
    assert db._chair_seed_label("pending_review", "דפנה") is None


def test_unknown_status_no_seed():
    assert db._chair_seed_label("", "דפנה") is None


# ── echo-chamber guard: machine reviewers never seed ──────────────────────────

def test_panel_reviewer_blocked():
    """The 3-judge panel must never label its own ground-truth (echo-chamber)."""
    assert db._chair_seed_label("approved", "panel:opus+deepseek+gemini 2/3-keep") is None


def test_corroboration_reviewer_blocked():
    assert db._chair_seed_label("approved", "corroborated (4 judicial citations ≥ 2)") is None


def test_panel_reviewer_blocked_case_insensitive():
    assert db._chair_seed_label("rejected", "PANEL:opus") is None


# ── empty reviewer is still a human gate (UI sends no reviewer string) ─────────

def test_empty_reviewer_is_human_gate():
    """The /precedents UI patches review_status with no reviewer string; that is
    still the chair gate (the panel/corroboration use raw SQL, not update_halacha)."""
    assert db._chair_seed_label("approved", "") is True
