常见故障自愈有上限,超限收敛终态且可见:任务 attempts 上限、会话过期、 planning 双闸、executing 超窗兜底、触发失败计数判死、孤儿 agent 双管、 fire-and-forget 触发;open_session 预算硬闸门、settle 按终态区分、报告 scores 归一化;cron 池遗留面全删。
69 lines
1.8 KiB
Python
69 lines
1.8 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,
|
|
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()
|