Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

test: fix test isolation and compatibility issues#5404

Open
whatevertogo wants to merge 6 commits intoAstrBotDevs:masterfrom
whatevertogo:fix/test-plugin-manager-compatibility
Open

test: fix test isolation and compatibility issues#5404
whatevertogo wants to merge 6 commits intoAstrBotDevs:masterfrom
whatevertogo:fix/test-plugin-manager-compatibility

Conversation

@whatevertogo
Copy link
Contributor

@whatevertogo whatevertogo commented Feb 24, 2026

Summary

  • Fix test isolation issues in plugin_manager tests
  • Fix version comparison and path assertions for Windows
  • Add missing apscheduler.triggers mock modules
  • Update assertion for new interrupt behavior
  • Use unique session IDs to avoid test conflicts

Test plan

  • Run full test suite: 314 passed

🤖 Generated with Claude Code

Summary by Sourcery

在插件管理器、API Key、环境、冒烟测试和工具运行器等测试中,提高测试隔离性、可靠性以及跨平台兼容性。

Bug 修复:

  • 确保插件管理器测试在完全隔离的临时数据根目录中运行,并清理模块缓存和全局注册表。
  • 通过模拟插件更新器并使用本地测试插件,避免在插件安装/更新测试中访问外部网络。
  • 在 OpenAPI 聊天/会话测试中为每种场景使用唯一的创建者/会话标识符,以防止测试冲突。
  • 通过放宽对硬编码路径的预期,使环境设置测试在不同操作系统上更健壮。
  • 通过模拟流水线所需的附加 apscheduler 触发器模块,稳定冒烟测试。
  • 将工具循环代理运行器的预期与新的中断行为对齐:用中断消息替代部分补全结果。
Original summary in English

Summary by Sourcery

Improve test isolation, reliability, and cross-platform compatibility across plugin manager, API key, environment, smoke, and tool runner tests.

Bug Fixes:

  • Ensure plugin manager tests run in a fully isolated temporary data root with cleaned module cache and global registries.
  • Avoid external network access in plugin install/update tests by mocking the plugin updater and using a local test plugin.
  • Prevent test conflicts in OpenAPI chat/session tests by using unique creator/session identifiers per scenario.
  • Make environment setup tests robust across operating systems by loosening hard-coded path expectations.
  • Stabilize smoke tests by mocking additional apscheduler trigger modules required by the pipeline.
  • Align tool loop agent runner expectations with the new interrupt behavior that replaces partial completions with an interruption message.

whatevertogo and others added 2 commits February 24, 2026 17:08
- 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 <[email protected]>
- 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 <[email protected]>
@auto-assign auto-assign bot requested review from Soulter and anka-afk February 24, 2026 09:35
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 24, 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 primarily focuses on enhancing the robustness and reliability of the test suite. It addresses several issues related to test isolation, ensuring that individual tests do not interfere with each other's state. Additionally, it improves cross-platform compatibility, particularly for Windows, and updates tests to align with recent changes in system behavior, such as how interrupted processes are reported. The overall goal is to create a more stable and predictable testing environment.

Highlights

  • Improved Test Isolation for Plugin Manager: Refactored the plugin_manager test fixture to ensure better isolation between tests by clearing module caches and global registries, and using temporary directories more effectively. This prevents test interference and makes tests more reliable.
  • Enhanced Cross-Platform Compatibility: Addressed compatibility issues, particularly for Windows environments, by modifying version comparison logic to handle tuples and updating path assertions to use os.path.join for platform-agnostic path matching.
  • Added Missing APScheduler Mocks: Included necessary mock modules for apscheduler.triggers.cron and apscheduler.triggers.date to stabilize pipeline import tests.
  • Updated Interrupt Behavior Assertion: Adjusted an assertion in test_tool_loop_agent_runner.py to reflect the new system message returned when an agent runner is interrupted, ensuring tests correctly validate this behavior.
  • Unique Session IDs in API Key Tests: Modified API key related tests to use unique session IDs and creator names, preventing conflicts and improving the reliability of concurrent or sequential test runs.
Changelog
  • tests/test_api_key_open_api.py
    • Updated usernames and creator names in API key tests to include unique suffixes, preventing test conflicts.
  • tests/test_main.py
    • Added __eq__ and __ge__ methods to _version_info for more flexible version comparisons.
    • Modified os.makedirs assertions to use os.path.join and endswith for cross-platform path validation.
  • tests/test_plugin_manager.py
    • Refactored plugin_manager_pm fixture to use pytest_asyncio and tmp_path for better test isolation and asynchronous setup/teardown.
    • Introduced _clear_module_cache and _clear_registry helper functions to ensure clean state between plugin manager tests.
    • Added _write_local_test_plugin to create mock plugin files for local testing without network access.
    • Created local_updator fixture to mock plugin installation and update processes.
    • Updated plugin installation, update, and uninstallation tests to utilize the new local mocking infrastructure and improved isolation mechanisms.
    • Expanded Context initialization to explicitly pass keyword arguments and include cron_manager and subagent_orchestrator mocks.
  • tests/test_smoke.py
    • Added mocks for apscheduler.triggers.cron and apscheduler.triggers.date to test_pipeline_import_is_stable_with_mocked_apscheduler.
  • tests/test_tool_loop_agent_runner.py
    • Updated assertion for completion_text in test_stop_signal_returns_aborted_and_persists_partial_message to check for 'interrupted' message.
Activity
  • The full test suite was run, with 314 tests passing, indicating no regressions and successful integration of the changes.
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 24, 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

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

Hey - 我发现了 1 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_main.py" line_range="19-27" />
<code_context>
         self.major = major
         self.minor = minor

+    def __eq__(self, other):
+        if isinstance(other, tuple):
+            return (self.major, self.minor) == other[:2]
+        return (self.major, self.minor) == (other.major, other.minor)
+
+    def __ge__(self, other):
+        if isinstance(other, tuple):
+            return (self.major, self.minor) >= other[:2]
+        return (self.major, self.minor) >= (other.major, other.minor)
+

</code_context>
<issue_to_address>
**suggestion (testing):**_version_info 与元组和实例之间的比较添加单元级检查

这些 `__eq__``__ge__` 方法目前只通过 `test_check_env` 间接覆盖。请添加一个有针对性的测试(例如 `test_version_info_comparisons`),直接验证它们与元组和 `_version_info` 实例之间的比较行为,包括:

- `_version_info(3, 10) >= (3, 10)``== (3, 10)`
- `_version_info(3, 9) >= (3, 10)``False`
- `_version_info(3, 10) >= _version_info(3, 10)` 以及类似的实例对实例比较。

这样即使以后 `check_env` 发生变更,也能稳固这些比较语义。
</issue_to_address>

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_main.py" line_range="19-27" />
<code_context>
         self.major = major
         self.minor = minor

+    def __eq__(self, other):
+        if isinstance(other, tuple):
+            return (self.major, self.minor) == other[:2]
+        return (self.major, self.minor) == (other.major, other.minor)
+
+    def __ge__(self, other):
+        if isinstance(other, tuple):
+            return (self.major, self.minor) >= other[:2]
+        return (self.major, self.minor) >= (other.major, other.minor)
+

</code_context>
<issue_to_address>
**suggestion (testing):** Add unit-level checks for _version_info comparisons against tuples and instances

These `__eq__` and `__ge__` methods are currently only covered indirectly via `test_check_env`. Please add a focused test (e.g. `test_version_info_comparisons`) that directly exercises comparisons against both tuples and `_version_info` instances, including:

- `_version_info(3, 10) >= (3, 10)` and `== (3, 10)`
- `_version_info(3, 9) >= (3, 10)` is `False`
- `_version_info(3, 10) >= _version_info(3, 10)` and similar instance-to-instance comparisons.

This will anchor the comparison semantics even if `check_env` changes later.
</issue_to_address>

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 feature:plugin The bug / feature is about AstrBot plugin system. label Feb 24, 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

This pull request introduces a series of valuable improvements to the test suite, focusing on enhancing test isolation, reliability, and cross-platform compatibility. The changes are well-executed and address several important testing concerns.

Key improvements include:

  • Test Isolation: The use of unique session and creator IDs in test_api_key_open_api.py effectively prevents test conflicts. The major refactoring of test_plugin_manager.py is particularly noteworthy, introducing a fully isolated environment for plugin tests by mocking network-dependent operations and ensuring proper cleanup of modules and global registries.
  • Cross-Platform Compatibility: The updates in test_main.py to use os.path.join for path assertions make the tests more robust and able to run on different operating systems like Windows.
  • Test Reliability: Mocking missing apscheduler.triggers in test_smoke.py and updating assertions in test_tool_loop_agent_runner.py to match new application behavior contribute to a more stable and reliable test suite.

Overall, these changes significantly improve the quality of the tests. The code is clean, and the approach to improving test isolation is excellent. I have no further comments. Great work!

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 24, 2026
@whatevertogo
Copy link
Contributor Author

已经和PR#5357合并

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:plugin The bug / feature is about AstrBot plugin system. size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant