-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: keep inline Face components in the same bubble during segmented reply #10049
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
Open
Shxiao101
wants to merge
5
commits into
AstrBotDevs:master
Choose a base branch
from
Shxiao101:fix/10047-segmented-inline-grouping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−10
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e606a30
fix: keep inline Face components in the same bubble during segmented …
Shxiao101 afa4224
test: count bubble word count per Plain component to fix flaky interv…
Shxiao101 9623682
refactor: attach Face to the adjacent text bubble instead of merging …
Shxiao101 2da0ca9
refactor: treat an inline Face as glue between its neighboring text b…
Shxiao101 c8fa963
chore: re-trigger unit test CI after macOS runner flake
Shxiao101 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| """Regression tests for segmented reply bubble grouping (#10047). | ||
|
|
||
| With segmented reply enabled, every component used to be sent as its own | ||
| message, so an inline Face in the middle of a sentence split the text into | ||
| several bubbles. The stage now treats an inline Face as glue: it attaches to | ||
| the preceding text bubble and keeps the following Plain in the same bubble, | ||
| while adjacent Plain components from the segmentation-words feature (#3959) | ||
| keep their deliberate split. | ||
| """ | ||
|
|
||
| import math | ||
|
|
||
| import pytest | ||
|
|
||
| import astrbot.core.message.components as Comp | ||
| from astrbot.core.pipeline.respond.stage import RespondStage | ||
|
|
||
|
|
||
| def test_inline_face_glues_the_whole_sentence_into_one_bubble(): | ||
| stage = RespondStage() | ||
| chain = [ | ||
| Comp.Plain(text="好的"), | ||
| Comp.Face(id=277), | ||
| Comp.Plain(text=",我知道了!"), | ||
| ] | ||
|
|
||
| segments = stage._group_segment_chain(chain) | ||
|
|
||
| assert segments == [chain] | ||
|
|
||
|
|
||
| def test_leading_face_joins_the_following_text_bubble(): | ||
| stage = RespondStage() | ||
| face = Comp.Face(id=277) | ||
| chain = [face, Comp.Plain(text="你好呀")] | ||
|
|
||
| segments = stage._group_segment_chain(chain) | ||
|
|
||
| assert segments == [[face, chain[1]]] | ||
|
|
||
|
|
||
| def test_adjacent_plain_components_keep_separate_bubbles(): | ||
| stage = RespondStage() | ||
| first = Comp.Plain(text="第一段。") | ||
| second = Comp.Plain(text="第二段。") | ||
|
|
||
| segments = stage._group_segment_chain([first, second]) | ||
|
|
||
| assert segments == [[first], [second]] | ||
|
|
||
|
|
||
| def test_components_that_need_separate_sending_stay_alone(): | ||
| stage = RespondStage() | ||
| record = Comp.Record(file="file:///tmp/a.wav") | ||
| chain = [Comp.Plain(text="看这个"), record, Comp.Plain(text="好听吗")] | ||
|
|
||
| segments = stage._group_segment_chain(chain) | ||
|
|
||
| assert segments == [[chain[0]], [record], [chain[2]]] | ||
|
|
||
|
|
||
| def test_face_after_media_stays_its_own_bubble(): | ||
| stage = RespondStage() | ||
| record = Comp.Record(file="file:///tmp/a.wav") | ||
| face = Comp.Face(id=277) | ||
| chain = [Comp.Plain(text="听"), record, face] | ||
|
|
||
| segments = stage._group_segment_chain(chain) | ||
|
|
||
| assert segments == [[chain[0]], [record], [face]] | ||
|
|
||
|
|
||
| def test_face_glue_does_not_absorb_media(): | ||
| stage = RespondStage() | ||
| record = Comp.Record(file="file:///tmp/a.wav") | ||
| chain = [Comp.Plain(text="好的"), Comp.Face(id=277), record] | ||
|
|
||
| segments = stage._group_segment_chain(chain) | ||
|
|
||
| assert segments == [[chain[0], chain[1]], [record]] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_log_interval_for_a_bubble_uses_total_plain_word_count(): | ||
| stage = RespondStage() | ||
| stage.interval_method = "log" | ||
| stage.log_base = 10.0 | ||
|
|
||
| # "hello" + "world" -> 2 words -> log10(3) ~= 0.477 | ||
| bubble = await stage._calc_comp_interval( | ||
| [Comp.Plain(text="hello"), Comp.Face(id=277), Comp.Plain(text="world")], | ||
| ) | ||
| lower, upper = math.log(3, 10), math.log(3, 10) + 0.5 | ||
| assert lower <= bubble <= upper | ||
|
|
||
| # A bubble without text keeps the non-Plain interval. | ||
| face_only = await stage._calc_comp_interval(Comp.Face(id=277)) | ||
| assert 1 <= face_only <= 1.75 | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The grouped text is
"hello" + "world" = "helloworld", but_word_cntcounts unspaced ASCII text as 1 word (len(text.split())), so the interval is drawn from[log10(2), log10(2)+0.5] = [0.301, 0.801]while the test asserts>= log10(3) = 0.477— ~35% of runs fail (CI evidence: macOS job 103455275079,assert 0.47712125471966244 <= 0.30788529321914043; local repro 9/20 on Windows). Adding a trailing space makes it 2 words and the bounds deterministic:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good diagnosis, matches what we found. Rather than adjusting the test, the implementation now counts words per Plain component and sums them over the bubble (2da0ca9), so
hello+world= 2 words and the asserted bounds are exact — no trailing-space workaround needed.