AgentEvalTool/backend/agenteval/intelligent_eval/lifecycle/report_submission.py
sinohqb 3705945a7d test: 完整测试覆盖补全(+163 用例)
架构重构(候选 1-6):
- storage/repository.py 按域拆分为包(target/scenario/run/campaign/result)
- storage/db.py 按域拆分为包(eval/campaign/file/model_config/intelligent_eval)
- intelligent_eval/lifecycle.py 按状态机阶段拆分为包
- services/runs.py 编排逻辑下沉
- Campaigns.tsx 拆分为 campaigns/ 子组件

测试补全(候选 7):
前端(+125 用例,107→232):
- utils/ 纯函数:date/campaignTime/ruleLabels/fileTree/fileFormat/colors
- stores/tabStore 状态管理
- 核心组件:FormDrawer/PageWrapper/ChatBubble/GeneratedMessages/SectionHeader/StatCard/TurnList
- 业务组件:CaseBlock/CaseDetail/RuleOverview/WindowTimeline/RunList/TabBar/CampaignRunTimeline
- 文件管理:FileCategoryTree/FileTable
- hooks:sessionReducer/useFiles/useRunSession

后端(+38 用例,916→954):
- targets API CRUD + 404 路径
- WebSocket 连接管理器
- proxy 头部重写(CSP/X-Frame-Options)
- target 仓储 update 方法
- app 健康检查 + SPA 404
- scenarios 模板端点 + 404
- files API 边缘分支(404 场景 + 500 兜底)
- files service update_category
- 智能评估状态机迁移测试

门禁状态:
- 前端:tsc 干净 + 232 passed
- 后端:954 passed + ruff 全绿
2026-08-24 15:56:09 +08:00

37 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Report submission phase: executing → completed."""
from typing import Any
from sqlmodel import Session
from agenteval.intelligent_eval.lifecycle._core import IntelligentEvalTransitionError, resolve_write
from agenteval.intelligent_eval.models import IntelligentEval, IntelligentEvalSessionStatus, IntelligentEvalStatus
from agenteval.intelligent_eval.repository import IntelligentEvalRepository, IntelligentEvalSessionRepository
def submit_report(session: Session, eval_id: str, report: dict[str, Any]) -> IntelligentEval:
"""OpenClaw 提交结构化报告executing → completed。
报告结构校验在路由层pydantic此处只负责落库与状态迁移。提交前必须
满足存在会话时须全部到达终态completed/failed/expired——否则拒绝
杜绝"评估 completed 但 completed_sessions=0进度 0%"的不一致。
ADR-0011卡死的 running 会话由 expire_stale_running_sessions 置 expired
(不完整证据),不再阻塞报告提交。
"""
repo = IntelligentEvalRepository(session)
eval_sessions = IntelligentEvalSessionRepository(session).list_by_eval(eval_id)
if any(s.status == IntelligentEvalSessionStatus.RUNNING for s in eval_sessions):
raise IntelligentEvalTransitionError("存在进行中的会话,不能提交报告")
# ADR-0011submit 边界把 scores 归一到 {overall, dimensions} 单一规范结构
if report.get("scores"):
from agenteval.intelligent_eval.report import normalize_scores
report = {**report, "scores": normalize_scores(report["scores"])}
result = repo._submit_report_if_executing(eval_id, report)
return resolve_write(
eval_id,
result,
expected=IntelligentEvalStatus.EXECUTING,
target=IntelligentEvalStatus.COMPLETED,
)