from types import SimpleNamespace

from vlm_detect.local_adapter_utils import extract_perception_text, is_trigger_match


def test_extracts_first_non_empty_target_type():
    msg = SimpleNamespace(
        targets=[
            SimpleNamespace(type=""),
            SimpleNamespace(type="病人坐在床边"),
        ]
    )

    assert extract_perception_text(msg) == "病人坐在床边"


def test_returns_empty_string_when_no_target_text():
    msg = SimpleNamespace(targets=[SimpleNamespace(type="")])

    assert extract_perception_text(msg) == ""


def test_trigger_match_casts_values_to_int():
    assert is_trigger_match("9", 9)
    assert not is_trigger_match(8, 9)
