146 lines
3.7 KiB
Python
146 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
OpenCLI Integration 测试脚本
|
|
"""
|
|
|
|
import sys
|
|
sys.path.insert(0, '/home/ubuntu/.nanobot/workspace/skills/opencli-integration')
|
|
|
|
from opencli_adapter import OpenCLIAdapter
|
|
|
|
|
|
def test_status():
|
|
"""测试状态检查"""
|
|
print("=" * 60)
|
|
print("测试1: 状态检查")
|
|
print("=" * 60)
|
|
|
|
try:
|
|
adapter = OpenCLIAdapter()
|
|
status = adapter.is_ready()
|
|
|
|
print(f"OpenCLI安装: {'✅' if status['opencli_installed'] else '❌'}")
|
|
print(f"Node版本: {status['node_version'] or '❌ 未安装'}")
|
|
print(f"Chrome运行: {'✅' if status['chrome_running'] else '❌'}")
|
|
print(f"CLIs目录: {'✅' if status['clis_dir_exists'] else '❌'}")
|
|
print(f"整体就绪: {'✅' if status['ready'] else '❌'}")
|
|
|
|
except RuntimeError as e:
|
|
print(f"⚠️ {e}")
|
|
|
|
print()
|
|
|
|
|
|
def test_adapter_info():
|
|
"""测试适配器信息"""
|
|
print("=" * 60)
|
|
print("测试2: 适配器管理")
|
|
print("=" * 60)
|
|
|
|
try:
|
|
adapter = OpenCLIAdapter()
|
|
|
|
# 检查clis目录
|
|
import os
|
|
clis_dir = os.path.expanduser("~/.opencli/clis")
|
|
if os.path.exists(clis_dir):
|
|
adapters = os.listdir(clis_dir)
|
|
print(f"已安装适配器: {len(adapters)}个")
|
|
for a in adapters[:5]: # 只显示前5个
|
|
print(f" - {a}")
|
|
else:
|
|
print("适配器目录不存在")
|
|
|
|
except Exception as e:
|
|
print(f"⚠️ {e}")
|
|
|
|
print()
|
|
|
|
|
|
def test_yaml_adapter():
|
|
"""测试创建YAML适配器"""
|
|
print("=" * 60)
|
|
print("测试3: YAML适配器创建")
|
|
print("=" * 60)
|
|
|
|
try:
|
|
adapter = OpenCLIAdapter()
|
|
|
|
config = {
|
|
"name": "test_site",
|
|
"base_url": "https://example.com",
|
|
"description": "测试适配器",
|
|
"commands": {
|
|
"search": {
|
|
"description": "搜索",
|
|
"params": ["query"]
|
|
}
|
|
}
|
|
}
|
|
|
|
path = adapter.create_yaml_adapter("test_site", config)
|
|
print(f"✅ 适配器创建成功: {path}")
|
|
|
|
# 读取验证
|
|
info = adapter.get_adapter_info("test_site")
|
|
if info:
|
|
print(f"✅ 适配器信息读取成功")
|
|
print(f" 名称: {info.get('name')}")
|
|
print(f" URL: {info.get('base_url')}")
|
|
|
|
# 清理
|
|
adapter.remove_adapter("test_site")
|
|
print("✅ 测试适配器已清理")
|
|
|
|
except Exception as e:
|
|
print(f"⚠️ {e}")
|
|
|
|
print()
|
|
|
|
|
|
def test_list_adapters():
|
|
"""测试列出适配器"""
|
|
print("=" * 60)
|
|
print("测试4: 列出适配器")
|
|
print("=" * 60)
|
|
|
|
try:
|
|
adapter = OpenCLIAdapter()
|
|
adapters = adapter.list()
|
|
|
|
if adapters:
|
|
print(f"发现 {len(adapters)} 个适配器:")
|
|
for a in adapters[:5]:
|
|
print(f" - {a.get('name', 'unknown')}")
|
|
else:
|
|
print("暂无适配器或未安装OpenCLI")
|
|
|
|
except Exception as e:
|
|
print(f"⚠️ {e}")
|
|
|
|
print()
|
|
|
|
|
|
def main():
|
|
"""运行所有测试"""
|
|
print("\n")
|
|
print("╔" + "=" * 58 + "╗")
|
|
print("║" + " " * 12 + "OpenCLI Integration 测试" + " " * 22 + "║")
|
|
print("╚" + "=" * 58 + "╝")
|
|
print("\n")
|
|
|
|
test_status()
|
|
test_adapter_info()
|
|
test_yaml_adapter()
|
|
test_list_adapters()
|
|
|
|
print("=" * 60)
|
|
print("所有测试完成!")
|
|
print("=" * 60)
|
|
print("\n注意: 完整功能测试需要安装OpenCLI和Chrome浏览器")
|
|
print("安装命令: npm install -g @jackwener/opencli")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|