✨ 跟项目能跑起来就差这一步!这次狠狠修了一波: 🩺 修复40+损坏Python文件 - 补全所有缺少的class定义头(plugin-loader-pro、code-reviewer、 http-api/ws-api/http-tcp、webui/dashboard/log-terminal 等) - 修复中文括号、字符串未闭合、缩进错乱等语法问题 🔗 创建符号链接 plugin_bridge -> plugin-bridge - 解决Python模块路径不支持连字符的问题 - 关联修复 plugin-bridge 中错误的 import 路径 🧹 清理废弃代码 - 删除 oss/tui/ 目录(已废弃) - 清理所有 __pycache__ 和 .pyc 缓存文件 ✅ 全量语法检查通过,零错误! 📋 ai.md 新增代码审计报告和分阶段修复计划 🗺️ 所有插件 use() 调用现在走统一路径
71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
"""Tests for Plugin Manager"""
|
|
|
|
import pytest
|
|
import tempfile
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
from oss.plugin.manager import PluginManager
|
|
from oss.plugin.loader import PluginLoader
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_plugin_dir():
|
|
temp_dir = tempfile.mkdtemp()
|
|
store_dir = Path(temp_dir) / "store"
|
|
store_dir.mkdir()
|
|
plugin_loader_dir = store_dir / "NebulaShell" / "plugin-loader"
|
|
plugin_loader_dir.mkdir(parents=True)
|
|
main_py = plugin_loader_dir / "main.py"
|
|
with open(main_py, 'w') as f:
|
|
f.write("""
|
|
from oss.plugin.types import Plugin
|
|
|
|
class TestPlugin(Plugin):
|
|
def __init__(self):
|
|
self.name = "test-plugin"
|
|
|
|
def init(self):
|
|
pass
|
|
|
|
def start(self):
|
|
pass
|
|
|
|
def stop(self):
|
|
pass
|
|
|
|
def New():
|
|
return TestPlugin()
|
|
""")
|
|
yield temp_dir
|
|
shutil.rmtree(temp_dir)
|
|
|
|
|
|
class TestPluginManager:
|
|
def test_loader_initialization(self, temp_plugin_dir):
|
|
loader = PluginLoader()
|
|
assert loader.loaded == {}
|
|
assert loader._config is not None
|
|
|
|
def test_load_plugin_with_main_py(self, temp_plugin_dir):
|
|
loader = PluginLoader()
|
|
assert loader is not None
|
|
|
|
def test_load_plugin_without_new_function(self):
|
|
loader = PluginLoader()
|
|
temp_dir = tempfile.mkdtemp()
|
|
plugin_dir = Path(temp_dir) / "syntax-error-plugin"
|
|
plugin_dir.mkdir()
|
|
|
|
main_py = plugin_dir / "main.py"
|
|
with open(main_py, 'w') as f:
|
|
f.write("def broken_function(\n")
|
|
|
|
result = loader._load_plugin("syntax-error-plugin", plugin_dir)
|
|
assert result is None
|
|
shutil.rmtree(temp_dir)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
pytest.main([__file__, '-v'])
|