Skip to content

test: add tests for star base class and config management#5356

Open
whatevertogo wants to merge 14 commits intoAstrBotDevs:masterfrom
whatevertogo:test/core-star-config
Open

test: add tests for star base class and config management#5356
whatevertogo wants to merge 14 commits intoAstrBotDevs:masterfrom
whatevertogo:test/core-star-config

Conversation

@whatevertogo
Copy link
Contributor

@whatevertogo whatevertogo commented Feb 23, 2026

Add unit tests for the Star base class safety helpers and expand configuration management test coverage to improve reliability of the plugin system and configuration handling.

Modifications / 改动点

  • Added tests/unit/test_star_base.py testing text_to_image safety helpers

  • Expanded tests/unit/test_config.py with additional test scenarios

  • Updated cron manager tests in tests/unit/test_cron_manager.py

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

# Verification: Star base class tests pass
$ pytest tests/unit/test_star_base.py -v
...
collected 3 items

tests/unit/test_star_base.py::TestStarBase::test_text_to_image_with_config PASSED
tests/unit/test_star_base.py::TestStarBase::test_text_to_image_without_config PASSED
tests/unit/test_star_base.py::TestStarBase::test_html_render PASSED

# Verification: Config tests pass
$ pytest tests/unit/test_config.py -v
...
collected 12 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.

由 Sourcery 提供的总结

为配置处理、定时任务管理(cron job),以及 Star 基类安全辅助工具添加了全面的单元测试,以增强这些子系统的可靠性。

Tests:

  • 为 AstrBotConfig 的加载、校验、模式(schema)转换、热重载行为,以及国际化(i18n)元数据工具添加了大量测试。
  • 为 CronJobManager 添加了单元测试,覆盖生命周期管理、任务创建/更新/删除、调度以及执行路径。
  • 为 Star 基类的文本转图片(text-to-image)辅助函数添加测试,以验证在上下文配置和模板选择方面的安全处理。
Original summary in English

Summary by Sourcery

Add comprehensive unit tests for configuration handling, cron job management, and Star base class safety helpers to strengthen reliability of these subsystems.

Tests:

  • Add extensive tests for AstrBotConfig loading, validation, schema conversion, hot reload behaviour, and i18n metadata utilities.
  • Add unit tests for CronJobManager covering lifecycle management, job creation/update/deletion, scheduling, and execution paths.
  • Add tests for the Star base class text-to-image helper to verify safe handling of context configuration and template selection.

- Add Star base class safety helper tests
- Expand config management unit tests
- Update cron manager tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 23, 2026 00:56
@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 enhances the reliability and robustness of the system by introducing a suite of new and expanded unit tests. The changes primarily focus on critical components such as the Star base class's safety features, the core configuration management system, and the cron job scheduling mechanism. This ensures that these foundational elements behave as expected under various conditions, improving overall system stability and maintainability.

Highlights

  • New Unit Tests for Star Base Class: Added dedicated unit tests for the Star base class, focusing on the text_to_image safety helpers and their interaction with context configurations.
  • Expanded Configuration Management Test Coverage: Significantly increased test coverage for the configuration management module, including AstrBotConfig loading, validation, hot-reloading, schema conversion, and internationalization utilities (ConfigMetadataI18n).
  • Comprehensive Cron Manager Tests: Introduced extensive unit tests for the CronJobManager, covering its initialization, lifecycle management (start/shutdown), job creation, updates, deletion, listing, database synchronization, and job scheduling/execution.
Changelog
  • tests/unit/test_config.py
    • Added comprehensive unit tests for configuration management, including AstrBotConfig loading, validation, hot-reloading, schema conversion, and ConfigMetadataI18n utilities.
  • tests/unit/test_cron_manager.py
    • Added extensive unit tests for the CronJobManager, covering its lifecycle, job management, and scheduling functionalities.
  • tests/unit/test_star_base.py
    • Added unit tests for the Star base class, specifically verifying the text_to_image method's handling of context configuration.
Activity
  • The author provided verification steps and test results, demonstrating that the newly added and expanded tests pass successfully.
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.

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.

嗨——我已经审查了你的改动,看起来非常棒!


Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,请考虑分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Feb 23, 2026
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

The pull request introduces new unit tests for the Star base class safety helpers and expands configuration management test coverage. The new tests cover AstrBotConfig loading, validation, hot reload, schema conversion, and ConfigMetadataI18n utilities. Additionally, CronJobManager tests have been updated. The changes improve the reliability of the plugin system and configuration handling. The tests are well-structured and cover various scenarios, including edge cases like missing configuration items and invalid timezones. Overall, the changes are positive and enhance the robustness of the codebase.

@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

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 unit tests to improve the reliability of the plugin system and configuration handling in AstrBot. The PR introduces comprehensive test coverage for the CronJobManager, expands configuration management tests with additional edge cases, and attempts to add tests for the Star base class's text_to_image method.

Changes:

  • Added comprehensive unit tests for CronJobManager covering job lifecycle, scheduling, execution, and error handling
  • Expanded AstrBotConfig tests with validation, hot-reload, schema conversion, and i18n utilities
  • Attempted to add tests for Star base class text_to_image method (but contains critical bugs)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
tests/unit/test_star_base.py NEW: Attempts to test Star.text_to_image safety helpers, but contains critical import and implementation bugs
tests/unit/test_cron_manager.py NEW: Comprehensive test suite for CronJobManager with 503 lines covering initialization, job management, scheduling, and execution
tests/unit/test_config.py NEW: Extensive test suite (607 lines) for AstrBotConfig covering loading, validation, hot-reload, schema conversion, and i18n utilities

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 23, 2026
whatevertogo and others added 9 commits February 24, 2026 10:37
- Use local mock plugin instead of real network requests
- Clear sys.modules cache for entire data module tree
- Clear star_map and star_registry in teardown
- Use pytest_asyncio.fixture for async fixture support

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- test_main.py: fix version comparison and path assertions for Windows
- test_smoke.py: add missing apscheduler.triggers mock modules
- test_tool_loop_agent_runner.py: update assertion for new interrupt behavior
- test_api_key_open_api.py: use unique session IDs to avoid test conflicts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: resolve pipeline and star import cycles

- Add bootstrap.py and stage_order.py to break circular dependencies
- Export Context, PluginManager, StarTools from star module
- Update pipeline __init__ to defer imports
- Split pipeline initialization into separate bootstrap module

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: add logging for get_config() failure in Star class

* fix: reorder logger initialization in base.py

---------

Co-authored-by: whatevertogo <whatevertogo@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Member

@Dt8333 Dt8333 left a comment

Choose a reason for hiding this comment

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

(怎么感觉看到了许多已经合并的代码)

个人还是希望项目中少点Any。
尽量把类型写清楚些,对人和静态检查都好些()

whatevertogo and others added 4 commits February 26, 2026 10:35
- Add tests for Star class initialization and context handling
- Add tests for text_to_image with/without config
- Add tests for html_render method
- Add tests for initialize/terminate lifecycle methods
- Add type hint validation tests for Context
- Add circular import prevention tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- pipeline/context.py: Use TYPE_CHECKING to import PluginManager instead of Any
- pipeline/__init__.py: Add TYPE_CHECKING imports for __all__ exports to satisfy static analyzers
- star/register/star_handler.py: Use TYPE_CHECKING to import AstrAgentContext instead of Any
- tests: Remove invalid type hint tests that tested incorrect assumptions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…patibility

Merge test improvements from fix/test-plugin-manager-compatibility branch.
Resolved conflicts by keeping TYPE_CHECKING imports (per PR review feedback).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- star/register/star_handler.py: Use AstrAgentContext instead of Any in generic types
- star/context.py: Remove unnecessary else branch with CronJobManager = Any
  (with __future__ annotations, TYPE_CHECKING imports are sufficient)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants