test: add comprehensive tests for core lifecycle and agent execution#5357
test: add comprehensive tests for core lifecycle and agent execution#5357whatevertogo wants to merge 4 commits intoAstrBotDevs:masterfrom
Conversation
- Add core lifecycle unit tests - Add main agent execution tests - Add computer use tests - Enhance event bus tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Sorry @whatevertogo, your pull request is larger than the review limit of 150000 diff characters
Summary of ChangesHello @whatevertogo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the stability and testability of the core system components. It introduces robust error handling for critical operations like webchat title generation and refines system prompt management. A major part of this change involves adding comprehensive unit tests for the main agent's execution flow, the application's lifecycle management, computer interaction functionalities, and the event bus, ensuring that these foundational elements are thoroughly validated and more resilient to potential issues. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Pull request overview
This pull request adds comprehensive unit tests for critical core components of AstrBot while also including important bug fixes for reliability and error handling. The changes significantly improve test coverage for the core system components: lifecycle management, main agent execution, computer use functionality, and event bus operations.
Changes:
- Adds 4 comprehensive test files (4,042 lines) covering core lifecycle, agent execution, computer use, and event bus
- Fixes defensive programming issues in event bus to handle malformed configuration data
- Fixes null safety issue in sandbox tools system prompt concatenation
- Fixes exception handling in webchat title generation
- Updates import path for PluginManager for consistency
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_event_bus.py | New comprehensive test suite (738 lines) for EventBus dispatch, event handling, subscription, and filtering |
| tests/unit/test_core_lifecycle.py | New comprehensive test suite (875 lines) for AstrBotCoreLifecycle initialization, start/stop, error handling, and pipeline scheduler |
| tests/unit/test_computer.py | New comprehensive test suite (893 lines) for computer use functionality including LocalBooter, security restrictions, and file operations |
| tests/unit/test_astr_main_agent.py | New comprehensive test suite (1535 lines) for main agent building, configuration, tool execution, and edge cases |
| astrbot/core/event_bus.py | Adds defensive checks for conf_info dict validation and handles missing id/name keys gracefully |
| astrbot/core/core_lifecycle.py | Updates PluginManager import path from package to direct module import for consistency |
| astrbot/core/astr_main_agent.py | Adds exception handling for webchat title generation and fixes null safety in system prompt concatenation |
There was a problem hiding this comment.
Code Review
This pull request significantly improves test coverage by adding comprehensive unit tests for core components like astr_main_agent, core_lifecycle, computer, and event_bus. It also includes bug fixes in astr_main_agent and event_bus to handle potential None values and exceptions gracefully. A critical prompt injection vulnerability was identified in the _handle_webchat function, where untrusted user input is directly embedded into an LLM prompt, potentially allowing attackers to manipulate session titles and lead to XSS. Additionally, one test case was found to be missing assertions, and minor log injection issues were noted as low severity.
refactor(tests): 移除测试文件中的循环导入注释 refactor(tests): 优化计算机客户端测试,简化不可用引导程序的处理逻辑
Add comprehensive unit tests for core lifecycle management, main agent execution, and computer use functionality to significantly improve test coverage for core system components.
Modifications / 改动点
tests/unit/test_core_lifecycle.pytesting initialization and shutdowntests/unit/test_astr_main_agent.pywith extensive agent execution teststests/unit/test_computer.pyfor computer use functionalitytests/unit/test_event_bus.pyastrbot/core/core_lifecycle.py,astrbot/core/astr_main_agent.py, andastrbot/core/event_bus.pyTest Coverage:
Lifecycle: initialization, reset, event handling
Agent: tool execution, context management, error handling
Computer: browser actions, screenshots, file operations
Event Bus: subscription, publishing, filtering
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.