AgentEvalTool/tests/conftest.py
sinohqb 71543f042a refactor(intelligent-eval): 可见性接缝收敛(Phase 1)
将「已删即 404」语义收进 IntelligentEvalRepository 单一接缝,消除三处独立裁决;
任务监控开始隐藏已删评估的任务(本 Phase 唯一刻意行为变化)。

- repository.py 新增 visible() 谓词与 require_live_eval() 服务接缝;
  六处裸谓词统一走它,get()/get_including_deleted() 语义不变。
- decision_logs.py 删除本地 _require_eval,三处调用迁至 repository 接缝;
  count_decisions 由 len(.all()) 改为 func.count。
- task_queue.py list_tasks 与 stats 过滤已删评估的任务(行为变化)。
- web/routers/intelligent_evals.py: _require_eval_exists → _require_live_eval,
  把 LookupError 翻译为 404;expired 会话 Markdown 标注下沉至
  read_model.report_markdown_by_eval;配置快照 11 字段序列化收至
  config_snapshot.snapshot_to_dict 单一出口。
- AGENTS.md 登记可见性纪律(已知陷阱 #6)。
- 补 characterization 测试锁定四处契约;更新 task_queue 测试以使用
  真实 eval_id(可见性过滤后字面 eval_id 不再可见)。
2026-08-24 05:47:00 +08:00

70 lines
1.9 KiB
Python

"""Shared test fixtures."""
import os
from pathlib import Path
import pytest
from sqlmodel import Session, SQLModel, create_engine
# Force tests to use a temp SQLite file instead of the real data/ dir.
os.environ.setdefault("AGENTEVAL_DATA_DIR_OVERRIDE", "")
@pytest.fixture()
def anyio_backend():
return "asyncio"
@pytest.fixture()
def tmp_db_path(tmp_path: Path) -> Path:
"""Return a path to a throwaway SQLite file for one test."""
return tmp_path / "test.db"
@pytest.fixture()
def db_session(tmp_db_path: Path) -> Session:
"""Yield a SQLModel Session backed by a fresh in-memory-ish SQLite file.
Tables are created via SQLModel.metadata.create_all; the session is closed
at the end of the test.
"""
# Import DB models so their table=True declarations register in metadata.
from agenteval.storage.db import ( # noqa: F401
CampaignAnalysisDB,
CampaignDB,
EvalResultDB,
EvalRunDB,
EvalTargetDB,
ExplorationMessageDB,
ExplorationSessionDB,
IntelligentEvalConfigSnapshotDB,
IntelligentEvalDB,
IntelligentEvalDecisionLogDB,
IntelligentEvalMessageDB,
IntelligentEvalSessionDB,
IntelligentEvalTaskQueueDB,
ModelConfigDB,
ScenarioDB,
ScenarioModelBindingDB,
TurnDB,
)
engine = create_engine(
f"sqlite:///{tmp_db_path}",
connect_args={"check_same_thread": False},
)
SQLModel.metadata.create_all(engine)
# Sanity check: verify the scenarios table has all expected columns.
from sqlalchemy import inspect as sa_inspect
cols = [c["name"] for c in sa_inspect(engine).get_columns("scenarios")]
assert "llm_config" in cols, f"scenarios table missing llm_config; cols={cols}"
session = Session(engine)
try:
yield session
finally:
session.close()
engine.dispose()