103 lines
3.3 KiB
Python
103 lines
3.3 KiB
Python
"""P2 deployment-config enum / range validation for MafRoundtableConfig.
|
|
|
|
Config and API schemas share ``MafMode`` / ``MafWritePolicy`` from
|
|
``deerflow.config.maf_roundtable_config`` —invalid deployment values must fail
|
|
at load time, not silently become runtime bugs.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from deerflow.config.maf_roundtable_config import MafBusinessRoute, MafRoundtableConfig
|
|
|
|
|
|
def test_valid_config_loads():
|
|
cfg = MafRoundtableConfig(
|
|
enabled=True,
|
|
default_mode="group_chat",
|
|
default_write_policy="auto",
|
|
default_max_rounds=16,
|
|
admin_diagnostic_access=False,
|
|
)
|
|
assert cfg.default_mode == "group_chat"
|
|
assert cfg.default_write_policy == "auto"
|
|
assert cfg.default_max_rounds == 16
|
|
|
|
|
|
def test_default_config_loads():
|
|
cfg = MafRoundtableConfig()
|
|
assert cfg.enabled is False
|
|
assert cfg.default_mode == "structured"
|
|
assert cfg.default_write_policy == "confirm_high_risk"
|
|
assert cfg.default_max_rounds == 8
|
|
|
|
|
|
def test_invalid_default_mode_rejected():
|
|
with pytest.raises(ValidationError):
|
|
MafRoundtableConfig(default_mode="wrong")
|
|
|
|
|
|
def test_invalid_default_write_policy_rejected():
|
|
with pytest.raises(ValidationError):
|
|
MafRoundtableConfig(default_write_policy="wrong")
|
|
|
|
|
|
def test_default_max_rounds_zero_rejected():
|
|
with pytest.raises(ValidationError):
|
|
MafRoundtableConfig(default_max_rounds=0)
|
|
|
|
|
|
def test_default_max_rounds_above_cap_rejected():
|
|
with pytest.raises(ValidationError):
|
|
MafRoundtableConfig(default_max_rounds=65)
|
|
|
|
|
|
def test_allow_mock_events_field_removed():
|
|
"""allow_mock_events must not be a config field anymore."""
|
|
assert "allow_mock_events" not in MafRoundtableConfig.model_fields
|
|
|
|
|
|
def test_route_ids_are_trimmed_and_manager_cannot_be_a_seat():
|
|
cfg = MafRoundtableConfig(
|
|
default_manager_agent_id=" manager ",
|
|
default_seat_agent_ids=[" seat-a "],
|
|
business_routes={
|
|
" 6BF ": MafBusinessRoute(
|
|
manager_agent_id="route-manager",
|
|
seat_agent_ids=["route-seat"],
|
|
)
|
|
},
|
|
)
|
|
assert cfg.default_manager_agent_id == "manager"
|
|
assert cfg.default_seat_agent_ids == ["seat-a"]
|
|
assert "6BF" in cfg.business_routes
|
|
|
|
with pytest.raises(ValidationError, match="must not appear"):
|
|
MafRoundtableConfig(
|
|
default_manager_agent_id="manager",
|
|
default_seat_agent_ids=["manager"],
|
|
)
|
|
with pytest.raises(ValidationError, match="default_manager_agent_id"):
|
|
MafRoundtableConfig(default_manager_agent_id=" ")
|
|
|
|
|
|
def test_duplicate_seats_and_invalid_business_code_are_rejected():
|
|
with pytest.raises(ValidationError, match="duplicates"):
|
|
MafRoundtableConfig(default_seat_agent_ids=["seat-a", "seat-a"])
|
|
with pytest.raises(ValidationError, match="business route code"):
|
|
MafRoundtableConfig(
|
|
business_routes={
|
|
"not valid": MafBusinessRoute(manager_agent_id="manager")
|
|
}
|
|
)
|
|
|
|
|
|
def test_route_seat_count_obeys_global_limit():
|
|
with pytest.raises(ValidationError, match="max_seats_per_run"):
|
|
MafRoundtableConfig(
|
|
max_seats_per_run=1,
|
|
default_seat_agent_ids=["seat-a", "seat-b"],
|
|
)
|