65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
"""工具范围的独立协议测试;合成读取器不代表B09真实数据库权限。"""
|
||
|
||
import pytest
|
||
|
||
from muse.任务运行.接口 import (
|
||
只读工具集,
|
||
工具定义,
|
||
工具来源,
|
||
工具结果,
|
||
工具范围,
|
||
工具请求,
|
||
模型协议错误,
|
||
)
|
||
|
||
|
||
def test_工具只能消费冻结范围且返回可追溯版本__a65001() -> None:
|
||
记录 = []
|
||
|
||
def 读取(范围, 条件):
|
||
assert 范围.作品ID == "work-a" and 范围.截止位置 == 3
|
||
assert 条件 == {"query": "桥"}
|
||
return 工具结果("第三章的桥", (工具来源("source-a", "3", "schema1", "projection1"),))
|
||
|
||
定义 = 工具定义(
|
||
"read",
|
||
"读取指定来源",
|
||
{
|
||
"type": "object",
|
||
"properties": {"query": {"type": "string"}},
|
||
"required": ["query"],
|
||
"additionalProperties": False,
|
||
},
|
||
读取,
|
||
)
|
||
集合 = 只读工具集(
|
||
(定义,),
|
||
("read",),
|
||
工具范围("task", "work-a", ("source-a",), 3, "production", "generation"),
|
||
记录.append,
|
||
)
|
||
assert 集合.调用(工具请求("call1", "read", {"query": "桥"})).内容 == "第三章的桥"
|
||
assert 记录[0]["source_refs"][0]["revision"] == "3"
|
||
with pytest.raises(模型协议错误):
|
||
集合.调用(工具请求("call2", "read", {"query": "桥", "work_id": "work-b"}))
|
||
with pytest.raises(模型协议错误):
|
||
集合.调用(工具请求("call3", "write", {"query": "桥"}))
|
||
assert len(记录) == 1
|
||
|
||
|
||
def test_所需工具未加载和越界来源均拒绝__a65002() -> None:
|
||
范围 = 工具范围("task", "work-a", ("source-a",), 3, "production", "generation")
|
||
with pytest.raises(模型协议错误):
|
||
只读工具集((), ("read",), 范围, lambda _: None)
|
||
工具 = 工具定义(
|
||
"read",
|
||
"读取",
|
||
{"type": "object"},
|
||
lambda *_: 工具结果("不应送入模型", (工具来源("source-b", "1", "s", "p"),)),
|
||
)
|
||
记录 = []
|
||
集合 = 只读工具集((工具,), ("read",), 范围, 记录.append)
|
||
with pytest.raises(模型协议错误):
|
||
集合.调用(工具请求("call", "read", {}))
|
||
assert not 记录
|