-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(channels): skip empty text blocks in DingTalk rich text parsing #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xieyxclack
merged 2 commits into
agentscope-ai:main
from
mvanhorn:osc/1303-dingtalk-rich-text-empty-blocks
Mar 16, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # -*- coding: utf-8 -*- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """Tests for DingTalk rich text parsing - empty text blocks must be skipped.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from copaw.app.channels.dingtalk.handler import DingTalkChannelHandler | ||
|
|
||
|
|
||
| def _make_handler() -> DingTalkChannelHandler: | ||
| """Create a handler with stubbed dependencies.""" | ||
| import asyncio | ||
|
|
||
| loop = asyncio.new_event_loop() | ||
| handler = DingTalkChannelHandler( | ||
| main_loop=loop, | ||
| enqueue_callback=None, | ||
| bot_prefix="", | ||
| download_url_fetcher=MagicMock(), | ||
| ) | ||
| return handler | ||
|
|
||
|
|
||
| def _make_incoming(rich_text_items: list) -> MagicMock: | ||
| """Build a mock incoming_message with richText content.""" | ||
| msg = MagicMock() | ||
| msg.robot_code = "test_robot" | ||
| msg.to_dict.return_value = {"content": {"richText": rich_text_items}} | ||
| return msg | ||
|
|
||
|
|
||
| class TestParseRichContent: | ||
| """Verify _parse_rich_content filters empty text blocks.""" | ||
|
|
||
| def test_empty_text_items_are_skipped(self) -> None: | ||
| handler = _make_handler() | ||
| items = [ | ||
| {"text": ""}, | ||
| {"text": " "}, | ||
| {"content": ""}, | ||
| {"content": None}, | ||
| ] | ||
| result = handler._parse_rich_content(_make_incoming(items)) | ||
| text_parts = [p for p in result if hasattr(p, "text")] | ||
| assert ( | ||
| len(text_parts) == 0 | ||
| ), f"Expected no TextContent blocks, got {text_parts}" | ||
|
|
||
| def test_valid_text_items_are_kept(self) -> None: | ||
| handler = _make_handler() | ||
| items = [ | ||
| {"text": "hello"}, | ||
| {"text": " world "}, | ||
| ] | ||
| result = handler._parse_rich_content(_make_incoming(items)) | ||
| text_parts = [p for p in result if hasattr(p, "text")] | ||
| assert len(text_parts) == 2 | ||
| assert text_parts[0].text == "hello" | ||
| assert text_parts[1].text == "world" | ||
|
|
||
| def test_mixed_empty_and_valid(self) -> None: | ||
| handler = _make_handler() | ||
| items = [ | ||
| {"text": ""}, | ||
| {"text": "keep this"}, | ||
| {"text": " "}, | ||
| {"content": "also keep"}, | ||
| ] | ||
| result = handler._parse_rich_content(_make_incoming(items)) | ||
| text_parts = [p for p in result if hasattr(p, "text")] | ||
| assert len(text_parts) == 2 | ||
| assert text_parts[0].text == "keep this" | ||
| assert text_parts[1].text == "also keep" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.