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

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

43 lines
1.4 KiB
Python

from __future__ import annotations
import pytest
from oclaw.prompts.loader import load_runtime_prompt_doc, load_prompt_doc, render_runtime_prompt, render_prompt
def test_load_prompt_doc_with_frontmatter() -> None:
doc = load_prompt_doc("runtime/default_system.zh.md")
assert doc.frontmatter.get("title") == "default_runtime_system_zh"
assert "你是一个通用 AI 助手" in doc.body
def test_render_prompt_strict_missing_variable_raises() -> None:
with pytest.raises(ValueError):
render_prompt("tools/tool_result_unpaired.md", variables={"tag": "x"}, strict=True)
def test_render_prompt_success() -> None:
out = render_prompt(
"tools/tool_result_unpaired.md",
variables={"tag": "tool_use_result:unpaired", "payload": "ok=true"},
strict=True,
)
assert "[tool_use_result:unpaired]" in out
assert "ok=true" in out
def test_load_runtime_prompt_doc_with_frontmatter() -> None:
doc = load_runtime_prompt_doc("roles/specialists/ops/system.md")
assert doc.frontmatter.get("title") == "oclaw_role_specialist_ops_system"
assert "你是网络运维专家" in doc.body
def test_render_runtime_prompt_success() -> None:
out = render_runtime_prompt(
"runtime/project_context_block.md",
variables={"project_context": "[AGENTS.md]\nfoo"},
strict=True,
)
assert "[project_context]" in out
assert "[AGENTS.md]" in out