实现侧: - 上下文:任务范围拆分为 范围校验/范围授权;索引按可发现口径重建、索引新鲜度改对称差;依赖校验统一快照漂移说明。 - 知识方法:方法与材料读取口径统一;超限方法材料按可选省略,核对路径不再二次计费;删除无合同的读时重算。 - 任务运行:新增 context.usage/tool.denied 事件类型;连接池常驻并在装配生命周期内开关;调用结算与核对分列。 - 效果评测/审校修订/交付连载/作者经验/作品规划:凭据冻结、标定消费、导出补证、事实引文核对等收尾修复。 - 资源加载:能力正文不再夹带索引用的导航注记(该注记此前进入角色与技能的模型提示)。 - 元数据:受保护骨架与代码保护属性对齐;字段校验与内置结构口径同步。 - 基础设施:环境预检进入装配生命周期;数据库连接运行期字段不参与相等比较;索引指纹归一化 jsonb 浮点。 - 删除被替代实现:7 份旧提示词模板与空壳 资料来源 读取器。 用例侧: - 用例身份与导航元信息迁移;夹具补生命周期、同库暴露与模板封存; - 本轮定向修复:方法材料省略、事实引文、迁移回执、额度与暂停用例、慢用例超时预算等。
108 lines
4.0 KiB
Python
108 lines
4.0 KiB
Python
"""维护入口使用同一owner,只有明确盘点范围可进入缓存候选。"""
|
||
|
||
import json
|
||
from contextlib import contextmanager
|
||
from types import SimpleNamespace
|
||
|
||
import pytest
|
||
|
||
from muse.共享.错误 import 配置错误
|
||
from muse.接入.cli.回收命令 import _缓存保护, 运行回收命令
|
||
|
||
|
||
@pytest.mark.case_id("NC-retention-cli-raw-owner")
|
||
def test_原文预览和具名执行传递配置作者与原请求(tmp_path):
|
||
调用 = []
|
||
原文 = SimpleNamespace(
|
||
发现到期清理候选=lambda actor, **args: 调用.append((actor, args)) or {"items": []},
|
||
执行到期清理=lambda actor, plan: 调用.append((actor, plan)) or {"receipt_id": "r"},
|
||
)
|
||
装配 = SimpleNamespace(
|
||
配置=SimpleNamespace(HTTP=SimpleNamespace(作者ID="configured-author")),
|
||
要求原文=lambda: 原文,
|
||
)
|
||
request = tmp_path / "request.json"
|
||
request.write_text(json.dumps({"as_of": "2026-09-17T00:00:00+00:00", "limit": 3}))
|
||
assert 运行回收命令(装配, "原文回收预览", str(request)) == {"items": []}
|
||
assert 调用[0][0] == "configured-author" and 调用[0][1]["上限"] == 3
|
||
plan = {"lease_id": "known-lease"}
|
||
request.write_text(json.dumps(plan))
|
||
assert 运行回收命令(装配, "原文回收执行", str(request)) == {"receipt_id": "r"}
|
||
assert 调用[1] == ("configured-author", plan)
|
||
|
||
|
||
@pytest.mark.case_id("NC-retention-cli-root-boundary")
|
||
def test_发布缓存不得包含或复用备份根(tmp_path):
|
||
request = tmp_path / "request.json"
|
||
request.write_text(
|
||
json.dumps(
|
||
{"cache_root": str(tmp_path), "reference_inventory": str(tmp_path / "inventory")}
|
||
)
|
||
)
|
||
配置 = SimpleNamespace(
|
||
HTTP=None, 原文暂存=None, 探索草稿=None, 备份目录=str(tmp_path / "backup")
|
||
)
|
||
with pytest.raises(配置错误, match="不能包含"):
|
||
运行回收命令(SimpleNamespace(配置=配置), "发布缓存预览", str(request))
|
||
|
||
|
||
@pytest.mark.case_id("NC-retention-cli-authoritative-references")
|
||
def test_声明盘点仍合入实际两用途任务与当前构建(tmp_path, monkeypatch):
|
||
记录 = []
|
||
|
||
class 连接:
|
||
def __enter__(self):
|
||
return self
|
||
|
||
def __exit__(self, *args):
|
||
pass
|
||
|
||
@contextmanager
|
||
def transaction(self):
|
||
yield
|
||
|
||
def execute(self, query):
|
||
text = query.as_string() if hasattr(query, "as_string") else query
|
||
记录.append(text)
|
||
if "evaluation" in text:
|
||
rows = [("evaluation-in-use",)]
|
||
else:
|
||
rows = [("production-in-use",)]
|
||
return SimpleNamespace(fetchall=lambda: rows)
|
||
|
||
from muse.共享.调用身份 import 用途
|
||
from muse.接入.cli import 回收命令 as 命令模块
|
||
|
||
monkeypatch.setattr(
|
||
命令模块, "数据库工厂", lambda *a: SimpleNamespace(用途=用途.维护, 连接=连接)
|
||
)
|
||
配置 = SimpleNamespace(
|
||
资源发布身份="current-build", 备份目录=None, 数据库=None, 运行用途=用途.维护
|
||
)
|
||
装配 = SimpleNamespace(配置=配置, 要求数据库=lambda: SimpleNamespace(连接=连接))
|
||
request = tmp_path / "inventory.json"
|
||
request.write_text(
|
||
json.dumps(
|
||
{
|
||
"scope": str(tmp_path),
|
||
"complete": True,
|
||
"running_build_ids": ["another-process"],
|
||
"backup_build_ids": ["backup-needed"],
|
||
}
|
||
)
|
||
)
|
||
with _缓存保护(装配, request, tmp_path, 执行=True) as protection:
|
||
assert protection["complete"] is True
|
||
assert protection["build_ids"] == [
|
||
"another-process",
|
||
"backup-needed",
|
||
"current-build",
|
||
"evaluation-in-use",
|
||
"production-in-use",
|
||
]
|
||
assert sum("LOCK TABLE" in text for text in 记录) == 2
|
||
记录.clear()
|
||
with _缓存保护(装配, request, tmp_path, 执行=False):
|
||
pass
|
||
assert not any("LOCK TABLE" in text for text in 记录)
|