feat/ eval
This commit is contained in:
@@ -5,6 +5,8 @@ import pytest
|
||||
|
||||
from app.features.evaluation.importers.user_export_markdown import (
|
||||
extract_dialogue_turns_from_export_md,
|
||||
extract_memoir_chapter_sections_from_export_md,
|
||||
extract_source_user_id_from_export_md,
|
||||
extract_user_utterances_from_export_md,
|
||||
)
|
||||
|
||||
@@ -72,3 +74,32 @@ def test_extract_dialogue_turns_from_repo_user_export() -> None:
|
||||
turns = extract_dialogue_turns_from_export_md(text)
|
||||
assert len(turns) >= 5
|
||||
assert "你好" in turns[0][0]
|
||||
|
||||
|
||||
def test_extract_source_user_id_from_export_md() -> None:
|
||||
md = "- **User ID:** `e27fcd97-fefa-43b8-a7a3-3ecd49ebf5f0`\n"
|
||||
assert (
|
||||
extract_source_user_id_from_export_md(md)
|
||||
== "e27fcd97-fefa-43b8-a7a3-3ecd49ebf5f0"
|
||||
)
|
||||
|
||||
|
||||
def test_extract_memoir_chapter_sections_from_export_md() -> None:
|
||||
md = """
|
||||
## 回忆录章节(生成正文)
|
||||
|
||||
### First chapter
|
||||
|
||||
Line a.
|
||||
{{IMAGE:foo}}
|
||||
|
||||
### Second title
|
||||
|
||||
Line b.
|
||||
"""
|
||||
sections = extract_memoir_chapter_sections_from_export_md(md)
|
||||
assert len(sections) == 2
|
||||
assert sections[0][0] == "First chapter"
|
||||
assert "Line a." in sections[0][1]
|
||||
assert "{{IMAGE" not in sections[0][1]
|
||||
assert sections[1][0] == "Second title"
|
||||
|
||||
74
api/tests/evaluation/test_replay_router.py
Normal file
74
api/tests/evaluation/test_replay_router.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""回放 / 评审路由参数校验(最小 HTTP)。"""
|
||||
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
from app.features.evaluation.internal_auth import get_internal_eval_principal
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_replay_conversation_requires_fixture_or_utterances(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
from fastapi import FastAPI
|
||||
|
||||
monkeypatch.setattr(
|
||||
"app.core.config.settings.internal_eval_api_key",
|
||||
"secret",
|
||||
raising=False,
|
||||
)
|
||||
from app.features.evaluation.router import router
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router, prefix="/internal/api/evaluation")
|
||||
|
||||
async def _override_auth():
|
||||
from app.features.evaluation.internal_auth import InternalEvalPrincipal
|
||||
|
||||
return InternalEvalPrincipal()
|
||||
|
||||
app.dependency_overrides[get_internal_eval_principal] = _override_auth
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(transport=transport, base_url="http://t") as client:
|
||||
r = await client.post(
|
||||
"/internal/api/evaluation/replay/conversation",
|
||||
headers={"X-Internal-Eval-Key": "secret"},
|
||||
json={"conversation_id": "00000000-0000-0000-0000-000000000001"},
|
||||
)
|
||||
assert r.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_replay_conversation_rejects_both_fixture_and_utterances(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
from fastapi import FastAPI
|
||||
|
||||
monkeypatch.setattr(
|
||||
"app.core.config.settings.internal_eval_api_key",
|
||||
"secret",
|
||||
raising=False,
|
||||
)
|
||||
from app.features.evaluation.router import router
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router, prefix="/internal/api/evaluation")
|
||||
|
||||
async def _override_auth():
|
||||
from app.features.evaluation.internal_auth import InternalEvalPrincipal
|
||||
|
||||
return InternalEvalPrincipal()
|
||||
|
||||
app.dependency_overrides[get_internal_eval_principal] = _override_auth
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(transport=transport, base_url="http://t") as client:
|
||||
r = await client.post(
|
||||
"/internal/api/evaluation/replay/conversation",
|
||||
headers={"X-Internal-Eval-Key": "secret"},
|
||||
json={
|
||||
"conversation_id": "00000000-0000-0000-0000-000000000001",
|
||||
"fixture_filename": "x.md",
|
||||
"user_utterances": ["a"],
|
||||
},
|
||||
)
|
||||
assert r.status_code == 400
|
||||
Reference in New Issue
Block a user