实现侧: - 上下文:任务范围拆分为 范围校验/范围授权;索引按可发现口径重建、索引新鲜度改对称差;依赖校验统一快照漂移说明。 - 知识方法:方法与材料读取口径统一;超限方法材料按可选省略,核对路径不再二次计费;删除无合同的读时重算。 - 任务运行:新增 context.usage/tool.denied 事件类型;连接池常驻并在装配生命周期内开关;调用结算与核对分列。 - 效果评测/审校修订/交付连载/作者经验/作品规划:凭据冻结、标定消费、导出补证、事实引文核对等收尾修复。 - 资源加载:能力正文不再夹带索引用的导航注记(该注记此前进入角色与技能的模型提示)。 - 元数据:受保护骨架与代码保护属性对齐;字段校验与内置结构口径同步。 - 基础设施:环境预检进入装配生命周期;数据库连接运行期字段不参与相等比较;索引指纹归一化 jsonb 浮点。 - 删除被替代实现:7 份旧提示词模板与空壳 资料来源 读取器。 用例侧: - 用例身份与导航元信息迁移;夹具补生命周期、同库暴露与模板封存; - 本轮定向修复:方法材料省略、事实引文、迁移回执、额度与暂停用例、慢用例超时预算等。
281 lines
11 KiB
Python
281 lines
11 KiB
Python
"""旧载荷形状、端点身份和来源声明的纯合同;不运行旧确认实现。"""
|
||
|
||
from copy import deepcopy
|
||
|
||
import pytest
|
||
|
||
from 建立映射 import 旧快照, 映射配置
|
||
from 知识记录分流 import 分流知识记录
|
||
|
||
|
||
def _输入(载荷=None, *, 关系=False):
|
||
源 = {
|
||
"source": {
|
||
"system": "pg",
|
||
"database": "synthetic-t5",
|
||
"table": "muse_knowledge_draft",
|
||
"id": "1",
|
||
"revision": "1",
|
||
},
|
||
"record": {
|
||
"work_id": 12,
|
||
"source_id": 17473,
|
||
"source_type": "chapter_extract",
|
||
"status": "pending",
|
||
"source_status": "active",
|
||
"source_action_policy": "allowed",
|
||
"draft_type": "relation" if 关系 else "entity",
|
||
"draft_payload": 载荷
|
||
if 载荷 is not None
|
||
else {"type": "character", "name": "林深", "fields": {"身份": "驾驶员"}},
|
||
},
|
||
}
|
||
域 = {"system": "pg", "database": "synthetic-t5"}
|
||
映射 = {
|
||
"works": [
|
||
{
|
||
**域,
|
||
"legacy_id": 12,
|
||
"use": "author",
|
||
"target_ref": "new-work",
|
||
"author_id": "author",
|
||
}
|
||
],
|
||
"sources": [
|
||
{
|
||
**域,
|
||
"legacy_id": 17473,
|
||
"source_type": "chapter_extract",
|
||
"work_id": 12,
|
||
"target_ref": "new-chapter",
|
||
"revision": "1",
|
||
"chapters": {"1": "chapter:new-chapter"},
|
||
}
|
||
],
|
||
"objects": [
|
||
{
|
||
**域,
|
||
"work_id": 12,
|
||
"use": "author",
|
||
"scope": "new-work",
|
||
"refs": refs,
|
||
"target_ref": id_,
|
||
}
|
||
for refs, id_ in (
|
||
(["name:林深", "name:11"], "a"),
|
||
(["entity:11"], "b"),
|
||
(["entity:12", "name:茧"], "c"),
|
||
)
|
||
],
|
||
"schemas": {
|
||
"character": {
|
||
"type": "object",
|
||
"properties": {"身份": {"type": "string"}},
|
||
"additionalProperties": False,
|
||
},
|
||
"character_relation": {
|
||
"type": "object",
|
||
"properties": {},
|
||
"additionalProperties": False,
|
||
},
|
||
},
|
||
}
|
||
return 源, 映射
|
||
|
||
|
||
def _分流(源, 映射):
|
||
快照 = 旧快照.从载荷(源)
|
||
结果 = 分流知识记录(快照, 映射配置(映射))
|
||
assert 结果.original == 快照.导出()
|
||
return 结果
|
||
|
||
|
||
@pytest.mark.case_id(
|
||
"NC-w21-210001",
|
||
environment="默认离线合成载荷",
|
||
given="描述/字段/证据别名同值及异值",
|
||
when="按新旧载荷合同经真实分流或隔离目标入口执行并回查",
|
||
then=["同值归一,冲突field_conflict且原两值保全"],
|
||
contract="docs/系统架构/新版设计/数据模型/旧知识记录分流.md",
|
||
)
|
||
@pytest.mark.parametrize(
|
||
"键,别名,值",
|
||
[
|
||
("brief", "description", "机师"),
|
||
("description", "描述", "机师"),
|
||
("fields", "attributes", {"身份": "驾驶员"}),
|
||
("fields", "字段", {"身份": "驾驶员"}),
|
||
("evidence", "证据", "证据句"),
|
||
],
|
||
)
|
||
def test_载荷别名同值承接冲突不吞原值__210001(键, 别名, 值):
|
||
源, 映射 = _输入()
|
||
载荷 = 源["record"]["draft_payload"]
|
||
载荷.update({键: 值, 别名: deepcopy(值)})
|
||
assert _分流(源, 映射).disposition == "待转换"
|
||
载荷[别名] = {"身份": "异值"} if isinstance(值, dict) else "异值"
|
||
assert _分流(源, 映射).reason_code == "field_conflict"
|
||
|
||
|
||
@pytest.mark.case_id(
|
||
"NC-w21-210002",
|
||
environment="默认离线合成载荷",
|
||
given="关系source为None/bool/数组/空对象/未知键/空白名/双键冲突",
|
||
when="按新旧载荷合同经真实分流或隔离目标入口执行并回查",
|
||
then=["按具体原因拒绝,detail固定relation.source且不回显原值"],
|
||
contract="docs/系统架构/新版设计/数据模型/旧知识记录分流.md",
|
||
)
|
||
@pytest.mark.parametrize(
|
||
"值,原因",
|
||
[
|
||
(None, "field_type_mismatch"),
|
||
(True, "field_type_mismatch"),
|
||
([], "field_type_mismatch"),
|
||
({}, "missing_endpoint"),
|
||
({"id": 11}, "unknown_fields"),
|
||
({"name": " "}, "field_type_mismatch"),
|
||
({"name": "林深", "名称": "异名"}, "field_conflict"),
|
||
(" ", "field_type_mismatch"),
|
||
],
|
||
)
|
||
def test_端点坏形状保全且错误固定到侧__210002(值, 原因):
|
||
源, 映射 = _输入(
|
||
{"type": "驾驶", "source": 值, "target": {"name": "茧"}, "description": "不应出现在错误中"},
|
||
关系=True,
|
||
)
|
||
结果 = _分流(源, 映射)
|
||
assert 结果.disposition == "隔离" and 结果.reason_code == 原因
|
||
assert 结果.detail == "relation.source"
|
||
|
||
|
||
@pytest.mark.case_id(
|
||
"NC-w21-210003",
|
||
environment="默认离线合成载荷",
|
||
given="数字字符串、整数及首尾空白名称对象;另给矛盾强ID",
|
||
when="按新旧载荷合同经真实分流或隔离目标入口执行并回查",
|
||
then=["明确name/entity分轨,匹配名strip而原值不改,多提示冲突拒绝"],
|
||
contract="docs/系统架构/新版设计/数据模型/旧知识记录分流.md",
|
||
)
|
||
@pytest.mark.parametrize(
|
||
"源值,目标", [("11", "a"), (11, "b"), ({"name": " 林深 ", "名称": " 林深 "}, "a")]
|
||
)
|
||
def test_名称引用不猜数字身份且全提示必须一致__210003(源值, 目标):
|
||
源, 映射 = _输入(
|
||
{"type": "驾驶", "source": 源值, "target": "茧", "description": "首次实战驾驶"}, 关系=True
|
||
)
|
||
结果 = _分流(源, 映射)
|
||
assert 结果.disposition == "待转换" and 结果.content["source"] == 目标
|
||
assert 结果.content["target"] == "c" and 结果.content["brief"] == "首次实战驾驶"
|
||
if 目标 == "a":
|
||
源["record"]["source_entity_id"] = 11
|
||
冲突 = _分流(源, 映射)
|
||
assert 冲突.reason_code == "endpoint_conflict" and 冲突.detail == "relation.source"
|
||
|
||
|
||
@pytest.mark.case_id(
|
||
"NC-w21-210004",
|
||
environment="默认离线合成载荷",
|
||
given="输入source_hint、未知来源键、布尔旧章、reference用途对象、来源别名冲突、非对象attributes",
|
||
when="按新旧载荷合同经真实分流或隔离目标入口执行并回查",
|
||
then=["拒未知/非法形状或用途,不容纳垃圾字段或包sourcePayload"],
|
||
contract="docs/系统架构/新版设计/数据模型/旧知识记录分流.md",
|
||
)
|
||
@pytest.mark.parametrize(
|
||
"改动,原因",
|
||
[
|
||
("hint输入", "unknown_fields"),
|
||
("未知来源键", "unknown_fields"),
|
||
("来源bool", "field_type_mismatch"),
|
||
("其他用途", "unknown_source"),
|
||
("来源冲突", "field_conflict"),
|
||
("属性非对象", "field_type_mismatch"),
|
||
],
|
||
)
|
||
def test_来源提示不容纳未知字段或扩展授权__210004(改动, 原因):
|
||
源, 映射 = _输入()
|
||
载荷 = 源["record"]["draft_payload"]
|
||
载荷["source"] = {"workId": 12, "chapterId": 17473, "chapter": 1}
|
||
if 改动 == "hint输入":
|
||
载荷["source_hint"] = {}
|
||
elif 改动 == "未知来源键":
|
||
载荷["source"]["unknown"] = 1
|
||
elif 改动 == "来源bool":
|
||
载荷["source"]["chapterId"] = True
|
||
elif 改动 == "其他用途":
|
||
映射["works"][0]["use"] = "reference"
|
||
elif 改动 == "来源冲突":
|
||
载荷["出处"] = {"workId": 13}
|
||
else:
|
||
载荷.pop("fields")
|
||
载荷["attributes"] = "不能包成sourcePayload"
|
||
assert _分流(源, 映射).reason_code == 原因
|
||
|
||
|
||
@pytest.mark.case_id(
|
||
"NC-w21-210005",
|
||
environment="默认离线合成载荷",
|
||
given="chapter与章序同值/异值/布尔,或来源缺章定位",
|
||
when="按新旧载荷合同经真实分流或隔离目标入口执行并回查",
|
||
then=["明确一致章驱动locator,scope_conflict/field_type_mismatch/missing_location准确"],
|
||
contract="docs/系统架构/新版设计/数据模型/旧知识记录分流.md",
|
||
)
|
||
@pytest.mark.parametrize(
|
||
"章序,有定位,原因",
|
||
[
|
||
("1", True, "classified"),
|
||
(2, True, "scope_conflict"),
|
||
(True, True, "field_type_mismatch"),
|
||
(1, False, "missing_location"),
|
||
],
|
||
)
|
||
def test_章序只取明确一致声明且不能猜定位__210005(章序, 有定位, 原因):
|
||
源, 映射 = _输入()
|
||
载荷 = 源["record"]["draft_payload"]
|
||
载荷.update(source={"workId": 12, "chapterId": 17473, "chapter": 1}, 章序=章序)
|
||
if not 有定位:
|
||
映射["sources"][0].pop("chapters")
|
||
结果 = _分流(源, 映射)
|
||
assert 结果.reason_code == 原因
|
||
if 原因 == "classified":
|
||
assert 结果.references[0]["locator"] == "chapter:new-chapter"
|
||
assert 结果.content["source_hint"] == 载荷["source"]
|
||
|
||
|
||
@pytest.mark.case_id(
|
||
"NC-w21-210006",
|
||
environment="默认离线合成载荷",
|
||
given="evidence为None/空串/空格/bool/整数",
|
||
when="按新旧载荷合同经真实分流或隔离目标入口执行并回查",
|
||
then=["原码点保留或明确拒绝,空白不strip成空证据"],
|
||
contract="docs/系统架构/新版设计/数据模型/旧知识记录分流.md",
|
||
)
|
||
@pytest.mark.parametrize("证据", [None, "", " ", True, 12])
|
||
def test_证据只保原码点而不宽松转型__210006(证据):
|
||
源, 映射 = _输入()
|
||
源["record"]["draft_payload"]["evidence"] = 证据
|
||
结果 = _分流(源, 映射)
|
||
if 证据 is None or isinstance(证据, str):
|
||
assert 结果.disposition == "待转换" and 结果.content["source_hint"]["evidence"] == 证据
|
||
else:
|
||
assert 结果.reason_code == "field_type_mismatch"
|
||
|
||
|
||
@pytest.mark.case_id(
|
||
"NC-w21-210007",
|
||
environment="默认离线合成载荷",
|
||
given="甲方/乙方动态字段的bool/数组/空对象端点",
|
||
when="按新旧载荷合同经真实分流或隔离目标入口执行并回查",
|
||
then=[
|
||
"同一端点解析器先于结构校验,field_type_mismatch固定到source/target侧,不被通用字段错误遮蔽"
|
||
],
|
||
contract="docs/系统架构/新版设计/数据模型/旧知识记录分流.md",
|
||
)
|
||
@pytest.mark.parametrize("边", ["甲方", "乙方"])
|
||
@pytest.mark.parametrize("值", [True, ["不得出现在错误中的旧原值"], {}])
|
||
def test_关系字段坏端点不被动态结构错误遮蔽__210007(边, 值):
|
||
源, 映射 = _输入({"type": "驾驶", "source": 11, "target": 12, "fields": {边: 值}}, 关系=True)
|
||
映射["schemas"]["character_relation"]["properties"] = {边: {"type": "string"}}
|
||
结果 = _分流(源, 映射)
|
||
assert 结果.reason_code == "field_type_mismatch"
|
||
assert 结果.detail == ("relation.source" if 边 == "甲方" else "relation.target")
|