- src/muse 新版全模块(装配/共享/上下文/任务运行/作品规划/故事世界/正文写作/审校修订/知识方法/作者经验/效果评测/交付连载/资料研究/正式变更/元数据/接入/基础设施/编排)+ 测试树(单元/契约/集成/架构/迁移/端到端/夹具) - 129 项功能全部实现与自动验证(功能覆盖.json/矩阵),含 W31 补齐的规则与代价/节奏安排/伏笔与承诺 - 旧实现按处置清单退出(702 条中 324 删,保护合同与未迁移条目留存有据);web/app.py 旧工作台退役,新工作台为唯一写入口 - 数据库/旧库迁移:真实旧库内容批次迁移链(端点守卫/PG作品正文映射/质量资产缺省投影) - 运行手册 docs/运行手册.md;W30 本机服务阶段一已运行(infra PG 为正式内容权威) - R2 执行证据与私有运行材料在 .agents.local/改造/R2-20260909/(不入库)
134 lines
5.0 KiB
Python
134 lines
5.0 KiB
Python
"""B06核原字和完整声明;纯合同验证不认证模型执行或语义正确性。"""
|
||
|
||
import copy
|
||
|
||
import pytest
|
||
|
||
from muse.审校修订.接口 import 审校错误, 核对语义检测, 组装语义检测材料
|
||
|
||
|
||
def 材料():
|
||
return 组装语义检测材料(
|
||
"旅者等在城门。",
|
||
{
|
||
"sources": [{"source_id": "outline", "kind": "fine_outline", "text": "旅者守门。"}],
|
||
"assertions": [{"statement_id": "guard", "text": "旅者是守卫。"}],
|
||
"constraints": [{"statement_id": "stay", "text": "不得离开城门。"}],
|
||
},
|
||
)
|
||
|
||
|
||
def 输出(material, script="ok"):
|
||
quote = material["candidate"]
|
||
result = {
|
||
"claims": [
|
||
{
|
||
"claim_id": "claim-1",
|
||
"text": "候选中人物采取行动。",
|
||
"candidate_quote": quote,
|
||
"state": "supported",
|
||
"evidence_refs": ["source:outline"],
|
||
"reason": "参照细纲核对。",
|
||
}
|
||
],
|
||
"findings": [],
|
||
"assertion_verdicts": [
|
||
{
|
||
"statement_id": id_,
|
||
"verdict": "pass",
|
||
"candidate_quote": quote,
|
||
"evidence_refs": ["assertion:" + id_],
|
||
"reason": "与给定命题相符。",
|
||
}
|
||
for id_ in material["required_assertions"]
|
||
],
|
||
"constraint_verdicts": [
|
||
{
|
||
"statement_id": id_,
|
||
"verdict": "pass",
|
||
"candidate_quote": quote,
|
||
"evidence_refs": ["constraint:" + id_],
|
||
"reason": "符合给定约束。",
|
||
}
|
||
for id_ in material["required_constraints"]
|
||
],
|
||
"new_setting_candidates": [],
|
||
}
|
||
if script == "high":
|
||
result["findings"] = [
|
||
{
|
||
"finding_id": "high-1",
|
||
"category": "fact",
|
||
"severity": "high",
|
||
"candidate_quote": quote,
|
||
"evidence_refs": ["source:outline"],
|
||
"message": "合成事实冲突。",
|
||
}
|
||
]
|
||
elif script == "unknown":
|
||
result["claims"][0].update(state="unknown", evidence_refs=[], reason="给定来源不足以认定。")
|
||
result["constraint_verdicts"][0].update(verdict="unknown", reason="约束无法确定。")
|
||
result["new_setting_candidates"] = [
|
||
{"claim_id": "claim-1", "proposal": "待作者核对的新设定。"}
|
||
]
|
||
elif script == "missing":
|
||
result["assertion_verdicts"] = []
|
||
return result
|
||
|
||
|
||
def test_原字定位与命题覆盖来自实际材料__25f101():
|
||
material = 材料()
|
||
result = 核对语义检测(material, 输出(material))
|
||
assert result["claims"][0]["start"] == 0
|
||
assert result["claims"][0]["end"] == len(material["candidate"])
|
||
assert result["constraint_counts"] == {"pass": 1, "fail": 0, "unknown": 0}
|
||
assert result["status"] == "passed"
|
||
|
||
|
||
@pytest.mark.parametrize(
|
||
"variant", ["passed", "quote", "missing", "reference", "duplicate", "position", "external"]
|
||
)
|
||
def test_缺项陌生依据及自报通过不能伪装检测__25f102(variant):
|
||
material = 材料()
|
||
output = 输出(material)
|
||
if variant == "passed":
|
||
output["passed"] = True
|
||
elif variant == "quote":
|
||
output["claims"][0]["candidate_quote"] = "原文没有这句话"
|
||
elif variant == "missing":
|
||
output["assertion_verdicts"] = []
|
||
elif variant == "reference":
|
||
output["claims"][0]["evidence_refs"] = ["source:stranger"]
|
||
elif variant == "duplicate":
|
||
output["claims"].append(copy.deepcopy(output["claims"][0]))
|
||
elif variant == "position":
|
||
output["claims"][0]["start"] = 0
|
||
else:
|
||
output = 输出(material, "high")
|
||
output["findings"][0]["evidence_refs"] = ["candidate"]
|
||
with pytest.raises(审校错误):
|
||
核对语义检测(material, output)
|
||
|
||
|
||
def test_高严重度与未知不得被零发现覆盖__25f103():
|
||
material = 材料()
|
||
high = 核对语义检测(material, 输出(material, "high"))
|
||
unknown = 核对语义检测(material, 输出(material, "unknown"))
|
||
assert high["status"] == "failed" and high["high_severity_count"] == 1
|
||
assert unknown["status"] == "inconclusive" and unknown["unknown_count"] == 2
|
||
assert unknown["new_setting_candidates"][0]["claim_id"] == "claim-1"
|
||
|
||
|
||
def test_声明新事实须有细纲且建议不能借用已确认陈述__25f104():
|
||
material = 材料()
|
||
output = 输出(material)
|
||
output["claims"][0].update(state="declared_new", evidence_refs=["assertion:guard"])
|
||
with pytest.raises(审校错误, match="细纲"):
|
||
核对语义检测(material, output)
|
||
output["claims"][0]["evidence_refs"] = ["source:outline"]
|
||
output["new_setting_candidates"] = [{"claim_id": "claim-1", "proposal": "新设定待确认。"}]
|
||
assert 核对语义检测(material, output)["new_setting_candidates"]
|
||
output["claims"][0]["state"] = "supported"
|
||
with pytest.raises(审校错误, match="未决"):
|
||
核对语义检测(material, output)
|