oclaw/tests/test_oclaw_dynamic_expert.py
oliver 420abac9f1 refactor: root-package imports (svc/runtime/interfaces) and fix PYTHONPATH
- Rename platform/ to svc/ to avoid shadowing stdlib platform.
- Replace from oclaw.* with from svc/runtime/interfaces; update -m CLI paths.
- tests/conftest: prepend repo root to sys.path (no parent-folder package name).
- CI: paths and offline_eval script under repo root.
- Ops scripts: PYTHONPATH must be repo root for python -m runtime.* (fixes gateway/WhatsApp sidecar startup).
- Fix default oclaw.json path in tabular/file attachment limits; stabilize attachment test config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 14:51:17 +08:00

38 lines
1.1 KiB
Python

from __future__ import annotations
from runtime.tools.base import ToolSpec
from 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"]