fix: fail-loud on missing evolve/diagnose templates (no silent empty)
This commit is contained in:
@@ -2269,7 +2269,9 @@ class Runner:
|
|||||||
|
|
||||||
def _read(name: str) -> str:
|
def _read(name: str) -> str:
|
||||||
p = Path("prompts") / name
|
p = Path("prompts") / name
|
||||||
return p.read_text(encoding="utf-8") if p.exists() else ""
|
if not p.exists():
|
||||||
|
raise FileNotFoundError(f"缺进化/诊断模板: {p}(请从 TRM4 迁移或检查 prompts/)")
|
||||||
|
return p.read_text(encoding="utf-8")
|
||||||
|
|
||||||
return EvolvePrompts(
|
return EvolvePrompts(
|
||||||
evolve_skill=_read("evolve_skill.md"),
|
evolve_skill=_read("evolve_skill.md"),
|
||||||
@@ -2284,7 +2286,9 @@ class Runner:
|
|||||||
|
|
||||||
def _read(name: str) -> str:
|
def _read(name: str) -> str:
|
||||||
p = Path("prompts") / name
|
p = Path("prompts") / name
|
||||||
return p.read_text(encoding="utf-8") if p.exists() else ""
|
if not p.exists():
|
||||||
|
raise FileNotFoundError(f"缺进化/诊断模板: {p}(请从 TRM4 迁移或检查 prompts/)")
|
||||||
|
return p.read_text(encoding="utf-8")
|
||||||
|
|
||||||
return DiagnosePrompts(
|
return DiagnosePrompts(
|
||||||
defect_vs_lapse=_read("defect_vs_lapse.md"),
|
defect_vs_lapse=_read("defect_vs_lapse.md"),
|
||||||
|
|||||||
@@ -365,7 +365,9 @@ def _load_diagnose_prompts() -> Any:
|
|||||||
|
|
||||||
def _read(name: str) -> str:
|
def _read(name: str) -> str:
|
||||||
p = Path("prompts") / name
|
p = Path("prompts") / name
|
||||||
return p.read_text(encoding="utf-8") if p.exists() else ""
|
if not p.exists():
|
||||||
|
raise FileNotFoundError(f"缺进化/诊断模板: {p}(请从 TRM4 迁移或检查 prompts/)")
|
||||||
|
return p.read_text(encoding="utf-8")
|
||||||
|
|
||||||
return DiagnosePrompts(
|
return DiagnosePrompts(
|
||||||
defect_vs_lapse=_read("defect_vs_lapse.md"),
|
defect_vs_lapse=_read("defect_vs_lapse.md"),
|
||||||
|
|||||||
@@ -23,3 +23,32 @@ def test_evolve_template_present_and_contract(name: str, required_tokens: list[s
|
|||||||
assert text.strip(), f"模板为空: {path}"
|
assert text.strip(), f"模板为空: {path}"
|
||||||
for token in required_tokens:
|
for token in required_tokens:
|
||||||
assert token in text, f"{name} 缺输出契约关键词 {token!r}(与解析代码不对齐)"
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user