diff --git a/src/providers/store_test/store.py b/src/providers/store_test/store.py index 27a57ab2..b086cded 100644 --- a/src/providers/store_test/store.py +++ b/src/providers/store_test/store.py @@ -315,34 +315,55 @@ async def sync_store(self): 以商店数据为准,更新商店数据到仓库中,如果仓库中不存在则获取用户名后存储 """ for key in self._store_adapters: - if key in self._previous_adapters: - self._previous_adapters[key] = self._previous_adapters[key].update( - self._store_adapters[key] - ) - else: - self._previous_adapters[key] = self._store_adapters[key].to_registry() + try: + if key in self._previous_adapters: + new_adapter = self._previous_adapters[key].update( + self._store_adapters[key] + ) + else: + new_adapter = self._store_adapters[key].to_registry() + except Exception as e: + logger.error(f"适配器 {key} 同步商店数据失败:{e}") + continue + self._previous_adapters[key] = new_adapter for key in self._store_bots: - if key in self._previous_bots: - self._previous_bots[key] = self._previous_bots[key].update( - self._store_bots[key] - ) - else: - self._previous_bots[key] = self._store_bots[key].to_registry() + try: + if key in self._previous_bots: + new_bot = self._previous_bots[key].update(self._store_bots[key]) + else: + new_bot = self._store_bots[key].to_registry() + except Exception as e: + logger.error(f"机器人 {key} 同步商店数据失败:{e}") + continue + + self._previous_bots[key] = new_bot for key in self._store_drivers: - if key in self._previous_drivers: - self._previous_drivers[key] = self._previous_drivers[key].update( - self._store_drivers[key] - ) - else: - self._previous_drivers[key] = self._store_drivers[key].to_registry() + try: + if key in self._previous_drivers: + new_driver = self._previous_drivers[key].update( + self._store_drivers[key] + ) + else: + new_driver = self._store_drivers[key].to_registry() + except Exception as e: + logger.error(f"驱动器 {key} 同步商店数据失败:{e}") + continue + + self._previous_drivers[key] = new_driver for key in self._store_plugins: - if key in self._previous_plugins: - self._previous_plugins[key] = self._previous_plugins[key].update( - self._store_plugins[key] - ) - else: - # TODO: 如果插件不存在,尝试重新测试获取相关信息验证 - pass + try: + if key in self._previous_plugins: + new_plugin = self._previous_plugins[key].update( + self._store_plugins[key] + ) + else: + # TODO: 如果插件不存在,尝试重新测试获取相关信息验证 + raise NotImplementedError("插件需要重新测试") + except Exception as e: + logger.error(f"插件 {key} 同步商店数据失败:{e}") + continue + + self._previous_plugins[key] = new_plugin def generate_github_summary(self, results: dict[str, StoreTestResult]): """生成 GitHub 摘要""" diff --git a/tests/providers/store_test/test_store_sync.py b/tests/providers/store_test/test_store_sync.py index 11ea16bd..0b51ee31 100644 --- a/tests/providers/store_test/test_store_sync.py +++ b/tests/providers/store_test/test_store_sync.py @@ -123,7 +123,7 @@ async def test_store_sync( "desc": "NoneBot 数据存储插件", "author": "he0119", "homepage": "https://github.com/he0119/nonebot-plugin-datastore", - "tags": [{"label": "good first plugin", "color": "#ffffff"}], + "tags": [{"label": "sync", "color": "#ffffff"}], "is_official": False, "type": "library", "supported_adapters": None, @@ -332,7 +332,189 @@ async def test_store_sync( "desc": "NoneBot 数据存储插件", "author": "he0119", "homepage": "https://github.com/he0119/nonebot-plugin-datastore", - "tags": [{"label": "good first plugin", "color": "#ffffff"}], + "tags": [{"label": "sync", "color": "#ffffff"}], + "is_official": False, + "type": "library", + "supported_adapters": None, + "valid": True, + "time": "2024-06-20T07:53:23.524486Z", + "version": "1.3.0", + "skip_test": False, + }, + { + "module_name": "nonebot_plugin_treehelp", + "project_link": "nonebot-plugin-treehelp", + "name": "帮助", + "desc": "获取插件帮助信息", + "author": "he0119", + "homepage": "https://github.com/he0119/nonebot-plugin-treehelp", + "tags": [], + "is_official": False, + "type": "application", + "supported_adapters": None, + "valid": True, + "time": "2024-07-13T04:41:40.905441Z", + "version": "0.5.0", + "skip_test": False, + }, + ] + ) + assert load_json(mocked_store_data["results"]) == snapshot( + { + "nonebot-plugin-datastore:nonebot_plugin_datastore": { + "time": "2023-06-26T22:08:18.945584+08:00", + "config": "", + "version": "1.3.0", + "test_env": None, + "results": {"validation": True, "load": True, "metadata": True}, + "outputs": { + "validation": None, + "load": "datastore", + "metadata": { + "name": "数据存储", + "description": "NoneBot 数据存储插件", + "usage": "请参考文档", + "type": "library", + "homepage": "https://github.com/he0119/nonebot-plugin-datastore", + "supported_adapters": None, + }, + }, + }, + "nonebot-plugin-treehelp:nonebot_plugin_treehelp": { + "time": "2023-06-26T22:20:41.833311+08:00", + "config": "", + "version": "0.3.0", + "test_env": None, + "results": {"validation": True, "load": True, "metadata": True}, + "outputs": { + "validation": None, + "load": "treehelp", + "metadata": { + "name": "帮助", + "description": "获取插件帮助信息", + "usage": """\ +获取插件列表 +/help +获取插件树 +/help -t +/help --tree +获取某个插件的帮助 +/help 插件名 +获取某个插件的树 +/help --tree 插件名 +""", + "type": "application", + "homepage": "https://github.com/he0119/nonebot-plugin-treehelp", + "supported_adapters": None, + }, + }, + }, + } + ) + + +async def test_store_sync_validation_failed( + mocked_store_data: dict[str, Path], mocked_api: MockRouter, mocker: MockerFixture +) -> None: + """测试同步商店数据出错的情况 + + 均增加一个 tag,以测试数据是否正确同步 + """ + from src.providers.store_test.store import StoreTest + + mocked_api.get("https://pypi.org/pypi/nonebot2/json", name="pypi_nonebot2").respond( + 404 + ) + + test = StoreTest() + await test.run(0, 0, False) + + assert load_json(mocked_store_data["adapters"]) == snapshot( + [ + { + "module_name": "nonebot.adapters.onebot.v11", + "project_link": "nonebot-adapter-onebot", + "name": "OneBot V11", + "desc": "OneBot V11 协议", + "author": "yanyongyu", + "homepage": "https://onebot.adapters.nonebot.dev/", + "tags": [{"label": "sync", "color": "#ffffff"}], + "is_official": True, + "time": "2024-10-24T07:34:56.115315Z", + "version": "2.4.6", + }, + { + "module_name": "nonebot.adapters.onebot.v12", + "project_link": "nonebot-adapter-onebot", + "name": "OneBot V12", + "desc": "OneBot V12 协议", + "author": "he0119", + "homepage": "https://onebot.adapters.nonebot.dev/", + "tags": [], + "is_official": True, + "time": "2024-10-24T07:34:56.115315Z", + "version": "2.4.6", + }, + ] + ) + assert load_json(mocked_store_data["bots"]) == snapshot( + [ + { + "name": "CoolQBot", + "desc": "基于 NoneBot2 的聊天机器人", + "author": "he0119", + "homepage": "https://github.com/he0119/CoolQBot", + "tags": [{"label": "sync", "color": "#ffffff"}], + "is_official": False, + }, + { + "name": "Github Bot", + "desc": "在QQ获取/处理Github repo/pr/issue", + "author": "BigOrangeQWQ", + "homepage": "https://github.com/cscs181/QQ-GitHub-Bot", + "tags": [], + "is_official": False, + }, + ] + ) + assert load_json(mocked_store_data["drivers"]) == snapshot( + [ + { + "module_name": "~none", + "project_link": "", + "name": "None", + "desc": "None 驱动器", + "author": "yanyongyu", + "homepage": "/docs/advanced/driver", + "tags": [], + "is_official": True, + "time": "2024-10-31T13:47:14.152851Z", + "version": "2.4.0", + }, + { + "module_name": "~fastapi", + "project_link": "nonebot2[fastapi]", + "name": "FastAPI", + "desc": "FastAPI 驱动器", + "author": "yanyongyu", + "homepage": "/docs/advanced/driver", + "tags": [], + "is_official": True, + "time": "2024-10-31T13:47:14.152851Z", + "version": "2.4.0", + }, + ] + ) + assert load_json(mocked_store_data["plugins"]) == snapshot( + [ + { + "module_name": "nonebot_plugin_datastore", + "project_link": "nonebot-plugin-datastore", + "name": "数据存储", + "desc": "NoneBot 数据存储插件", + "author": "he0119", + "homepage": "https://github.com/he0119/nonebot-plugin-datastore", + "tags": [{"label": "sync", "color": "#ffffff"}], "is_official": False, "type": "library", "supported_adapters": None, diff --git a/tests/store/store_plugins.json5 b/tests/store/store_plugins.json5 index dff05ed0..15439ec5 100644 --- a/tests/store/store_plugins.json5 +++ b/tests/store/store_plugins.json5 @@ -6,7 +6,7 @@ "author_id": 1, "tags": [ { - "label": "good first plugin", + "label": "sync", "color": "#ffffff" } ],