From 3469b2d36d24fc97f944bb5be1d945ee2c6f919d Mon Sep 17 00:00:00 2001 From: uy_sun Date: Wed, 27 Nov 2024 13:45:16 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=E6=8D=95=E8=8E=B7=20docker=20?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 避免运行时报错导致整个机器人炸掉 --- src/providers/docker_test/__init__.py | 34 ++++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/providers/docker_test/__init__.py b/src/providers/docker_test/__init__.py index 3608c410..9731f1af 100644 --- a/src/providers/docker_test/__init__.py +++ b/src/providers/docker_test/__init__.py @@ -72,18 +72,24 @@ async def run(self, version: str) -> DockerTestResult: # 连接 Docker 环境 client = docker.DockerClient(base_url="unix://var/run/docker.sock") - # 运行 Docker 容器,捕获输出。 容器内运行的代码拥有超时设限,此处无需设置超时 - output = client.containers.run( - image_name, - environment={ - "PLUGIN_INFO": self.key, - "PLUGIN_CONFIG": self.config, - # 插件测试需要用到的插件列表来验证插件依赖是否正确加载 - "PLUGINS_URL": REGISTRY_PLUGINS_URL, - }, - detach=False, - remove=True, - ).decode() - - data = json.loads(output) + try: + # 运行 Docker 容器,捕获输出。 容器内运行的代码拥有超时设限,此处无需设置超时 + output = client.containers.run( + image_name, + environment={ + "PLUGIN_INFO": self.key, + "PLUGIN_CONFIG": self.config, + # 插件测试需要用到的插件列表来验证插件依赖是否正确加载 + "PLUGINS_URL": REGISTRY_PLUGINS_URL, + }, + detach=False, + remove=True, + ).decode() + data = json.loads(output) + except Exception as e: + data = { + "run": False, + "load": False, + "outputs": str(e), + } return DockerTestResult(**data) From be2cdef1b21ed92896593a0a1b9a05d973bebeeb Mon Sep 17 00:00:00 2001 From: uy_sun Date: Wed, 27 Nov 2024 13:52:58 +0800 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E5=8F=82=E6=95=B0=E5=92=8C=E6=B5=8B=E8=AF=95=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/providers/docker_test/__init__.py | 3 +- src/providers/docker_test/plugin_test.py | 69 +++++++++---------- .../docker_test/test_docker_plugin_test.py | 9 ++- tests/utils/docker_test/test_plugin_test.py | 8 +-- 4 files changed, 42 insertions(+), 47 deletions(-) diff --git a/src/providers/docker_test/__init__.py b/src/providers/docker_test/__init__.py index 9731f1af..907d3f9e 100644 --- a/src/providers/docker_test/__init__.py +++ b/src/providers/docker_test/__init__.py @@ -77,7 +77,8 @@ async def run(self, version: str) -> DockerTestResult: output = client.containers.run( image_name, environment={ - "PLUGIN_INFO": self.key, + "PROJECT_LINK": self.project_link, + "MODULE_NAME": self.module_name, "PLUGIN_CONFIG": self.config, # 插件测试需要用到的插件列表来验证插件依赖是否正确加载 "PLUGINS_URL": REGISTRY_PLUGINS_URL, diff --git a/src/providers/docker_test/plugin_test.py b/src/providers/docker_test/plugin_test.py index 8213aa06..371f4e81 100644 --- a/src/providers/docker_test/plugin_test.py +++ b/src/providers/docker_test/plugin_test.py @@ -219,27 +219,30 @@ def parse_requirements(requirements: str) -> dict[str, str]: class PluginTest: - def __init__(self, project_info: str, config: str | None = None) -> None: + def __init__( + self, project_link: str, module_name: str, config: str | None = None + ) -> None: """插件测试构造函数 Args: project_info (str): 项目信息,格式为 project_link:module_name config (str | None, optional): 插件配置. 默认为 None. """ - self.project_link = project_info.split(":")[0] - self.module_name = project_info.split(":")[1] + self.project_link = project_link + self.module_name = module_name self.config = config - self._version = None - self._plugin_list = None + self._plugin_list = None + self._test_dir = Path("plugin_test") + # 插件信息 + self._version = None + # 插件测试结果 self._create = False self._run = False - self._deps = [] - + # 插件输出 self._lines_output = [] - - # 插件测试目录 - self._test_dir = Path("plugin_test") + # 插件测试环境 + self._deps = [] self._test_env = [] @property @@ -251,13 +254,6 @@ def key(self) -> str: """ return f"{self.project_link}:{self.module_name}" - @property - def path(self) -> Path: - """插件测试目录""" - # 替换 : 为 -,防止文件名不合法 - key = self.key.replace(":", "-") - return self._test_dir / f"{key}" - @property def env(self) -> dict[str, str]: """获取环境变量""" @@ -279,11 +275,6 @@ def _log_output(self, msg: str): async def run(self): """插件测试入口""" - - # 创建测试目录 - if not self._test_dir.exists(): - self._test_dir.mkdir() - # 创建插件测试项目 await self.create_poetry_project() if self._create: @@ -294,9 +285,9 @@ async def run(self): await self.run_poetry_project() metadata = None - metadata_path = self.path / "metadata.json" + metadata_path = self._test_dir / "metadata.json" if metadata_path.exists(): - with open(self.path / "metadata.json", encoding="utf-8") as f: + with open(self._test_dir / "metadata.json", encoding="utf-8") as f: metadata = json.load(f) result = { @@ -326,7 +317,7 @@ async def command(self, cmd: str, timeout: int = 300) -> tuple[bool, str, str]: cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - cwd=self.path, + cwd=self._test_dir, env=self.env, ) try: @@ -347,8 +338,8 @@ async def command(self, cmd: str, timeout: int = 300) -> tuple[bool, str, str]: async def create_poetry_project(self): """创建 poetry 项目用来测试插件""" - if not self.path.exists(): - self.path.mkdir() + if not self._test_dir.exists(): + self._test_dir.mkdir() code, stdout, stderr = await self.command( f"""poetry init -n && sed -i "s/\\^/~/g" pyproject.toml && poetry env info --ansi && poetry add {self.project_link}""" @@ -372,7 +363,7 @@ async def create_poetry_project(self): async def show_package_info(self) -> None: """获取插件的版本与插件信息""" - if self.path.exists(): + if self._test_dir.exists(): code, stdout, stderr = await self.command( f"poetry show {self.project_link}" ) @@ -389,19 +380,19 @@ async def show_package_info(self) -> None: async def run_poetry_project(self) -> None: """运行插件""" - if self.path.exists(): + if self._test_dir.exists(): # 默认使用 fake 驱动 - with open(self.path / ".env", "w", encoding="utf-8") as f: + with open(self._test_dir / ".env", "w", encoding="utf-8") as f: f.write("DRIVER=fake") # 如果提供了插件配置项,则写入配置文件 if self.config is not None: - with open(self.path / ".env.prod", "w", encoding="utf-8") as f: + with open(self._test_dir / ".env.prod", "w", encoding="utf-8") as f: f.write(self.config) - with open(self.path / "fake.py", "w", encoding="utf-8") as f: + with open(self._test_dir / "fake.py", "w", encoding="utf-8") as f: f.write(FAKE_SCRIPT) - with open(self.path / "runner.py", "w", encoding="utf-8") as f: + with open(self._test_dir / "runner.py", "w", encoding="utf-8") as f: f.write( RUNNER_SCRIPT.format( self.module_name, @@ -424,7 +415,7 @@ async def run_poetry_project(self) -> None: async def show_plugin_dependencies(self) -> None: """获取插件的依赖""" - if self.path.exists(): + if self._test_dir.exists(): code, stdout, stderr = await self.command("poetry export --without-hashes") if code: @@ -485,13 +476,15 @@ def _get_test_env(self, requirements: dict[str, str]) -> list[str]: def main(): """根据传入的环境变量进行测试 - PLUGIN_INFO 即为该插件的 KEY + PROJECT_LINK 为插件的项目名 + MODULE_NAME 为插件的模块名 PLUGIN_CONFIG 即为该插件的配置 """ - - plugin_info = os.environ.get("PLUGIN_INFO", "") + project_link = os.environ.get("PROJECT_LINK", "") + module_name = os.environ.get("MODULE_NAME", "") plugin_config = os.environ.get("PLUGIN_CONFIG", None) - plugin = PluginTest(plugin_info, plugin_config) + + plugin = PluginTest(project_link, module_name, plugin_config) asyncio.run(plugin.run()) diff --git a/tests/utils/docker_test/test_docker_plugin_test.py b/tests/utils/docker_test/test_docker_plugin_test.py index d5d6021e..44b0d6c5 100644 --- a/tests/utils/docker_test/test_docker_plugin_test.py +++ b/tests/utils/docker_test/test_docker_plugin_test.py @@ -45,7 +45,8 @@ async def test_docker_plugin_test(mocked_api: MockRouter, mocker: MockerFixture) "ghcr.io/nonebot/nonetest:3.12-latest", environment=snapshot( { - "PLUGIN_INFO": "project_link:module_name", + "PROJECT_LINK": "project_link", + "MODULE_NAME": "module_name", "PLUGIN_CONFIG": "", "PLUGINS_URL": "https://raw.githubusercontent.com/nonebot/registry/results/plugins.json", } @@ -110,7 +111,8 @@ async def test_docker_plugin_test_metadata_some_fields_empty( "ghcr.io/nonebot/nonetest:3.12-latest", environment=snapshot( { - "PLUGIN_INFO": "project_link:module_name", + "PROJECT_LINK": "project_link", + "MODULE_NAME": "module_name", "PLUGIN_CONFIG": "", "PLUGINS_URL": "https://raw.githubusercontent.com/nonebot/registry/results/plugins.json", } @@ -175,7 +177,8 @@ async def test_docker_plugin_test_metadata_some_fields_invalid( "ghcr.io/nonebot/nonetest:3.12-latest", environment=snapshot( { - "PLUGIN_INFO": "project_link:module_name", + "PROJECT_LINK": "project_link", + "MODULE_NAME": "module_name", "PLUGIN_CONFIG": "", "PLUGINS_URL": "https://raw.githubusercontent.com/nonebot/registry/results/plugins.json", } diff --git a/tests/utils/docker_test/test_plugin_test.py b/tests/utils/docker_test/test_plugin_test.py index e54e131e..c552b35b 100644 --- a/tests/utils/docker_test/test_plugin_test.py +++ b/tests/utils/docker_test/test_plugin_test.py @@ -8,9 +8,9 @@ async def test_plugin_test(mocker: MockerFixture, tmp_path: Path): from src.providers.docker_test.plugin_test import PluginTest - test = PluginTest("project_link:module_name", "test=123") + test = PluginTest("project_link", "module_name", "test=123") - mocker.patch.object(test, "_test_dir", tmp_path) + mocker.patch.object(test, "_test_dir", tmp_path / "plugin_test") def command_output(cmd: str, timeout: int = 300): if ( @@ -86,9 +86,7 @@ def command_output(cmd: str, timeout: int = 300): ) if cmd == "poetry run python runner.py": # run_plugin_test - with open( - tmp_path / "project_link-module_name" / "metadata.json", "w" - ) as f: + with open(tmp_path / "plugin_test" / "metadata.json", "w") as f: json.dump( { "name": "帮助", From 9c33954833ff703a59a8f6ae926c8e94618758d1 Mon Sep 17 00:00:00 2001 From: uy_sun Date: Wed, 27 Nov 2024 13:55:43 +0800 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8=20output=20?= =?UTF-8?q?=E8=80=8C=E4=B8=8D=E6=98=AF=20outputs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/plugins/publish/validation.py | 5 +- src/providers/docker_test/__init__.py | 11 +- src/providers/docker_test/plugin_test.py | 2 +- src/providers/store_test/validation.py | 5 +- .../process/test_publish_pull_request.py | 1 + ..._publish_resolve_conflict_pull_requests.py | 2 + .../utils/test_trigger_registry_update.py | 2 + .../utils/test_validate_info_from_issue.py | 2 +- .../docker_test/test_docker_plugin_test.py | 12 +-- tests/utils/docker_test/test_plugin_test.py | 100 +++++++++--------- tests/utils/store_test/output.json | 5 +- tests/utils/store_test/output_failed.json | 5 +- 12 files changed, 70 insertions(+), 82 deletions(-) diff --git a/src/plugins/github/plugins/publish/validation.py b/src/plugins/github/plugins/publish/validation.py index 48b21854..c7dce682 100644 --- a/src/plugins/github/plugins/publish/validation.py +++ b/src/plugins/github/plugins/publish/validation.py @@ -112,7 +112,7 @@ async def validate_plugin_info_from_issue( project_link, module_name, test_config ).run("3.12") # 去除颜色字符 - test_output = strip_ansi("\n".join(test_result.outputs)) + test_output = strip_ansi(test_result.output) metadata = test_result.metadata if metadata: # 从插件测试结果中获得元数据 @@ -130,8 +130,7 @@ async def validate_plugin_info_from_issue( ) logger.info(f"插件元数据:{metadata}") logger.info("插件测试输出:") - for output in test_result.outputs: - logger.info(output) + logger.info(test_result.output) # 验证插件相关信息 result = validate_info(PublishType.PLUGIN, raw_data, previous_data) diff --git a/src/providers/docker_test/__init__.py b/src/providers/docker_test/__init__.py index 907d3f9e..62d277a2 100644 --- a/src/providers/docker_test/__init__.py +++ b/src/providers/docker_test/__init__.py @@ -35,7 +35,7 @@ class DockerTestResult(BaseModel): """ metadata: SkipValidation[Metadata] | None """ 插件元数据 """ - outputs: list[str] + output: str """ 测试输出 """ @field_validator("config", mode="before") @@ -50,15 +50,6 @@ def __init__(self, project_link: str, module_name: str, config: str = ""): self.module_name = module_name self.config = config - @property - def key(self) -> str: - """插件的标识符 - - project_link:module_name - 例:nonebot-plugin-test:nonebot_plugin_test - """ - return f"{self.project_link}:{self.module_name}" - async def run(self, version: str) -> DockerTestResult: """运行 Docker 容器测试插件 diff --git a/src/providers/docker_test/plugin_test.py b/src/providers/docker_test/plugin_test.py index 371f4e81..9b7db9d7 100644 --- a/src/providers/docker_test/plugin_test.py +++ b/src/providers/docker_test/plugin_test.py @@ -292,7 +292,7 @@ async def run(self): result = { "metadata": metadata, - "outputs": self._lines_output, + "output": "\n".join(self._lines_output), "load": self._run, "run": self._create, "version": self._version, diff --git a/src/providers/store_test/validation.py b/src/providers/store_test/validation.py index ed8d01e0..46bebf0e 100644 --- a/src/providers/store_test/validation.py +++ b/src/providers/store_test/validation.py @@ -41,7 +41,7 @@ async def validate_plugin( ) plugin_test_load = plugin_test_result.load - plugin_test_output = "\n".join(plugin_test_result.outputs) + plugin_test_output = plugin_test_result.output plugin_test_version = plugin_test_result.version plugin_test_env = plugin_test_result.test_env plugin_metadata = plugin_test_result.metadata @@ -52,8 +52,7 @@ async def validate_plugin( ) click.echo(f"插件元数据:{plugin_metadata}") click.echo("插件测试输出:") - for output in plugin_test_result.outputs: - click.echo(output) + click.echo(plugin_test_output) if previous_plugin is None: # 使用商店插件数据作为新的插件数据 diff --git a/tests/github/publish/process/test_publish_pull_request.py b/tests/github/publish/process/test_publish_pull_request.py index c9d06c43..b177e00e 100644 --- a/tests/github/publish/process/test_publish_pull_request.py +++ b/tests/github/publish/process/test_publish_pull_request.py @@ -53,6 +53,7 @@ async def test_process_pull_request( ) mock_test_result.load = True mock_test_result.version = "1.0.0" + mock_test_result.output = "" mock_docker = mocker.patch("src.providers.docker_test.DockerPluginTest.run") mock_docker.return_value = mock_test_result diff --git a/tests/github/publish/utils/test_publish_resolve_conflict_pull_requests.py b/tests/github/publish/utils/test_publish_resolve_conflict_pull_requests.py index 755cf5c2..1a2b5462 100644 --- a/tests/github/publish/utils/test_publish_resolve_conflict_pull_requests.py +++ b/tests/github/publish/utils/test_publish_resolve_conflict_pull_requests.py @@ -320,6 +320,7 @@ async def test_resolve_conflict_pull_requests_plugin( supported_adapters=["~onebot.v11"], ) mock_test_result.version = "1.0.0" + mock_test_result.output = "" mock_docker = mocker.patch("src.providers.docker_test.DockerPluginTest.run") mock_docker.return_value = mock_test_result @@ -461,6 +462,7 @@ async def test_resolve_conflict_pull_requests_plugin_not_valid( mock_test_result = mocker.MagicMock() mock_test_result.load = False mock_test_result.metadata = None + mock_test_result.output = "" mock_docker = mocker.patch("src.providers.docker_test.DockerPluginTest.run") mock_docker.return_value = mock_test_result diff --git a/tests/github/publish/utils/test_trigger_registry_update.py b/tests/github/publish/utils/test_trigger_registry_update.py index bfc23b7a..8acd0ced 100644 --- a/tests/github/publish/utils/test_trigger_registry_update.py +++ b/tests/github/publish/utils/test_trigger_registry_update.py @@ -45,6 +45,7 @@ async def test_trigger_registry_update( ) mock_test_result.load = True mock_test_result.version = "1.0.0" + mock_test_result.output = "" mock_docker = mocker.patch("src.providers.docker_test.DockerPluginTest.run") mock_docker.return_value = mock_test_result @@ -307,6 +308,7 @@ async def test_trigger_registry_update_plugins_issue_body_info_missing( supported_adapters=["~onebot.v11"], ) mock_test_result.load = True + mock_test_result.output = "" mock_docker = mocker.patch("src.providers.docker_test.DockerPluginTest.run") mock_docker.return_value = mock_test_result diff --git a/tests/github/publish/utils/test_validate_info_from_issue.py b/tests/github/publish/utils/test_validate_info_from_issue.py index cb0b63ee..b3852d0d 100644 --- a/tests/github/publish/utils/test_validate_info_from_issue.py +++ b/tests/github/publish/utils/test_validate_info_from_issue.py @@ -80,7 +80,7 @@ async def test_validate_info_from_issue_plugin( ) mock_test_result.version = "1.0.0" mock_test_result.load = True - mock_test_result.outputs = ['require("nonebot_plugin_alconna")', "test"] + mock_test_result.output = 'require("nonebot_plugin_alconna")\ntest' mock_docker = mocker.patch("src.providers.docker_test.DockerPluginTest.run") mock_docker.return_value = mock_test_result diff --git a/tests/utils/docker_test/test_docker_plugin_test.py b/tests/utils/docker_test/test_docker_plugin_test.py index 44b0d6c5..e893061c 100644 --- a/tests/utils/docker_test/test_docker_plugin_test.py +++ b/tests/utils/docker_test/test_docker_plugin_test.py @@ -12,7 +12,7 @@ async def test_docker_plugin_test(mocked_api: MockRouter, mocker: MockerFixture) mocked_run.return_value = json.dumps( { "metadata": None, - "outputs": ["test"], + "output": "test", "load": True, "run": True, "version": "0.0.1", @@ -33,7 +33,7 @@ async def test_docker_plugin_test(mocked_api: MockRouter, mocker: MockerFixture) config="", load=True, metadata=None, - outputs=["test"], + output="test", run=True, test_env="python==3.12", version="0.0.1", @@ -72,7 +72,7 @@ async def test_docker_plugin_test_metadata_some_fields_empty( "type": None, "supported_adapters": None, }, - "outputs": ["test"], + "output": "test", "load": True, "run": True, "version": "0.0.1", @@ -99,7 +99,7 @@ async def test_docker_plugin_test_metadata_some_fields_empty( "type": None, "supported_adapters": None, }, - outputs=["test"], + output="test", run=True, test_env="python==3.12", version="0.0.1", @@ -138,7 +138,7 @@ async def test_docker_plugin_test_metadata_some_fields_invalid( "type": True, "supported_adapters": {}, }, - "outputs": ["test"], + "output": "test", "load": True, "run": True, "version": "0.0.1", @@ -165,7 +165,7 @@ async def test_docker_plugin_test_metadata_some_fields_invalid( type=True, # type: ignore supported_adapters={}, # type: ignore ), - outputs=["test"], + output="test", run=True, test_env="python==3.12", version="0.0.1", diff --git a/tests/utils/docker_test/test_plugin_test.py b/tests/utils/docker_test/test_plugin_test.py index c552b35b..87ea4ae8 100644 --- a/tests/utils/docker_test/test_plugin_test.py +++ b/tests/utils/docker_test/test_plugin_test.py @@ -121,56 +121,56 @@ def command_output(cmd: str, timeout: int = 300): "type": "application", "supported_adapters": None, }, - "outputs": [ - "项目 project_link 创建成功。", - " Virtualenv", - " Python: 3.12.7", - " Implementation: CPython", - " Path: NA", - " Executable: NA", - " ", - " Base", - " Platform: linux", - " OS: posix", - " Python: 3.12.7", - " Path: /usr/local", - " Executable: /usr/local/bin/python3.12", - " Using version ^0.5.0 for nonebot-plugin-treehelp", - " ", - " Updating dependencies", - " Resolving dependencies...", - " ", - " Package operations: 16 installs, 0 updates, 0 removals", - " ", - " - Installing typing-extensions (4.12.2)", - " - Installing annotated-types (0.7.0)", - " - Installing idna (3.10)", - " - Installing multidict (6.1.0)", - " - Installing propcache (0.2.0)", - " - Installing pydantic-core (2.23.4)", - " - Installing sniffio (1.3.1)", - " - Installing anyio (4.6.2.post1)", - " - Installing exceptiongroup (1.2.2)", - " - Installing loguru (0.7.2)", - " - Installing pydantic (2.9.2)", - " - Installing pygtrie (2.5.0)", - " - Installing python-dotenv (1.0.1)", - " - Installing yarl (1.17.2)", - " - Installing nonebot2 (2.4.0)", - " - Installing nonebot-plugin-treehelp (0.5.0)", - " ", - " Writing lock file", - "插件 project_link 的信息如下:", - " name : nonebot-plugin-treehelp", - " version : 0.5.0", - " description : 适用于 Nonebot2 的树形帮助插件", - " ", - " dependencies", - " - nonebot2 >=2.2.0", - "插件 project_link 依赖的插件如下:", - " ", - "插件 module_name 加载正常:", - ], + "output": """\ +项目 project_link 创建成功。 + Virtualenv + Python: 3.12.7 + Implementation: CPython + Path: NA + Executable: NA + + Base + Platform: linux + OS: posix + Python: 3.12.7 + Path: /usr/local + Executable: /usr/local/bin/python3.12 + Using version ^0.5.0 for nonebot-plugin-treehelp + + Updating dependencies + Resolving dependencies... + + Package operations: 16 installs, 0 updates, 0 removals + + - Installing typing-extensions (4.12.2) + - Installing annotated-types (0.7.0) + - Installing idna (3.10) + - Installing multidict (6.1.0) + - Installing propcache (0.2.0) + - Installing pydantic-core (2.23.4) + - Installing sniffio (1.3.1) + - Installing anyio (4.6.2.post1) + - Installing exceptiongroup (1.2.2) + - Installing loguru (0.7.2) + - Installing pydantic (2.9.2) + - Installing pygtrie (2.5.0) + - Installing python-dotenv (1.0.1) + - Installing yarl (1.17.2) + - Installing nonebot2 (2.4.0) + - Installing nonebot-plugin-treehelp (0.5.0) + + Writing lock file +插件 project_link 的信息如下: + name : nonebot-plugin-treehelp + version : 0.5.0 + description : 适用于 Nonebot2 的树形帮助插件 + + dependencies + - nonebot2 >=2.2.0 +插件 project_link 依赖的插件如下: + +插件 module_name 加载正常:\ +""", # noqa: W293 "load": True, "run": True, "version": "0.5.0", diff --git a/tests/utils/store_test/output.json b/tests/utils/store_test/output.json index b7e312d8..388a6b13 100644 --- a/tests/utils/store_test/output.json +++ b/tests/utils/store_test/output.json @@ -7,10 +7,7 @@ "homepage": "https://nonebot.dev/", "supported_adapters": null }, - "outputs": [ - "\u521b\u5efa\u6d4b\u8bd5\u76ee\u5f55 plugin_test", - " require(\"nonebot_plugin_alconna\")" - ], + "output": "\u521b\u5efa\u6d4b\u8bd5\u76ee\u5f55 plugin_test\n require(\"nonebot_plugin_alconna\")", "load": true, "run": true, "version": "0.2.0", diff --git a/tests/utils/store_test/output_failed.json b/tests/utils/store_test/output_failed.json index 58074199..e17f15eb 100644 --- a/tests/utils/store_test/output_failed.json +++ b/tests/utils/store_test/output_failed.json @@ -1,9 +1,6 @@ { "metadata": null, - "outputs": [ - "\u521b\u5efa\u6d4b\u8bd5\u76ee\u5f55 plugin_test", - " For further information visit https://errors.pydantic.dev/2.9/v/model_type\u001b[0m" - ], + "output": "\u521b\u5efa\u6d4b\u8bd5\u76ee\u5f55 plugin_test\n For further information visit https://errors.pydantic.dev/2.9/v/model_type\u001b[0m", "load": false, "run": true, "version": "0.3.9", From 0e1e7062a9d7ca8f7cb8fd6c7c599b97fefd6c11 Mon Sep 17 00:00:00 2001 From: uy_sun Date: Wed, 27 Nov 2024 13:57:09 +0800 Subject: [PATCH 4/5] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e6bcc61..1c811f07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/ ### Fixed - 超时后仍需读取 stdout 与 stderr 的内容 +- 修复 Docker Test 报错未捕获的问题 ## [4.0.11] - 2024-11-23 From e2d2ca8ad669acf889e2baa5280828f4b872f02b Mon Sep 17 00:00:00 2001 From: uy_sun Date: Wed, 27 Nov 2024 19:38:05 +0800 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9=E4=B8=BA=20o?= =?UTF-8?q?utput?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/github/plugins/config/utils.py | 5 ++--- tests/github/config/process/test_config_check.py | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/github/plugins/config/utils.py b/src/plugins/github/plugins/config/utils.py index 7de0405e..a05bcd0a 100644 --- a/src/plugins/github/plugins/config/utils.py +++ b/src/plugins/github/plugins/config/utils.py @@ -59,7 +59,7 @@ async def validate_info_from_issue(handler: IssueHandler) -> ValidationDict: test_result = await test.run("3.12") # 去除颜色字符 - test_output = strip_ansi("\n".join(test_result.outputs)) + test_output = strip_ansi(test_result.output) metadata = test_result.metadata if metadata: # 从插件测试结果中获得元数据 @@ -78,8 +78,7 @@ async def validate_info_from_issue(handler: IssueHandler) -> ValidationDict: ) logger.info(f"插件元数据:{metadata}") logger.info("插件测试输出:") - for output in test_result.outputs: - logger.info(output) + logger.info(test_output) # 验证插件相关信息 result = validate_info(PublishType.PLUGIN, raw_data, previous_data) diff --git a/tests/github/config/process/test_config_check.py b/tests/github/config/process/test_config_check.py index 0ffb7097..7576c1b8 100644 --- a/tests/github/config/process/test_config_check.py +++ b/tests/github/config/process/test_config_check.py @@ -76,6 +76,7 @@ async def test_process_config_check( ) mock_test_result.load = True mock_test_result.version = "1.0.0" + mock_test_result.output = "" mock_docker = mocker.patch("src.providers.docker_test.DockerPluginTest.run") mock_docker.return_value = mock_test_result