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

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

84 lines
3.2 KiB
Python

"""工程工具拒绝越界输入,并在写产物前完成整批检查。"""
import json
from pathlib import Path
import pytest
import 构建资源包
import 生成接口
import 维护索引
@pytest.mark.case_id("NC-O04-index-prunes-before-descent")
def test_忽略目录在进入前剪枝(tmp_path, monkeypatch):
for name in ["docs", ".venv/深层", "web/node_modules/深层"]:
directory = tmp_path / name
directory.mkdir(parents=True)
(directory / "目录.md").write_text("synthetic")
visited = []
original = 维护索引.os.walk
def walk(*args, **kwargs):
for entry in original(*args, **kwargs):
visited.append(Path(entry[0]).relative_to(tmp_path).as_posix())
yield entry
monkeypatch.setattr(维护索引.os, "walk", walk)
assert list(维护索引.遍历文件(tmp_path, "目录.md")) == [tmp_path / "docs/目录.md"]
assert not any(".venv" in p or "node_modules" in p for p in visited)
@pytest.mark.case_id("NC-O04-openapi-preflight-before-factory")
@pytest.mark.parametrize(
"bad", ["../outside.json", "/absolute.json", "web"], ids=["parent", "absolute", "directory"]
)
def test_整批输出拒绝发生在导入与写入前(tmp_path, monkeypatch, bad):
(tmp_path / "web").mkdir()
monkeypatch.setattr(生成接口, "仓库根", tmp_path)
calls = []
monkeypatch.setattr(生成接口.importlib, "import_module", lambda name: calls.append(name))
items = [
{"格式": "OpenAPI", "工厂": "synthetic:factory", "输出": "good.json"},
{"格式": "OpenAPI", "工厂": "synthetic:factory", "输出": bad},
]
with pytest.raises(生成接口.生成错误):
生成接口.生成接口({"schema_version": 1, "资源": items})
assert calls == []
assert not (tmp_path / "good.json").exists()
assert list((tmp_path / "web").iterdir()) == []
@pytest.mark.case_id("NC-O04-resource-collision-preserves-output")
def test_迁移投影与直接资源重名在写前拒绝(tmp_path, monkeypatch):
tools = tmp_path / "工具"
tools.mkdir()
migration = tmp_path / "数据库/迁移"
migration.mkdir(parents=True)
(migration / "V0001__synthetic.sql").write_text("SELECT 1;")
resources = tmp_path / "src/muse/资源"
resources.mkdir(parents=True)
(resources / "清单.json").write_text("previous-release")
entry = tools / "资源登记.json"
entry.write_text(
json.dumps(
{
"发布身份": "synthetic",
"迁移目录": "数据库/迁移",
"资源": [
{
"源路径": "数据库/迁移/V0001__synthetic.sql",
"打包路径": "迁移/V0001__synthetic.sql",
}
],
}
)
)
monkeypatch.setattr(构建资源包, "仓库根", tmp_path)
monkeypatch.setattr(构建资源包, "登记文件", entry)
monkeypatch.setattr(构建资源包, "资源目录", resources)
with pytest.raises(ValueError, match="重复"):
构建资源包.打包()
assert (resources / "清单.json").read_text() == "previous-release"
assert list(resources.iterdir()) == [resources / "清单.json"]