mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 01:50:44 +08:00
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。 Made-with: Cursor
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from types import SimpleNamespace
|
|
|
|
from oclaw.runtime.skill_executor import SkillExecutionContext, SkillExecutor
|
|
from oclaw.runtime.tools.base import ToolRegistry, ToolSpec
|
|
|
|
|
|
class _DummyStore:
|
|
def __init__(self) -> None:
|
|
self.events: list[dict] = []
|
|
self.logs: list[dict] = []
|
|
self.messages: list[dict] = []
|
|
|
|
def add_trace_event(self, **kwargs): # noqa: ANN003
|
|
self.events.append(dict(kwargs))
|
|
|
|
def add_tool_log(self, **kwargs): # noqa: ANN003
|
|
self.logs.append(dict(kwargs))
|
|
|
|
def add_message(self, **kwargs): # noqa: ANN003
|
|
self.messages.append(dict(kwargs))
|
|
return SimpleNamespace(id=len(self.messages))
|
|
|
|
|
|
def test_skill_executor_emits_skill_trace_events() -> None:
|
|
store = _DummyStore()
|
|
reg = ToolRegistry(
|
|
[
|
|
ToolSpec(
|
|
name="echo_skill",
|
|
description="echo",
|
|
parameters={"type": "object", "properties": {"x": {"type": "string"}}},
|
|
handler=lambda a: {"ok": True, "x": a.get("x")},
|
|
read_only=True,
|
|
)
|
|
]
|
|
)
|
|
ex = SkillExecutor()
|
|
uses = [SimpleNamespace(id="call_1", name="echo_skill", arguments={"x": "1"})]
|
|
ex.execute_skill_uses(
|
|
ctx=SkillExecutionContext(store=store, tools=reg, session_id="s1", trace_id="t1"),
|
|
assistant_msg_id=1,
|
|
skill_uses=uses,
|
|
)
|
|
et = [str((e.get("event_type") or "")) for e in store.events]
|
|
assert "skill_selected" in et
|
|
assert "skill_executed" in et
|
|
|