66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
"""Pure contract tests for intelligent-evaluation read projections."""
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
from agenteval.intelligent_eval.models import (
|
|
IntelligentEval,
|
|
IntelligentEvalSession,
|
|
IntelligentEvalSessionStatus,
|
|
IntelligentEvalStatus,
|
|
)
|
|
from agenteval.intelligent_eval.read_model import project_detail, project_list_item
|
|
|
|
|
|
def _evaluation() -> IntelligentEval:
|
|
now = datetime(2026, 1, 1, tzinfo=timezone.utc)
|
|
return IntelligentEval(
|
|
id="eval-1",
|
|
name="客服评估",
|
|
target_id="target-1",
|
|
status=IntelligentEvalStatus.EXECUTING,
|
|
goal="验证退货流程",
|
|
seeds={"personas": ["老客户"]},
|
|
intent="流程覆盖",
|
|
role_description="模拟用户",
|
|
plan={"dimensions": ["退货"]},
|
|
time_window_hours=24,
|
|
created_at=now,
|
|
updated_at=now,
|
|
)
|
|
|
|
|
|
def _session(session_id: str, status: IntelligentEvalSessionStatus) -> IntelligentEvalSession:
|
|
return IntelligentEvalSession(
|
|
id=session_id,
|
|
eval_id="eval-1",
|
|
target_id="target-1",
|
|
persona={"name": session_id},
|
|
goal="完成退货",
|
|
dimension="退货",
|
|
status=status,
|
|
turn_count=2,
|
|
)
|
|
|
|
|
|
def test_list_projection_contains_stable_fields_and_counts() -> None:
|
|
projection = project_list_item(
|
|
_evaluation(),
|
|
[_session("s-1", IntelligentEvalSessionStatus.RUNNING), _session("s-2", IntelligentEvalSessionStatus.COMPLETED)],
|
|
)
|
|
|
|
assert projection.id == "eval-1"
|
|
assert projection.session_count == 2
|
|
assert projection.completed_sessions == 1
|
|
assert projection.plan == {"dimensions": ["退货"]}
|
|
|
|
|
|
def test_detail_projection_contains_session_metadata_without_messages() -> None:
|
|
projection = project_detail(_evaluation(), [_session("s-1", IntelligentEvalSessionStatus.COMPLETED)])
|
|
payload = projection.model_dump(mode="json")
|
|
|
|
assert payload["sessions"][0]["id"] == "s-1"
|
|
assert payload["sessions"][0]["turn_count"] == 2
|
|
assert "messages" not in payload
|
|
assert "content" not in payload["sessions"][0]
|
|
|