oclaw/tests/test_oclaw_dynamic_expert.py
oliver 4a23b715a2 重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。

Made-with: Cursor
2026-04-25 01:24:23 +08:00

38 lines
1.1 KiB
Python

from __future__ import annotations
from oclaw.runtime.tools.base import ToolSpec
from oclaw.runtime.tools.catalog import _apply_declared_tool_policy
def _tool(name: str, tags: set[str]) -> ToolSpec:
return ToolSpec(
name=name,
description=name,
parameters={"type": "object", "properties": {}},
handler=lambda _args: {"ok": True},
tags=frozenset(tags),
)
def test_declared_tool_policy_filters_by_tags_and_names() -> None:
tools = [
_tool("search_workspace", {"search", "read"}),
_tool("run_command", {"shell", "exec"}),
_tool("read_file", {"read", "fs"}),
]
out = _apply_declared_tool_policy(
tools,
allow_tags=["read"],
allow_tools=["run_command"],
)
names = {t.name for t in out}
assert "search_workspace" in names
assert "read_file" in names
assert "run_command" in names
def test_declared_tool_policy_empty_rules_returns_original() -> None:
tools = [_tool("a", {"x"}), _tool("b", {"y"})]
out = _apply_declared_tool_policy(tools, allow_tags=[], allow_tools=[])
assert [t.name for t in out] == ["a", "b"]