- Extend evaluation API: schemas, router, repo, admin and execution services - Improve user export markdown importer; add fixtures and importer tests - Session catalog repo/service updates; internal app wiring and docs - Add internal-eval.sh helper; refresh app-eval-web (App, styles, Vite)
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""只读加载 api/tests/user_exports/*.md,供内部评测台对照(非生产数据路径)。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import re
|
||
from pathlib import Path
|
||
|
||
from app.features.evaluation.importers.user_export_markdown import (
|
||
extract_dialogue_turns_from_export_md,
|
||
)
|
||
|
||
_SAFE_MD = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9_.-]*\.md$")
|
||
|
||
|
||
def user_exports_dir() -> Path:
|
||
# api/app/features/evaluation/user_export_fixtures.py → api/
|
||
return Path(__file__).resolve().parents[3] / "tests" / "user_exports"
|
||
|
||
|
||
def list_user_export_fixture_names() -> list[str]:
|
||
root = user_exports_dir()
|
||
if not root.is_dir():
|
||
return []
|
||
return sorted(p.name for p in root.glob("*.md"))
|
||
|
||
|
||
def read_user_export_fixture(filename: str) -> tuple[list[tuple[str, str]], str]:
|
||
if not _SAFE_MD.match(filename):
|
||
raise ValueError("invalid fixture filename")
|
||
root = user_exports_dir()
|
||
path = (root / filename).resolve()
|
||
if path.parent != root.resolve() or not path.is_file():
|
||
raise FileNotFoundError(filename)
|
||
text = path.read_text(encoding="utf-8")
|
||
turns = extract_dialogue_turns_from_export_md(text)
|
||
return turns, text
|