55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
"""校验 5 个进化/动量模板存在且输出契约关键词与解析代码对齐。"""
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
_PROMPTS_DIR = Path("prompts")
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"name, required_tokens",
|
|
[
|
|
("evolve_skill.md", ["suggestions", "edits"]),
|
|
("evolve_system.md", ["suggestions", "edits"]),
|
|
("evolve_tool.md", ["edits_extract", "edits_verify"]),
|
|
("evolve_rank.md", ["selected_indices"]),
|
|
("slow_momentum.md", ["slow_update_content"]),
|
|
],
|
|
)
|
|
def test_evolve_template_present_and_contract(name: str, required_tokens: list[str]) -> None:
|
|
path = _PROMPTS_DIR / name
|
|
assert path.exists(), f"缺模板: {path}"
|
|
text = path.read_text(encoding="utf-8")
|
|
assert text.strip(), f"模板为空: {path}"
|
|
for token in required_tokens:
|
|
assert token in text, f"{name} 缺输出契约关键词 {token!r}(与解析代码不对齐)"
|
|
|
|
|
|
def test_video_split_loader_fail_loud_on_missing(tmp_path, monkeypatch):
|
|
"""video_split_cli 的真实 diagnose 加载器缺模板必须 FileNotFoundError。"""
|
|
monkeypatch.chdir(tmp_path) # 空目录,无 prompts/*.md
|
|
from app.harness.video_split_cli import _load_diagnose_prompts
|
|
|
|
with pytest.raises(FileNotFoundError, match="缺进化/诊断模板"):
|
|
_load_diagnose_prompts()
|
|
|
|
|
|
def test_runner_evolve_loader_fail_loud_on_missing(tmp_path, monkeypatch):
|
|
"""runner 的真实 evolve 加载器缺模板必须 FileNotFoundError。"""
|
|
monkeypatch.chdir(tmp_path)
|
|
from app.harness.runner import Runner
|
|
|
|
r = object.__new__(Runner) # 绕过 __init__,仅测无状态加载器方法
|
|
with pytest.raises(FileNotFoundError, match="缺进化/诊断模板"):
|
|
r._load_evolve_prompts()
|
|
|
|
|
|
def test_runner_diagnose_loader_fail_loud_on_missing(tmp_path, monkeypatch):
|
|
"""runner 的真实 diagnose 加载器缺模板必须 FileNotFoundError。"""
|
|
monkeypatch.chdir(tmp_path)
|
|
from app.harness.runner import Runner
|
|
|
|
r = object.__new__(Runner)
|
|
with pytest.raises(FileNotFoundError, match="缺进化/诊断模板"):
|
|
r._load_diagnose_prompts()
|