Skip to content

test: add comprehensive tests for core lifecycle and agent execution#5357

Open
whatevertogo wants to merge 4 commits intoAstrBotDevs:masterfrom
whatevertogo:test/core-lifecycle-agent
Open

test: add comprehensive tests for core lifecycle and agent execution#5357
whatevertogo wants to merge 4 commits intoAstrBotDevs:masterfrom
whatevertogo:test/core-lifecycle-agent

Conversation

@whatevertogo
Copy link
Contributor

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 / 改动点

  • Added tests/unit/test_core_lifecycle.py testing initialization and shutdown
  • Added tests/unit/test_astr_main_agent.py with extensive agent execution tests
  • Added tests/unit/test_computer.py for computer use functionality
  • Enhanced event bus tests in tests/unit/test_event_bus.py
  • Fixed issues in astrbot/core/core_lifecycle.py, astrbot/core/astr_main_agent.py, and astrbot/core/event_bus.py

Test 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 / 运行截图或测试结果

# Verification: Core lifecycle tests pass
$ pytest tests/unit/test_core_lifecycle.py -v
...
collected 8 items

tests/unit/test_core_lifecycle.py::TestCoreLifecycle::test_initialization PASSED
tests/unit/test_core_lifecycle.py::TestCoreLifecycle::test_reset PASSED
tests/unit/test_core_lifecycle.py::TestCoreLifecycle::test_event_handling PASSED
...

# Verification: Main agent tests pass
$ pytest tests/unit/test_astr_main_agent.py -v
...
collected 15 items

# Verification: Computer tests pass
$ pytest tests/unit/test_computer.py -v
...
collected 10 items

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

- 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>
Copilot AI review requested due to automatic review settings February 23, 2026 00:57
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @whatevertogo, your pull request is larger than the review limit of 150000 diff characters

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Feb 23, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Enhanced Robustness for Webchat Title Generation: Implemented error handling for webchat conversation title generation, ensuring that failures in LLM calls are caught and logged without disrupting the application flow.
  • Improved System Prompt Handling in Sandbox Mode: Adjusted the logic for appending sandbox mode prompts to system prompts, making it more resilient to initially empty or None system prompt values.
  • Refactored Plugin Manager Import: Updated the import path for PluginManager to reflect a more organized module structure within the astrbot.core.star package.
  • Strengthened Event Bus Configuration Validation: Added comprehensive validation and fallback mechanisms for configuration information within the event bus, preventing issues from incomplete or invalid configuration data.
  • Comprehensive Unit Test Coverage: Introduced extensive unit tests across core components including astr_main_agent, core_lifecycle, computer module functionalities, and event_bus, significantly improving test coverage and system stability.
Changelog
  • astrbot/core/astr_main_agent.py
    • Added try-except block around LLM call for webchat title generation to gracefully handle exceptions and log errors.
    • Modified _apply_sandbox_tools to safely append SANDBOX_MODE_PROMPT to req.system_prompt, handling cases where req.system_prompt might be None.
  • astrbot/core/core_lifecycle.py
    • Updated import statement for PluginManager to astrbot.core.star.star_manager.
  • astrbot/core/event_bus.py
    • Added validation to ensure conf_info is a dictionary and contains an 'id' before processing.
    • Improved conf_name retrieval by falling back to string representation of conf_id if 'name' is missing.
    • Updated error logging to use conf_id when a PipelineScheduler is not found.
  • tests/unit/test_astr_main_agent.py
    • Added new file with comprehensive unit tests for astr_main_agent module, covering configuration, provider selection, conversation management, knowledge base, file extraction, persona/skills, LLM request decoration, modality fixes, plugin tools, agent building, webchat title handling, LLM safety, and sandbox tools.
  • tests/unit/test_computer.py
    • Added new file with comprehensive unit tests for the computer module, including LocalBooter, security restrictions, LocalShellComponent, LocalPythonComponent, LocalFileSystemComponent, ComputerBooter base class, ShipyardBooter, BoxliteBooter, and ComputerClient.
  • tests/unit/test_core_lifecycle.py
    • Added new file with comprehensive unit tests for AstrBotCoreLifecycle, covering initialization, proxy settings, task management, platform loading, error handling, component setup, migration failures, start/stop operations, and pipeline scheduler management.
  • tests/unit/test_event_bus.py
    • Added new file with comprehensive unit tests for the EventBus module, covering initialization, event dispatching, missing schedulers, multiple events, incomplete config info, name fallbacks, event printing, subscription, and filtering.
Activity
  • whatevertogo opened this pull request with the title 'test: add comprehensive tests for core lifecycle and agent execution'.
  • whatevertogo provided a detailed description outlining the motivation to improve test coverage for core system components.
  • whatevertogo listed specific modifications, including the addition of new unit test files for core lifecycle, main agent execution, and computer use functionality.
  • whatevertogo also noted enhancements to existing event bus tests and fixes in several core Python files.
  • whatevertogo included verification steps with pytest output demonstrating that the new tests pass for lifecycle, main agent, and computer functionalities.
  • whatevertogo confirmed that the changes are not breaking and that new dependencies are handled appropriately.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot
Copy link

dosubot bot commented Feb 23, 2026

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Feb 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

whatevertogo and others added 3 commits February 24, 2026 10:37
refactor(tests): 移除测试文件中的循环导入注释
refactor(tests): 优化计算机客户端测试,简化不可用引导程序的处理逻辑
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants