muse-agent-example/tests/单元/test_机器味诊断合同.py
zizi cf0f4fb985 W20–W24:保存知识方法、迁移框架、审校修订与案例行为的集成成果
接续 88dd570,保存 W20–W24 已实现的共享接口、业务入口、迁移、工作台、测试与文档。
W20/W22/W23 保持 in_progress,W21/W24 保持 verified;此提交不宣称方法或规则正式启用、多轮返修、真实角色评测完成。

W25 新增实验、标定、逐调用交付与角色执行及其迁移/测试/索引留在实施工作树,原有私人和旧实现保留项不纳入。

验证:离线 571、前端 33 通过;PG 469 项通过、2 项浏览器未启用,2 项误带入的 W25 用例已移出本提交;最终任务与交付边界 37 项通过。make 检查、最终类型、84 项资源及 diff 检查通过。未重跑浏览器或 Pi 宿主,不以合成调用认证外部模型效果。
独立整体审查四维通过;证据保存在 R2-20260909/提交W20-W24。
2026-09-13 16:24:42 +08:00

90 lines
3.8 KiB
Python

"""规则候选四类例证与完整只读诊断;不把预览当作规则启用或文学认证。"""
from copy import deepcopy
import pytest
from muse.审校修订.接口 import (
审校错误,
核对规则,
核对规则启用,
核对规则库,
诊断文本,
读取内置规则,
)
def test_规则种子候选与四类例证双向对应__228001():
库 = 读取内置规则()
assert len(库["rules"]) == 26 and len(库["samples"]) == 107
for r in 库["rules"].values():
assert r["status"] == "candidate"
for kind in ("sf", "snf", "boundary", "regression"):
assert r["samples"][kind]
for id_ in r["samples"][kind]:
assert 库["samples"][id_]["type"] == kind
assert r["id"] in 库["samples"][id_]["rules"]
with pytest.raises(审校错误, match="B10"):
核对规则启用(r, 库["samples"], {"self_reported": True})
@pytest.mark.parametrize(
"坏处", ["缺类", "缺样例", "错类", "反向引用", "重复规则", "重复例证", "未知触发器"]
)
def test_坏规则或例证缺口不能装载__228002(坏处):
库 = deepcopy(读取内置规则())
r = 库["rules"]["l002"]
s = 库["samples"]
if 坏处 == "缺类":
r["samples"]["regression"] = []
elif 坏处 == "缺样例":
r["samples"]["sf"] = ["不存在"]
elif 坏处 == "错类":
s[r["samples"]["sf"][0]]["type"] = "snf"
elif 坏处 == "反向引用":
s[r["samples"]["sf"][0]]["rules"] = []
elif 坏处 == "未知触发器":
r["trigger"]["type"] = "script"
with pytest.raises(审校错误):
if 坏处 == "重复规则":
核对规则库([r, r], list(s.values()))
elif 坏处 == "重复例证":
核对规则库([r], list(s.values()) + [next(iter(s.values()))])
else:
核对规则(r, s)
def test_候选预览全文对白与有意表达不误判__228003():
库 = 读取内置规则()
文本 = "「值得注意的是,这是对白。」" + "雨落下来。" * 9000 + "值得注意的是,这是叙述。"
assert 诊断文本(文本, work_id="w", 规则库=库)["findings"] == []
报告 = 诊断文本(文本, work_id="w", 规则库=库, 预览候选=True)
发现 = [r for r in 报告["findings"] if r["rule_id"] == "l002"]
assert len(发现) == 1 and 发现[0]["start"] > 40000
assert 发现[0]["quote"] == 文本[发现[0]["start"] : 发现[0]["end"]]
assert 发现[0]["carrier"] == "narration" and 发现[0]["decision_proposal"] == "ask"
assert 报告["coverage"]["deterministic"] == [[0, len(文本)]]
assert 报告["unreviewed_rules"] and 报告["calibration"] == "uncalibrated"
保护 = 诊断文本(文本, work_id="w", 规则库=库, 预览候选=True, 保护表达=("值得注意的是",))
assert (
next(r for r in 保护["findings"] if r["rule_id"] == "l002")["decision_proposal"] == "retain"
)
@pytest.mark.parametrize("文本,作品", [("", "w"), (" ", "w"), ("正常文字。", "")])
def test_空正文或无作品拒绝诊断__228004(文本, 作品):
with pytest.raises(审校错误):
诊断文本(文本, work_id=作品, 规则库=读取内置规则())
def test_指纹覆盖所有内容而非只看版本号__228005():
库 = 读取内置规则()
r = deepcopy(库)
r["rules"]["l001"]["fix_hint"] = "新的处置意见"
with pytest.raises(审校错误, match="指纹"):
诊断文本("正常文字。", work_id="w", 规则库=r)
新 = 核对规则库(list(r["rules"].values()), list(r["samples"].values()))
assert 新["fingerprint"] != 库["fingerprint"]
报告 = 诊断文本("春天到了。", work_id="w", 规则库=库, 预览候选=True)
assert 报告["findings"] == [] and 报告["executed_rules"] and not 报告["persisted"]