muse-agent-example/tests/adapters/test_host_adapter_consistency.py

66 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Pi / DSH / Claude 适配器都只消费 FrameworkExecutionRequest,形状一致。"""
from __future__ import annotations
import pathlib
import sys
import tempfile
import unittest
ROOT = next(
parent
for parent in (pathlib.Path(__file__).resolve().parent, *pathlib.Path(__file__).resolve().parents)
if (parent / "AGENTS.md").is_file() and (parent / ".git").exists()
)
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from framework.adapters.claude.runner import ClaudeExecutionPolicy, build_claude_argv # noqa: E402
from framework.adapters.dsh.runner import DshExecutionPolicy, build_dsh_argv # noqa: E402
from framework.adapters.pi.runner import ExecutionPolicy, build_pi_argv # noqa: E402
from framework.primitives.execution import FrameworkExecutionRequest # noqa: E402
class HostAdapterConsistencyTest(unittest.TestCase):
def setUp(self) -> None:
self.request = FrameworkExecutionRequest(
system_prompt="你是写手",
user_content="写一节",
)
def test_three_hosts_build_argv_from_the_same_request(self) -> None:
pi = build_pi_argv(
self.request,
ExecutionPolicy(provider="p", model="claude-opus-test"),
)
dsh = build_dsh_argv(
self.request,
DshExecutionPolicy(provider="p", model="deepseek-chat"),
patch_path="/tmp/dsh.patch",
)
claude = build_claude_argv(
self.request,
ClaudeExecutionPolicy(provider="anthropic", model="claude-opus-test"),
)
self.assertEqual(pi[0], "pi")
self.assertEqual(dsh[0], "dsh")
self.assertEqual(claude[0], "claude")
self.assertIn("你是写手", pi)
self.assertIn("写一节", claude)
def test_adapters_do_not_import_muse_business(self) -> None:
for rel in (
"framework/adapters/pi/runner.py",
"framework/adapters/dsh/runner.py",
"framework/adapters/claude/runner.py",
):
text = (ROOT / rel).read_text(encoding="utf-8")
self.assertNotIn("muse_role", text)
self.assertNotIn("agent_trace", text)
self.assertNotIn("muse_db", text)
if __name__ == "__main__":
unittest.main()