"""Tests for Settings auto-derivation of openclaw_ws_origin."""

from agenteval.config.settings import Settings


def test_explicit_openclaw_ws_origin_is_preserved():
    s = Settings(
        openclaw_ws_origin="http://explicit.example",
        allowed_origins=["http://other.example"],
    )
    assert s.openclaw_ws_origin == "http://explicit.example"


def test_derived_from_single_non_wildcard_origin():
    s = Settings(allowed_origins=["http://192.168.8.145:8001"])
    assert s.openclaw_ws_origin == "http://192.168.8.145:8001"


def test_derived_picks_first_non_localhost_origin():
    s = Settings(allowed_origins=[
        "http://localhost:5173",
        "http://127.0.0.1:8001",
        "http://192.168.8.145:8001",
        "http://agenteval:8000",
    ])
    assert s.openclaw_ws_origin == "http://192.168.8.145:8001"


def test_derived_skips_wildcard():
    s = Settings(allowed_origins=["*", "http://example.com"])
    assert s.openclaw_ws_origin == "http://example.com"


def test_derived_falls_back_when_only_wildcard():
    s = Settings(allowed_origins=["*"])
    assert s.openclaw_ws_origin == "http://localhost:8000"


def test_derived_falls_back_when_empty():
    s = Settings(allowed_origins=[])
    assert s.openclaw_ws_origin == "http://localhost:8000"


def test_poll_reply_timeout_default_and_env(monkeypatch):
    assert Settings().poll_reply_timeout == 30.0
    monkeypatch.setenv("AGENTEVAL_POLL_REPLY_TIMEOUT", "60")
    assert Settings().poll_reply_timeout == 60.0
