Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
refactor(tests): optimize unit test structure
chengyongru72acba5d274b
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 67a4d9b0d..e00362d02 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -21,13 +21,14 @@ jobs:with:python-version: ${{ matrix.python-version }}+ - name: Install uv+ uses: astral-sh/setup-uv@v4+- name: Install system dependenciesrun: sudo apt-get update && sudo apt-get install -y libolm-dev build-essential- - name: Install dependencies- run: |- python -m pip install --upgrade pip- pip install .[dev]+ - name: Install all dependencies+ run: uv sync --all-extras- name: Run tests- run: python -m pytest tests/ -v+ run: uv run pytest tests/diff --git a/nanobot/agent/tools/shell.py b/nanobot/agent/tools/shell.pyindex 5b4641297..ed552b33e 100644--- a/nanobot/agent/tools/shell.py+++ b/nanobot/agent/tools/shell.py@@ -3,6 +3,7 @@import asyncioimport osimport re+import sysfrom pathlib import Pathfrom typing import Any@@ -113,10 +114,11 @@ class ExecTool(Tool):except asyncio.TimeoutError:passfinally:- try:- os.waitpid(process.pid, os.WNOHANG)- except (ProcessLookupError, ChildProcessError) as e:- logger.debug("Process already reaped or not found: {}", e)+ if sys.platform != "win32":+ try:+ os.waitpid(process.pid, os.WNOHANG)+ except (ProcessLookupError, ChildProcessError) as e:+ logger.debug("Process already reaped or not found: {}", e)return f"Error: Command timed out after {effective_timeout} seconds"output_parts = []diff --git a/pyproject.toml b/pyproject.tomlindex a941ab17d..be367a473 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -70,11 +70,8 @@ langsmith = [dev = ["pytest>=9.0.0,<10.0.0","pytest-asyncio>=1.3.0,<2.0.0",+ "pytest-cov>=6.0.0,<7.0.0","ruff>=0.1.0",- "matrix-nio[e2e]>=0.25.2",- "mistune>=3.0.0,<4.0.0",- "nh3>=0.2.17,<1.0.0",- "mypy>=1.19.1",][project.scripts]diff --git a/tests/test_consolidate_offset.py b/tests/agent/test_consolidate_offset.pysimilarity index 100%rename from tests/test_consolidate_offset.pyrename to tests/agent/test_consolidate_offset.pydiff --git a/tests/test_context_prompt_cache.py b/tests/agent/test_context_prompt_cache.pysimilarity index 100%rename from tests/test_context_prompt_cache.pyrename to tests/agent/test_context_prompt_cache.pydiff --git a/tests/test_evaluator.py b/tests/agent/test_evaluator.pysimilarity index 100%rename from tests/test_evaluator.pyrename to tests/agent/test_evaluator.pydiff --git a/tests/test_gemini_thought_signature.py b/tests/agent/test_gemini_thought_signature.pysimilarity index 100%rename from tests/test_gemini_thought_signature.pyrename to tests/agent/test_gemini_thought_signature.pydiff --git a/tests/test_heartbeat_service.py b/tests/agent/test_heartbeat_service.pysimilarity index 100%rename from tests/test_heartbeat_service.pyrename to tests/agent/test_heartbeat_service.pydiff --git a/tests/test_loop_consolidation_tokens.py b/tests/agent/test_loop_consolidation_tokens.pysimilarity index 100%rename from tests/test_loop_consolidation_tokens.pyrename to tests/agent/test_loop_consolidation_tokens.pydiff --git a/tests/test_loop_save_turn.py b/tests/agent/test_loop_save_turn.pysimilarity index 100%rename from tests/test_loop_save_turn.pyrename to tests/agent/test_loop_save_turn.pydiff --git a/tests/test_memory_consolidation_types.py b/tests/agent/test_memory_consolidation_types.pysimilarity index 100%rename from tests/test_memory_consolidation_types.pyrename to tests/agent/test_memory_consolidation_types.pydiff --git a/tests/test_onboard_logic.py b/tests/agent/test_onboard_logic.pysimilarity index 100%rename from tests/test_onboard_logic.pyrename to tests/agent/test_onboard_logic.pydiff --git a/tests/test_session_manager_history.py b/tests/agent/test_session_manager_history.pysimilarity index 100%rename from tests/test_session_manager_history.pyrename to tests/agent/test_session_manager_history.pydiff --git a/tests/test_skill_creator_scripts.py b/tests/agent/test_skill_creator_scripts.pysimilarity index 100%rename from tests/test_skill_creator_scripts.pyrename to tests/agent/test_skill_creator_scripts.pydiff --git a/tests/test_task_cancel.py b/tests/agent/test_task_cancel.pysimilarity index 100%rename from tests/test_task_cancel.pyrename to tests/agent/test_task_cancel.pydiff --git a/tests/test_base_channel.py b/tests/channels/test_base_channel.pysimilarity index 100%rename from tests/test_base_channel.pyrename to tests/channels/test_base_channel.pydiff --git a/tests/test_channel_plugins.py b/tests/channels/test_channel_plugins.pysimilarity index 100%rename from tests/test_channel_plugins.pyrename to tests/channels/test_channel_plugins.pydiff --git a/tests/test_dingtalk_channel.py b/tests/channels/test_dingtalk_channel.pysimilarity index 95%rename from tests/test_dingtalk_channel.pyrename to tests/channels/test_dingtalk_channel.pyindex a0b866fad..6894c8683 100644--- a/tests/test_dingtalk_channel.py+++ b/tests/channels/test_dingtalk_channel.py@@ -3,6 +3,16 @@ from types import SimpleNamespaceimport pytest+# Check optional dingtalk dependencies before running tests+try:+ from nanobot.channels import dingtalk+ DINGTALK_AVAILABLE = getattr(dingtalk, "DINGTALK_AVAILABLE", False)+except ImportError:+ DINGTALK_AVAILABLE = False++if not DINGTALK_AVAILABLE:+ pytest.skip("DingTalk dependencies not installed (dingtalk-stream)", allow_module_level=True)+from nanobot.bus.queue import MessageBusimport nanobot.channels.dingtalk as dingtalk_modulefrom nanobot.channels.dingtalk import DingTalkChannel, NanobotDingTalkHandlerdiff --git a/tests/test_email_channel.py b/tests/channels/test_email_channel.pysimilarity index 100%rename from tests/test_email_channel.pyrename to tests/channels/test_email_channel.pydiff --git a/tests/test_feishu_markdown_rendering.py b/tests/channels/test_feishu_markdown_rendering.pysimilarity index 81%rename from tests/test_feishu_markdown_rendering.pyrename to tests/channels/test_feishu_markdown_rendering.pyindex 6812a21aa..efcd20733 100644--- a/tests/test_feishu_markdown_rendering.py+++ b/tests/channels/test_feishu_markdown_rendering.py@@ -1,3 +1,14 @@+# Check optional Feishu dependencies before running tests+try:+ from nanobot.channels import feishu+ FEISHU_AVAILABLE = getattr(feishu, "FEISHU_AVAILABLE", False)+except ImportError:+ FEISHU_AVAILABLE = False++if not FEISHU_AVAILABLE:+ import pytest+ pytest.skip("Feishu dependencies not installed (lark-oapi)", allow_module_level=True)+from nanobot.channels.feishu import FeishuChanneldiff --git a/tests/test_feishu_post_content.py b/tests/channels/test_feishu_post_content.pysimilarity index 82%rename from tests/test_feishu_post_content.pyrename to tests/channels/test_feishu_post_content.pyindex 7b1cb9d31..a4c5bae19 100644--- a/tests/test_feishu_post_content.py+++ b/tests/channels/test_feishu_post_content.py@@ -1,3 +1,14 @@+# Check optional Feishu dependencies before running tests+try:+ from nanobot.channels import feishu+ FEISHU_AVAILABLE = getattr(feishu, "FEISHU_AVAILABLE", False)+except ImportError:+ FEISHU_AVAILABLE = False++if not FEISHU_AVAILABLE:+ import pytest+ pytest.skip("Feishu dependencies not installed (lark-oapi)", allow_module_level=True)+from nanobot.channels.feishu import FeishuChannel, _extract_post_contentdiff --git a/tests/test_feishu_reply.py b/tests/channels/test_feishu_reply.pysimilarity index 97%rename from tests/test_feishu_reply.pyrename to tests/channels/test_feishu_reply.pyindex b2072b31a..0753653a7 100644--- a/tests/test_feishu_reply.py+++ b/tests/channels/test_feishu_reply.py@@ -7,6 +7,16 @@ from unittest.mock import MagicMock, patchimport pytest+# Check optional Feishu dependencies before running tests+try:+ from nanobot.channels import feishu+ FEISHU_AVAILABLE = getattr(feishu, "FEISHU_AVAILABLE", False)+except ImportError:+ FEISHU_AVAILABLE = False++if not FEISHU_AVAILABLE:+ pytest.skip("Feishu dependencies not installed (lark-oapi)", allow_module_level=True)+from nanobot.bus.events import OutboundMessagefrom nanobot.bus.queue import MessageBusfrom nanobot.channels.feishu import FeishuChannel, FeishuConfigdiff --git a/tests/test_feishu_table_split.py b/tests/channels/test_feishu_table_split.pysimilarity index 89%rename from tests/test_feishu_table_split.pyrename to tests/channels/test_feishu_table_split.pyindex af8fa164a..030b8910d 100644--- a/tests/test_feishu_table_split.py+++ b/tests/channels/test_feishu_table_split.py@@ -6,6 +6,17 @@ list of card elements into groups so that each group contains at most onetable, allowing nanobot to send multiple cards instead of failing."""+# Check optional Feishu dependencies before running tests+try:+ from nanobot.channels import feishu+ FEISHU_AVAILABLE = getattr(feishu, "FEISHU_AVAILABLE", False)+except ImportError:+ FEISHU_AVAILABLE = False++if not FEISHU_AVAILABLE:+ import pytest+ pytest.skip("Feishu dependencies not installed (lark-oapi)", allow_module_level=True)+from nanobot.channels.feishu import FeishuChanneldiff --git a/tests/test_feishu_tool_hint_code_block.py b/tests/channels/test_feishu_tool_hint_code_block.pysimilarity index 93%rename from tests/test_feishu_tool_hint_code_block.pyrename to tests/channels/test_feishu_tool_hint_code_block.pyindex 2a1b81227..a65f1d988 100644--- a/tests/test_feishu_tool_hint_code_block.py+++ b/tests/channels/test_feishu_tool_hint_code_block.py@@ -6,6 +6,16 @@ from unittest.mock import MagicMock, patchimport pytestfrom pytest import mark+# Check optional Feishu dependencies before running tests+try:+ from nanobot.channels import feishu+ FEISHU_AVAILABLE = getattr(feishu, "FEISHU_AVAILABLE", False)+except ImportError:+ FEISHU_AVAILABLE = False++if not FEISHU_AVAILABLE:+ pytest.skip("Feishu dependencies not installed (lark-oapi)", allow_module_level=True)+from nanobot.bus.events import OutboundMessagefrom nanobot.channels.feishu import FeishuChanneldiff --git a/tests/test_matrix_channel.py b/tests/channels/test_matrix_channel.pysimilarity index 99%rename from tests/test_matrix_channel.pyrename to tests/channels/test_matrix_channel.pyindex 1f3b69ccf..dd5e97d90 100644--- a/tests/test_matrix_channel.py+++ b/tests/channels/test_matrix_channel.py@@ -4,6 +4,12 @@ from types import SimpleNamespaceimport pytest+# Check optional matrix dependencies before importing+try:+ import nh3 # noqa: F401+except ImportError:+ pytest.skip("Matrix dependencies not installed (nh3)", allow_module_level=True)+import nanobot.channels.matrix as matrix_modulefrom nanobot.bus.events import OutboundMessagefrom nanobot.bus.queue import MessageBusdiff --git a/tests/test_qq_channel.py b/tests/channels/test_qq_channel.pysimilarity index 93%rename from tests/test_qq_channel.pyrename to tests/channels/test_qq_channel.pyindex ab9afcbc7..729442a13 100644--- a/tests/test_qq_channel.py+++ b/tests/channels/test_qq_channel.py@@ -4,6 +4,16 @@ from types import SimpleNamespaceimport pytest+# Check optional QQ dependencies before running tests+try:+ from nanobot.channels import qq+ QQ_AVAILABLE = getattr(qq, "QQ_AVAILABLE", False)+except ImportError:+ QQ_AVAILABLE = False++if not QQ_AVAILABLE:+ pytest.skip("QQ dependencies not installed (qq-botpy)", allow_module_level=True)+from nanobot.bus.events import OutboundMessagefrom nanobot.bus.queue import MessageBusfrom nanobot.channels.qq import QQChannel, QQConfigdiff --git a/tests/test_slack_channel.py b/tests/channels/test_slack_channel.pysimilarity index 95%rename from tests/test_slack_channel.pyrename to tests/channels/test_slack_channel.pyindex d243235aa..f7eec95c0 100644--- a/tests/test_slack_channel.py+++ b/tests/channels/test_slack_channel.py@@ -2,6 +2,12 @@ from __future__ import annotationsimport pytest+# Check optional Slack dependencies before running tests+try:+ import slack_sdk # noqa: F401+except ImportError:+ pytest.skip("Slack dependencies not installed (slack-sdk)", allow_module_level=True)+from nanobot.bus.events import OutboundMessagefrom nanobot.bus.queue import MessageBusfrom nanobot.channels.slack import SlackChanneldiff --git a/tests/test_telegram_channel.py b/tests/channels/test_telegram_channel.pysimilarity index 99%rename from tests/test_telegram_channel.pyrename to tests/channels/test_telegram_channel.pyindex 8b6ba9789..353d5d05d 100644--- a/tests/test_telegram_channel.py+++ b/tests/channels/test_telegram_channel.py@@ -5,6 +5,12 @@ from unittest.mock import AsyncMockimport pytest+# Check optional Telegram dependencies before running tests+try:+ import telegram # noqa: F401+except ImportError:+ pytest.skip("Telegram dependencies not installed (python-telegram-bot)", allow_module_level=True)+from nanobot.bus.events import OutboundMessagefrom nanobot.bus.queue import MessageBusfrom nanobot.channels.telegram import TELEGRAM_REPLY_CONTEXT_MAX_LEN, TelegramChanneldiff --git a/tests/test_weixin_channel.py b/tests/channels/test_weixin_channel.pysimilarity index 100%rename from tests/test_weixin_channel.pyrename to tests/channels/test_weixin_channel.pydiff --git a/tests/test_whatsapp_channel.py b/tests/channels/test_whatsapp_channel.pysimilarity index 100%rename from tests/test_whatsapp_channel.pyrename to tests/channels/test_whatsapp_channel.pydiff --git a/tests/test_cli_input.py b/tests/cli/test_cli_input.pysimilarity index 100%rename from tests/test_cli_input.pyrename to tests/cli/test_cli_input.pydiff --git a/tests/test_commands.py b/tests/cli/test_commands.pysimilarity index 100%rename from tests/test_commands.pyrename to tests/cli/test_commands.pydiff --git a/tests/test_restart_command.py b/tests/cli/test_restart_command.pysimilarity index 100%rename from tests/test_restart_command.pyrename to tests/cli/test_restart_command.pydiff --git a/tests/test_config_migration.py b/tests/config/test_config_migration.pysimilarity index 100%rename from tests/test_config_migration.pyrename to tests/config/test_config_migration.pydiff --git a/tests/test_config_paths.py b/tests/config/test_config_paths.pysimilarity index 100%rename from tests/test_config_paths.pyrename to tests/config/test_config_paths.pydiff --git a/tests/test_cron_service.py b/tests/cron/test_cron_service.pysimilarity index 100%rename from tests/test_cron_service.pyrename to tests/cron/test_cron_service.pydiff --git a/tests/test_cron_tool_list.py b/tests/cron/test_cron_tool_list.pysimilarity index 100%rename from tests/test_cron_tool_list.pyrename to tests/cron/test_cron_tool_list.pydiff --git a/tests/test_azure_openai_provider.py b/tests/providers/test_azure_openai_provider.pysimilarity index 100%rename from tests/test_azure_openai_provider.pyrename to tests/providers/test_azure_openai_provider.pydiff --git a/tests/test_custom_provider.py b/tests/providers/test_custom_provider.pysimilarity index 100%rename from tests/test_custom_provider.pyrename to tests/providers/test_custom_provider.pydiff --git a/tests/test_litellm_kwargs.py b/tests/providers/test_litellm_kwargs.pysimilarity index 100%rename from tests/test_litellm_kwargs.pyrename to tests/providers/test_litellm_kwargs.pydiff --git a/tests/test_mistral_provider.py b/tests/providers/test_mistral_provider.pysimilarity index 100%rename from tests/test_mistral_provider.pyrename to tests/providers/test_mistral_provider.pydiff --git a/tests/test_provider_retry.py b/tests/providers/test_provider_retry.pysimilarity index 100%rename from tests/test_provider_retry.pyrename to tests/providers/test_provider_retry.pydiff --git a/tests/test_providers_init.py b/tests/providers/test_providers_init.pysimilarity index 100%rename from tests/test_providers_init.pyrename to tests/providers/test_providers_init.pydiff --git a/tests/test_security_network.py b/tests/security/test_security_network.pysimilarity index 100%rename from tests/test_security_network.pyrename to tests/security/test_security_network.pydiff --git a/tests/test_exec_security.py b/tests/tools/test_exec_security.pysimilarity index 100%rename from tests/test_exec_security.pyrename to tests/tools/test_exec_security.pydiff --git a/tests/test_filesystem_tools.py b/tests/tools/test_filesystem_tools.pysimilarity index 100%rename from tests/test_filesystem_tools.pyrename to tests/tools/test_filesystem_tools.pydiff --git a/tests/test_mcp_tool.py b/tests/tools/test_mcp_tool.pysimilarity index 100%rename from tests/test_mcp_tool.pyrename to tests/tools/test_mcp_tool.pydiff --git a/tests/test_message_tool.py b/tests/tools/test_message_tool.pysimilarity index 100%rename from tests/test_message_tool.pyrename to tests/tools/test_message_tool.pydiff --git a/tests/test_message_tool_suppress.py b/tests/tools/test_message_tool_suppress.pysimilarity index 100%rename from tests/test_message_tool_suppress.pyrename to tests/tools/test_message_tool_suppress.pydiff --git a/tests/test_tool_validation.py b/tests/tools/test_tool_validation.pysimilarity index 100%rename from tests/test_tool_validation.pyrename to tests/tools/test_tool_validation.pydiff --git a/tests/test_web_fetch_security.py b/tests/tools/test_web_fetch_security.pysimilarity index 100%rename from tests/test_web_fetch_security.pyrename to tests/tools/test_web_fetch_security.pydiff --git a/tests/test_web_search_tool.py b/tests/tools/test_web_search_tool.pysimilarity index 100%rename from tests/test_web_search_tool.pyrename to tests/tools/test_web_search_tool.py