muse-agent-example/tests/单元/test_规划审校发布模板.py
zizi d909d1bd1b 后端实现与用例身份:19 包集成落地并修复收尾缺陷
实现侧:
- 上下文:任务范围拆分为 范围校验/范围授权;索引按可发现口径重建、索引新鲜度改对称差;依赖校验统一快照漂移说明。
- 知识方法:方法与材料读取口径统一;超限方法材料按可选省略,核对路径不再二次计费;删除无合同的读时重算。
- 任务运行:新增 context.usage/tool.denied 事件类型;连接池常驻并在装配生命周期内开关;调用结算与核对分列。
- 效果评测/审校修订/交付连载/作者经验/作品规划:凭据冻结、标定消费、导出补证、事实引文核对等收尾修复。
- 资源加载:能力正文不再夹带索引用的导航注记(该注记此前进入角色与技能的模型提示)。
- 元数据:受保护骨架与代码保护属性对齐;字段校验与内置结构口径同步。
- 基础设施:环境预检进入装配生命周期;数据库连接运行期字段不参与相等比较;索引指纹归一化 jsonb 浮点。
- 删除被替代实现:7 份旧提示词模板与空壳 资料来源 读取器。

用例侧:
- 用例身份与导航元信息迁移;夹具补生命周期、同库暴露与模板封存;
- 本轮定向修复:方法材料省略、事实引文、迁移回执、额度与暂停用例、慢用例超时预算等。
2026-09-18 01:15:00 +08:00

91 lines
3.7 KiB
Python

"""规划与文学审校仅消费发布资源;发现技能不等于全部运行能力。"""
import hashlib
import json
import zipfile
from pathlib import Path
import pytest
from muse import 资源加载
from muse.共享.错误 import 资源缺失错误
from muse.审校修订.完整审校 import 文学模板
from muse.编排.生成规划 import 规划模板
from muse.资源加载 import 使用资源提供器, 安装包资源提供器, 读取能力
模板集 = (
(lambda: 规划模板("fine_outline"), "规划/细化章节计划.md"),
(lambda: 规划模板("outline"), "规划/生成作品规划.md"),
(文学模板, "审校/创作质量审阅.md"),
)
def _安装资源(tmp_path, monkeypatch, 名称, 内容, *, 缺文件=False, 错哈希=False):
(tmp_path / "清单.json").write_text(
json.dumps(
{
"发布身份": "test-release",
"资源": {
名称: {"sha256": "0" * 64 if 错哈希 else hashlib.sha256(内容).hexdigest()}
},
}
)
)
with zipfile.ZipFile(tmp_path / "运行资源.zip", "w") as 包:
if not 缺文件:
包.writestr(名称, 内容)
monkeypatch.setattr(资源加载.resources, "files", lambda _: tmp_path)
@pytest.mark.case_id("NC-prompt-package-content-and-hash")
@pytest.mark.parametrize("读取,名称", 模板集, ids=("fine-plan", "work-plan", "literary"))
def test_规划审校无源树从发布包读相同内容与哈希(tmp_path, monkeypatch, 读取, 名称):
内容 = "仅存在于当前发布包的测试提示词。".encode()
_安装资源(tmp_path, monkeypatch, 名称, 内容)
# 包根仅包含 ZIP 与清单;故意拒绝从项目散落 markdown 读取的旧路径。
原读取 = Path.read_text
def 禁止源码(self, *args, **kwargs):
if self.suffix == ".md":
raise AssertionError("提示词不得回退源码文件")
return 原读取(self, *args, **kwargs)
monkeypatch.setattr(Path, "read_text", 禁止源码)
with 使用资源提供器(安装包资源提供器()):
assert 读取() == (内容.decode(), hashlib.sha256(内容).hexdigest())
@pytest.mark.case_id("NC-prompt-package-missing-or-corrupt-rejected")
@pytest.mark.parametrize("读取,名称", 模板集, ids=("fine-plan", "work-plan", "literary"))
@pytest.mark.parametrize("故障", ("missing", "hash"))
def test_发布包模板缺失或篡改不从源码补齐(tmp_path, monkeypatch, 读取, 名称, 故障):
_安装资源(
tmp_path,
monkeypatch,
名称,
b"released content",
缺文件=故障 == "missing",
错哈希=故障 == "hash",
)
with 使用资源提供器(安装包资源提供器()), pytest.raises(资源缺失错误):
读取()
@pytest.mark.case_id("NC-writing-operations-are-runtime-capabilities")
def test_作者写作与候选核对操作登记可读且命令真实(源码资源):
from muse.接入.http.应用 import 导出合同
命令 = {
操作["operationId"]
for 路径 in 导出合同()["paths"].values()
for 操作 in 路径.values()
if isinstance(操作, dict) and "operationId" in 操作
}
with 使用资源提供器(源码资源):
写作 = 读取能力("operation", "write-next-chapter")
核对 = 读取能力("operation", "check-consistency")
assert 写作["commands"] == ["start_writing_task", "read_task", "read_task_events"]
assert 核对["commands"] == ["read_candidate_review_report", "read_task_events"]
assert set(写作["commands"] + 核对["commands"]) <= 命令
assert "创作" in 写作["正文"] and "报告" in 核对["正文"]