test: refactor and enhance P1 platform adapter tests#5358
test: refactor and enhance P1 platform adapter tests#5358whatevertogo wants to merge 5 commits intoAstrBotDevs:masterfrom
Conversation
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 significantly enhances the maintainability and reliability of the P1 platform adapters for Telegram, Discord, and Aiocqhttp. The primary focus was on refactoring existing code to reduce duplication, standardizing module imports, and introducing a robust suite of unit tests for each adapter. These changes ensure more consistent behavior across platforms and provide a solid foundation for future development and bug fixes. 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.
Code Review
This pull request is a significant improvement, introducing comprehensive unit tests for the Aiocqhttp, Discord, and Telegram platform adapters. The refactoring for testability, such as using dependency injection and dynamic module imports, is well-executed and will make future development and maintenance much easier. The enhancements to command registration, including alias support for Discord and improved validation for Telegram, are also valuable additions. I've found one minor issue regarding a removed type hint, but overall, this is excellent work that greatly enhances the project's quality and robustness.
There was a problem hiding this comment.
Pull request overview
Refactors and extends unit tests for P1 platform adapters (Telegram, Discord, aiocqhttp/OneBot v11) and makes a few small adapter changes to improve command registration behavior and robustness of message handling.
Changes:
- Refactored/expanded adapter unit tests to use shared helper + mock modules (intended to reduce duplication).
- Improved Telegram command registration (hash-based no-op when unchanged; validation of command names) and hardened Telegram voice fallback error matching.
- Improved Discord slash command registration to expand aliases and ignore duplicates; improved aiocqhttp bot creation testability and image segment URL handling.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_telegram_adapter.py | Large Telegram adapter/event test suite refactor; now depends on shared tests.fixtures.* helpers/mocks. |
| tests/unit/test_discord_adapter.py | Discord adapter tests refactor; now depends on shared tests.fixtures.* helpers/mocks. |
| tests/unit/test_aiocqhttp_adapter.py | aiocqhttp adapter/event tests refactor; now depends on shared tests.fixtures.* helpers/mocks. |
| astrbot/core/platform/sources/telegram/tg_event.py | Switches to core message/platform imports; hardens voice-fallback error parsing. |
| astrbot/core/platform/sources/telegram/tg_adapter.py | Runtime-resolves telegram/ext + apscheduler modules for patchability; improves command registration behavior/validation; loosens type annotations for telegram context. |
| astrbot/core/platform/sources/discord/discord_platform_adapter.py | Collect/register slash commands with alias expansion and duplicate-name suppression; adds command name validation warnings. |
| astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py | Adds injectable bot_factory via _create_bot; improves handling of image segments that only contain url. |
| astrbot/core/platform/sources/aiocqhttp/aiocqhttp_message_event.py | Switches to core imports and aiocqhttp.* type references. |
astrbot/core/platform/sources/discord/discord_platform_adapter.py
Outdated
Show resolved
Hide resolved
- Refactor Telegram adapter tests to use shared mocks - Refactor Discord adapter tests to use shared mocks - Refactor Aiocqhttp adapter tests to use shared mocks - Fix sender name handling and command registration Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
c332667 to
38cc597
Compare
Refactor and enhance tests for P1 platform adapters (Telegram, Discord, Aiocqhttp) using shared mock utilities to reduce code duplication and improve maintainability.
Modifications / 改动点
tests/unit/test_telegram_adapter.pyto use shared mocks (~200 lines removed)tests/unit/test_discord_adapter.pyto use shared mocks (~120 lines removed)tests/unit/test_aiocqhttp_adapter.pyto use shared mocks (~50 lines removed)Benefits:
Reduced code duplication by ~370 lines
Easier to maintain with centralized mock utilities
Consistent testing patterns across platforms
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.