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

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

42 lines
1.5 KiB
Python

from __future__ import annotations
from unittest.mock import patch
from oclaw.runtime.tools.base import ToolSpec
from oclaw.runtime.tools.catalog import materialize_tool_specs
def _mk_spec(name: str) -> ToolSpec:
return ToolSpec(
name=name,
description="d",
parameters={"type": "object", "properties": {}},
handler=lambda _args: {"ok": True},
tags=frozenset({"internal"}),
)
def test_catalog_loads_role_scoped_expert_tools() -> None:
with patch(
"oclaw.runtime.tools.catalog.materialize_tools_for_expert",
return_value=[_mk_spec("custom_tool_a"), _mk_spec("custom_tool_b")],
):
with patch("oclaw.runtime.tools.catalog.materialize_public_tools", return_value=[_mk_spec("system_time")]):
specs = materialize_tool_specs(expert="generalist")
names = {x.name for x in specs}
assert "system_time" in names
assert "custom_tool_a" in names
assert "custom_tool_b" in names
def test_catalog_deduplicates_same_tool_name() -> None:
with patch(
"oclaw.runtime.tools.catalog.materialize_tools_for_expert",
return_value=[_mk_spec("system_time"), _mk_spec("custom_tool_a")],
):
with patch("oclaw.runtime.tools.catalog.materialize_public_tools", return_value=[_mk_spec("system_time")]):
specs = materialize_tool_specs(expert="generalist")
names = [x.name for x in specs]
assert names.count("system_time") == 1
assert "custom_tool_a" in set(names)