架构重构(候选 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 全绿
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
"""Tests for scenario template endpoints and 404 paths."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from agenteval.web.app import app
|
|
from agenteval.web.deps import get_db
|
|
from fastapi.testclient import TestClient
|
|
from sqlmodel import Session, SQLModel, create_engine
|
|
|
|
|
|
@pytest.fixture()
|
|
def scenarios_client(tmp_path: Path):
|
|
from agenteval.storage.db import ScenarioDB # noqa: F401
|
|
|
|
engine = create_engine(
|
|
f"sqlite:///{tmp_path / 'scenarios_api.db'}",
|
|
connect_args={"check_same_thread": False},
|
|
)
|
|
SQLModel.metadata.create_all(engine)
|
|
session = Session(engine)
|
|
|
|
def override_get_db():
|
|
yield session
|
|
|
|
app.dependency_overrides[get_db] = override_get_db
|
|
with TestClient(app) as client:
|
|
yield client, session
|
|
|
|
app.dependency_overrides.clear()
|
|
session.close()
|
|
engine.dispose()
|
|
|
|
|
|
def test_list_scenario_templates(scenarios_client):
|
|
client, _ = scenarios_client
|
|
resp = client.get("/api/scenarios/templates")
|
|
assert resp.status_code == 200
|
|
assert isinstance(resp.json(), list)
|
|
|
|
|
|
def test_get_nonexistent_template_returns_404(scenarios_client):
|
|
client, _ = scenarios_client
|
|
resp = client.get("/api/scenarios/templates/nonexistent")
|
|
assert resp.status_code == 404
|
|
|
|
|
|
def test_get_nonexistent_scenario_returns_404(scenarios_client):
|
|
client, _ = scenarios_client
|
|
resp = client.get("/api/scenarios/nonexistent")
|
|
assert resp.status_code == 404
|
|
|
|
|
|
def test_update_nonexistent_scenario_returns_404(scenarios_client):
|
|
client, _ = scenarios_client
|
|
resp = client.put("/api/scenarios/nonexistent", json={"name": "test"})
|
|
assert resp.status_code == 404
|
|
|
|
|
|
def test_delete_nonexistent_scenario_returns_404(scenarios_client):
|
|
client, _ = scenarios_client
|
|
resp = client.delete("/api/scenarios/nonexistent")
|
|
assert resp.status_code == 404
|