AgentEvalTool/tests/unit/test_cascade.py
sinohqb a77cd83e6a v0.2.0-dev: 文件管理 + 页面布局统一 + 6 个 bug 修复
## 新增功能
- 文件管理模块:分类树 + 文件上传/下载/删除
- 文件上传支持拖拽(Dragger)+ 手动上传(customRequest 模式)

## 页面布局统一(参照评测执行页)
- 仪表盘/评测对象/评测场景/评测报告 全部改为全高 flex 布局
- 统一内联页头样式(h2 + 竖线分隔 + 描述)
- 表格撑满高度、overflow 处理
- 每页添加刷新按钮

## Bug 修复
- 分类树操作按钮 hover 不可见(CSS 规则缺失)
- 文件上传失败(multipart boundary 缺失)
- LLM API 响应 content blocks 数组格式支持(_extract_content_from_api_response)
- response_time_max_ms 被静默忽略(隐式规则传空 params)
- 空 messages 导致 IndexError 崩溃
- poll_reply 异常中止整个 run(缺 try/catch)
- engine finally 未关闭 session
- 3 个页面 UTC 时间戳解析偏差 8 小时

## 后端
- EvalEngine: poll_reply 异常保护、空 dialog 保护、session 关闭
- LLM API 响应解析支持 content-block-array 格式
- 隐式 response_time 规则正确传递 max_ms 参数

## 前端
- api.ts: 移除手动 Content-Type(让浏览器自动添加 boundary)
- Files.tsx: customRequest 替代 beforeUpload、布局优化
- index.css: 分类树 hover 规则
- Targets/Scenarios/Home/Reports: 全高布局改造
- 3 个页面时间戳改用 formatDateTime()(修复 UTC 偏差)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-16 15:25:22 +08:00

89 lines
2.9 KiB
Python

"""Tests for cascade delete behavior.
Deleting a run should automatically delete its turns and results.
Deleting a target/scenario should automatically delete its runs.
"""
import pytest
from agenteval.models import (
Case, CaseType, ChannelType, EvalResult, EvalRun, EvalTarget, PlatformType,
RunStatus, Scenario, TargetStatus, Turn,
)
from agenteval.storage.db import EvalResultDB, EvalRunDB, EvalTargetDB, ScenarioDB, TurnDB
from agenteval.storage.repository import (
ResultRepository, RunRepository, ScenarioRepository, TargetRepository,
)
def _make_target() -> EvalTarget:
return EvalTarget(
id="t-1", name="t",
platform=PlatformType.AI_DIGITAL_EMPLOYEE,
channel_type=ChannelType.TUTU_API,
channel_config={"base_url": "x", "token": "x", "tenant": "x",
"chat_channel_id": "x", "chat_contact_id": "x"},
)
def _make_scenario() -> Scenario:
return Scenario(
id="s-1", name="s",
cases=[Case(id="c1", type=CaseType.SINGLE, messages=["hi"])],
)
def test_delete_run_cascades_to_turns_and_results(db_session):
TargetRepository(db_session).create(_make_target())
ScenarioRepository(db_session).create(_make_scenario())
run = RunRepository(db_session).create(EvalRun(
id="r-1", target_id="t-1", scenario_id="s-1", status=RunStatus.COMPLETED,
))
turn = ResultRepository(db_session).save_turn(Turn(
id="tu-1", run_id="r-1", case_id="c1", round_index=1,
))
ResultRepository(db_session).save_result(EvalResult(
id="e-1", run_id="r-1", case_id="c1", turn_id="tu-1",
rule_type="keyword_match", passed=True,
))
# Sanity: everything is there.
assert db_session.get(EvalRunDB, "r-1") is not None
assert db_session.get(TurnDB, "tu-1") is not None
assert db_session.get(EvalResultDB, "e-1") is not None
# Delete the run.
RunRepository(db_session).delete("r-1")
# Turn and result must be gone too.
assert db_session.get(EvalRunDB, "r-1") is None
assert db_session.get(TurnDB, "tu-1") is None
assert db_session.get(EvalResultDB, "e-1") is None
def test_delete_target_cascades_to_runs(db_session):
TargetRepository(db_session).create(_make_target())
ScenarioRepository(db_session).create(_make_scenario())
RunRepository(db_session).create(EvalRun(
id="r-1", target_id="t-1", scenario_id="s-1",
))
TargetRepository(db_session).delete("t-1")
assert db_session.get(EvalTargetDB, "t-1") is None
assert db_session.get(EvalRunDB, "r-1") is None
def test_delete_scenario_cascades_to_runs(db_session):
TargetRepository(db_session).create(_make_target())
ScenarioRepository(db_session).create(_make_scenario())
RunRepository(db_session).create(EvalRun(
id="r-1", target_id="t-1", scenario_id="s-1",
))
ScenarioRepository(db_session).delete("s-1")
assert db_session.get(ScenarioDB, "s-1") is None
assert db_session.get(EvalRunDB, "r-1") is None