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

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

58 lines
2 KiB
Python

from __future__ import annotations
from pathlib import Path
from oclaw.runtime.skills import build_skill_manifest, discover_workspace_skill_manifests, load_skill_manifest
from oclaw.runtime.tools.base import ToolRegistry, ToolSpec
def test_load_skill_manifest_with_oclaw_metadata(tmp_path: Path) -> None:
d = tmp_path / "skills" / "demo"
d.mkdir(parents=True, exist_ok=True)
(d / "SKILL.md").write_text(
"""---
name: demo
description: demo skill
user-invocable: true
disable-model-invocation: false
metadata: {"oclaw":{"install":[{"id":"i1","kind":"node","package":"foo"}]}}
---
# Demo
""",
encoding="utf-8",
)
m = load_skill_manifest(d)
assert m is not None
assert m.name == "demo"
assert m.description == "demo skill"
assert len(m.install) == 1
assert m.install[0].kind == "node"
def test_discover_workspace_skill_manifests(tmp_path: Path) -> None:
base = tmp_path / "skills"
(base / "a").mkdir(parents=True, exist_ok=True)
(base / "a" / "SKILL.md").write_text("name: a\ndescription: A", encoding="utf-8")
rows = discover_workspace_skill_manifests(base)
assert len(rows) == 1
assert rows[0].name == "a"
def test_skill_manifest_is_deterministic_and_sorted() -> None:
class Store:
def get_setting(self, _k: str) -> str:
return ""
reg = ToolRegistry(
[
ToolSpec(name="z_tool", description="z", parameters={"type": "object"}, handler=lambda _a: {"ok": True}),
ToolSpec(name="a_tool", description="a", parameters={"type": "object"}, handler=lambda _a: {"ok": True}),
]
)
skills1, stats1 = build_skill_manifest(registry=reg, store=Store(), base_url="")
skills2, stats2 = build_skill_manifest(registry=reg, store=Store(), base_url="")
assert [s.name for s in skills1] == ["a_tool", "z_tool"]
assert [s.name for s in skills2] == ["a_tool", "z_tool"]
assert stats1.get("visible_names_preview") == stats2.get("visible_names_preview")