from backend.review.gate import build_review_queue


def test_gate_marks_blocking_and_audit_items():
    memory = {"clusters": [{"key": "room:101", "location": "Room 101", "assertions": [{"id": "a1"}, {"id": "a2"}]}], "findings": []}
    prioritized = [
        {"issue_id": "AGENT-0001", "severity": "high", "confidence": "high", "category": "note_or_spec_contradiction", "source_stage": "conflict"},
        {"issue_id": "AGENT-0002", "severity": "low", "confidence": "high", "category": "note_or_spec_contradiction", "source_stage": "conflict"},
    ]
    queue = build_review_queue(memory, prioritized, [])
    by_id = {item["review_item_id"]: item for item in queue}
    assert by_id["finding:AGENT-0001"]["blocking"] is True
    assert by_id["finding:AGENT-0002"]["blocking"] is False
    assert any(item["kind"] == "clean_cluster" for item in queue)


def test_gate_limit_caps_clean_cluster_items():
    memory = {
        "clusters": [
            {"key": f"room:{index}", "assertions": [{"id": "a"}, {"id": "b"}]}
            for index in range(3)
        ],
        "findings": [],
    }
    queue = build_review_queue(memory, [], [], limit=1)
    clean_items = [item for item in queue if item["kind"] == "clean_cluster"]
    assert len(clean_items) == 1
    assert clean_items[0]["review_item_id"] == "clean_cluster:room:0"
