- src/muse 新版全模块(装配/共享/上下文/任务运行/作品规划/故事世界/正文写作/审校修订/知识方法/作者经验/效果评测/交付连载/资料研究/正式变更/元数据/接入/基础设施/编排)+ 测试树(单元/契约/集成/架构/迁移/端到端/夹具) - 129 项功能全部实现与自动验证(功能覆盖.json/矩阵),含 W31 补齐的规则与代价/节奏安排/伏笔与承诺 - 旧实现按处置清单退出(702 条中 324 删,保护合同与未迁移条目留存有据);web/app.py 旧工作台退役,新工作台为唯一写入口 - 数据库/旧库迁移:真实旧库内容批次迁移链(端点守卫/PG作品正文映射/质量资产缺省投影) - 运行手册 docs/运行手册.md;W30 本机服务阶段一已运行(infra PG 为正式内容权威) - R2 执行证据与私有运行材料在 .agents.local/改造/R2-20260909/(不入库)
108 lines
3.9 KiB
Python
108 lines
3.9 KiB
Python
"""同命题分歧与预注册输入审计,不认证模型真值。"""
|
|
|
|
import copy
|
|
import json
|
|
|
|
import pytest
|
|
import test_效果判据 as 判据测试
|
|
|
|
from muse.效果评测.启用判据 import 判定效果
|
|
from muse.效果评测.混淆项 import _分歧, 审计输入, 核对审计声明
|
|
|
|
|
|
def _声明():
|
|
return dict(
|
|
version="writer-input-audit-v1",
|
|
annotation_ref="synthetic:annotation",
|
|
as_of_position=2,
|
|
forbidden_facts=[
|
|
dict(fact_id="future", text="林深在封闭祭坛取出了唯一信物", first_position=3)
|
|
],
|
|
declared_new_entity_ids=None,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"text,hit",
|
|
[
|
|
("林深在封闭祭坛取出了唯一信物", True),
|
|
("林深,在封闭祭坛,取出了唯一信物。", True),
|
|
("林深静静地守着城门。", False),
|
|
],
|
|
)
|
|
def test_机械审计识别登记片段且不回显秘密__25f612(text, hit):
|
|
audit = 核对审计声明(_声明())
|
|
r = 审计输入(dict(arm="C", user_input=text, system_prompt="合成指令"), audit)
|
|
assert bool(r["finding_count"]) is hit and r["status"] == "measured"
|
|
assert audit["forbidden_facts"][0]["text"] not in json.dumps(r, ensure_ascii=False)
|
|
|
|
|
|
@pytest.mark.parametrize("mutation", ["past", "duplicate", "empty_source", "bad_entity"])
|
|
def test_审计声明不接收错误时点重复或空身份__25f613(mutation):
|
|
from muse.共享.错误 import Muse错误
|
|
|
|
r = _声明()
|
|
if mutation == "past":
|
|
r["forbidden_facts"][0]["first_position"] = 2
|
|
if mutation == "duplicate":
|
|
r["forbidden_facts"] *= 2
|
|
if mutation == "empty_source":
|
|
r["annotation_ref"] = " "
|
|
if mutation == "bad_entity":
|
|
r["declared_new_entity_ids"] = [" "]
|
|
with pytest.raises((Muse错误, ValueError)):
|
|
核对审计声明(r)
|
|
|
|
|
|
def test_同ID不同命题类型不会串算且未知保留未完__25f614():
|
|
sample = dict(
|
|
literary={
|
|
"A:C": dict(
|
|
status="stable_report",
|
|
execution_verified=True,
|
|
candidates={"a": "A", "c": "C"},
|
|
verdicts=[
|
|
dict(kind=k, candidate_id=c, statement_id="same", verdict=v)
|
|
for k, c, v in [
|
|
("assertion_verdicts", "a", "fail"),
|
|
("constraint_verdicts", "a", "pass"),
|
|
("assertion_verdicts", "c", "pass"),
|
|
("constraint_verdicts", "c", "pass"),
|
|
]
|
|
],
|
|
)
|
|
},
|
|
detections={
|
|
arm: dict(
|
|
report={
|
|
k: [dict(statement_id="same", verdict=v)]
|
|
for k, v in [("assertion_verdicts", av), ("constraint_verdicts", cv)]
|
|
}
|
|
)
|
|
for arm, av, cv in [("A", "pass", "pass"), ("C", "pass", "fail")]
|
|
},
|
|
)
|
|
clean = dict(status="measured", finding_count=0)
|
|
fn, fp = _分歧(sample, ["A", "C"], clean)
|
|
assert fn["finding_count"] == fp["finding_count"] == 1
|
|
assert fn["findings"][0]["kind"] == "assertion_verdicts"
|
|
assert fp["findings"][0]["kind"] == "constraint_verdicts"
|
|
sample["detections"]["C"]["report"]["constraint_verdicts"][0]["verdict"] = "unknown"
|
|
assert _分歧(sample, ["A", "C"], clean)[1]["status"] == "incomplete"
|
|
del sample["detections"]["A"]
|
|
assert _分歧(sample, ["A", "C"], clean)[0]["denominator"] == 4
|
|
assert (
|
|
_分歧(sample, ["A", "C"], dict(status="not_measured", finding_count=None))[1][
|
|
"finding_count"
|
|
]
|
|
is None
|
|
)
|
|
|
|
|
|
def test_新混淆展示不改变既有统计凭据依据__25f615():
|
|
data = 判据测试._输入()
|
|
before = 判定效果(*data)
|
|
changed = copy.deepcopy(data)
|
|
changed[3]["confounders"] = {"version": "evaluation-confounders-v1", "samples": {}}
|
|
assert 判定效果(*changed) == before
|