65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
||
|
||
import sys
|
||
import unittest
|
||
from pathlib import Path
|
||
|
||
|
||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||
SDK_SRC = PROJECT_ROOT / "packages" / "jwebot-sdk" / "src"
|
||
KERNEL_SRC = PROJECT_ROOT / "packages" / "jwebot-kernel" / "src"
|
||
sys.path[:0] = [str(SDK_SRC), str(KERNEL_SRC)]
|
||
|
||
from jwebot_kernel import ( # noqa: E402
|
||
ExecutionPath,
|
||
RouteKind,
|
||
classify_question,
|
||
parse_local_command,
|
||
)
|
||
|
||
|
||
ALIASES = {
|
||
"功能列表": "feature_list",
|
||
"丢骰子": "dice",
|
||
"丢骰子挑战": "dice_challenge",
|
||
"steam": "steam_friends",
|
||
}
|
||
|
||
|
||
class KernelRoutingTests(unittest.TestCase):
|
||
def test_longest_command_prefix_wins(self):
|
||
self.assertEqual(
|
||
parse_local_command("/丢骰子挑战5d20", ALIASES),
|
||
("dice_challenge", "5d20"),
|
||
)
|
||
|
||
def test_unknown_slash_command_stays_local(self):
|
||
decision = classify_question("/unknown", ALIASES)
|
||
self.assertEqual(decision.route, RouteKind.LOCAL)
|
||
self.assertEqual(
|
||
decision.execution_path,
|
||
ExecutionPath.LOCAL_COMMAND,
|
||
)
|
||
self.assertEqual(decision.reason, "local_unknown")
|
||
|
||
def test_hash_request_routes_to_cloud(self):
|
||
decision = classify_question("#status", ALIASES)
|
||
self.assertEqual(decision.route, RouteKind.CLOUD)
|
||
self.assertEqual(decision.execution_path, ExecutionPath.OPENCLAW)
|
||
self.assertEqual(decision.reason, "hash_command")
|
||
|
||
def test_ordinary_chat_routes_direct(self):
|
||
decision = classify_question("hello", ALIASES)
|
||
self.assertEqual(decision.route, RouteKind.CHAT)
|
||
self.assertEqual(decision.execution_path, ExecutionPath.DEEPSEEK)
|
||
self.assertEqual(decision.reason, "direct_chat")
|
||
|
||
def test_command_arguments_are_preserved(self):
|
||
decision = classify_question("/steam 在线", ALIASES)
|
||
self.assertEqual(decision.command_kind, "steam_friends")
|
||
self.assertEqual(decision.arguments, "在线")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|