"""Unit tests for derive_implicit_rules — 期望→隐式规则的纯翻译."""

from agenteval.evaluation.implicit_rules import derive_implicit_rules
from agenteval.models import Expectation


def test_empty_expectation_yields_no_rules():
    assert derive_implicit_rules(Expectation()) == []


def test_intent_and_coherence_alone_yield_no_rules():
    # intent / coherence_min_score 不派生隐式规则（无对应规则类型）
    exp = Expectation(intent="问诊分流", coherence_min_score=0.8)
    assert derive_implicit_rules(exp) == []


def test_response_time_yields_response_time_rule():
    rules = derive_implicit_rules(Expectation(response_time_max_ms=2000))
    assert len(rules) == 1
    assert rules[0].type == "response_time"
    assert rules[0].params == {"max_ms": 2000}


def test_keywords_include_yields_keyword_rule():
    rules = derive_implicit_rules(Expectation(keywords_include=["挂号", "门诊"]))
    assert len(rules) == 1
    assert rules[0].type == "keyword_match"
    assert rules[0].params == {"keywords": ["挂号", "门诊"], "exclude_keywords": []}


def test_keywords_exclude_alone_yields_keyword_rule():
    rules = derive_implicit_rules(Expectation(keywords_exclude=["投诉"]))
    assert len(rules) == 1
    assert rules[0].type == "keyword_match"
    assert rules[0].params == {"keywords": [], "exclude_keywords": ["投诉"]}


def test_both_expectations_yield_two_rules_in_order():
    exp = Expectation(
        response_time_max_ms=1500,
        keywords_include=["预约"],
        keywords_exclude=["取消"],
    )
    rules = derive_implicit_rules(exp)
    assert [r.type for r in rules] == ["response_time", "keyword_match"]
