架构重构(候选 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 全绿
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""Repository for evaluation targets."""
|
|
|
|
from typing import Optional
|
|
|
|
from agenteval.models import EvalTarget
|
|
from agenteval.storage.db import EvalTargetDB, utc_now
|
|
from agenteval.storage.repository.base import BaseRepository
|
|
|
|
|
|
class TargetRepository(BaseRepository[EvalTarget, EvalTargetDB]):
|
|
"""Repository for evaluation targets."""
|
|
|
|
_table = EvalTargetDB
|
|
_order_by = "created_at"
|
|
|
|
def _to_db(self, target: EvalTarget) -> EvalTargetDB:
|
|
db = EvalTargetDB(
|
|
id=target.id,
|
|
name=target.name,
|
|
description=target.description,
|
|
platform=target.platform.value,
|
|
channel_type=target.channel_type.value,
|
|
status=target.status.value,
|
|
created_at=target.created_at,
|
|
updated_at=target.updated_at or utc_now(),
|
|
)
|
|
db.set_config(target.channel_config)
|
|
return db
|
|
|
|
def _from_db(self, db: EvalTargetDB) -> EvalTarget:
|
|
return EvalTarget(
|
|
id=db.id,
|
|
name=db.name,
|
|
description=db.description,
|
|
platform=db.platform,
|
|
channel_type=db.channel_type,
|
|
channel_config=db.get_config(),
|
|
status=db.status,
|
|
created_at=db.created_at,
|
|
updated_at=db.updated_at,
|
|
)
|
|
|
|
def update(self, target: EvalTarget) -> Optional[EvalTarget]:
|
|
existing = self.session.get(EvalTargetDB, target.id)
|
|
if not existing:
|
|
return None
|
|
existing.name = target.name
|
|
existing.description = target.description
|
|
existing.platform = target.platform.value
|
|
existing.channel_type = target.channel_type.value
|
|
existing.status = target.status.value
|
|
existing.set_config(target.channel_config)
|
|
existing.updated_at = utc_now()
|
|
self.session.add(existing)
|
|
self.session.commit()
|
|
self.session.refresh(existing)
|
|
return self._from_db(existing)
|