Files
life-echo/api/app/features/evaluation/user_export_fixtures.py
Kevin ca8bcc8489 feat(evaluation): session catalog, user export import, and eval web UI
- 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)
2026-04-06 13:49:28 +08:00

37 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""只读加载 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