oclaw/tests/test_workspaces_prompt_contract.py
oliver 9d2900db02 完成运行时与启动链路的全面相对路径整改,统一以仓库根为路径基准并移除 oclaw 双层硬编码。
同时补齐路径回归测试与开源自检文档,确保从非仓库 cwd 启动时 workspace 根、配置和 wiki 路径仍稳定可用。

Made-with: Cursor
2026-04-26 09:22:42 +08:00

53 lines
1.8 KiB
Python

from __future__ import annotations
from pathlib import Path
from oclaw.platform.config.paths import PROJECT_ROOT
def _read(path: Path) -> str:
return path.read_text(encoding="utf-8")
def test_main_dynamic_placeholder_only_in_role_system() -> None:
root = (PROJECT_ROOT / "runtime" / "workspaces" / "main").resolve()
role_system = _read(root / "ROLE_SYSTEM.md")
soul = _read(root / "SOUL.md")
assert "{{MANAGER_DYNAMIC_EXPERTS_HINT}}" in role_system
assert "{{" not in soul
for name in ("AGENTS.md", "IDENTITY.md", "USER.md"):
p = root / name
if p.exists():
assert "{{" not in _read(p)
def test_main_hard_routing_rule_only_in_role_system() -> None:
root = (PROJECT_ROOT / "runtime" / "workspaces" / "main").resolve()
role_system = _read(root / "ROLE_SYSTEM.md")
assert "回退 `generalist`" in role_system
for name in ("AGENTS.md", "IDENTITY.md", "USER.md", "SOUL.md"):
p = root / name
if p.exists():
assert "回退 `generalist`" not in _read(p)
def test_every_workspace_has_role_system() -> None:
root = (PROJECT_ROOT / "runtime" / "workspaces").resolve()
for item in root.iterdir():
if not item.is_dir():
continue
if item.name.startswith("__"):
continue
assert (item / "ROLE_SYSTEM.md").exists(), f"missing ROLE_SYSTEM.md for {item.name}"
def test_workspace_legacy_prompt_files_removed() -> None:
root = (PROJECT_ROOT / "runtime" / "workspaces").resolve()
legacy = ("AGENTS.md", "IDENTITY.md", "USER.md")
for item in root.iterdir():
if not item.is_dir():
continue
if item.name.startswith("__"):
continue
for name in legacy:
assert not (item / name).exists(), f"legacy prompt file still exists: {item.name}/{name}"