Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(reply): parse quick replies without separator (#1367)

Call White1acfd0c971ef
diff --git a/core/message_dispatcher.py b/core/message_dispatcher.py
index 50cee776c..8719a6e66 100644
--- a/core/message_dispatcher.py
+++ b/core/message_dispatcher.py
@@ -2146,11 +2146,18 @@ class ConsolidatedMessageDispatcher:
return None
if current_runtime_turn or output_semantics.detached:
self._schedule_agent_run_activity(context, output_semantics)
+ quick_reply_target = routed_delivery_context(context)
raw_text = text
enhanced = None
if visible_output_type and level != "silent":
quick_replies_on = getattr(self.controller.config, "reply_enhancements", True)
- enhanced = process_reply(raw_text, include_quick_replies=quick_replies_on)
+ enhanced = process_reply(
+ raw_text,
+ include_quick_replies=quick_replies_on,
+ allow_unseparated_quick_replies=self._supports_quick_replies(
+ quick_reply_target
+ ),
+ )
text = enhanced.visible_text
else:
text = strip_silent_blocks(raw_text)
@@ -2452,6 +2459,9 @@ class ConsolidatedMessageDispatcher:
background_enhanced = process_reply(
raw_text,
include_quick_replies=quick_replies_on,
+ allow_unseparated_quick_replies=self._supports_quick_replies(
+ target_context
+ ),
keep_file_links=True,
)
persisted_output = persist_agent_message(
@@ -2863,7 +2873,12 @@ class ConsolidatedMessageDispatcher:
# render the button group (IM channels render native buttons
# from the same ``enhanced.buttons``).
avibe_enhanced = process_reply(
- raw_text, include_quick_replies=quick_replies_on, keep_file_links=True
+ raw_text,
+ include_quick_replies=quick_replies_on,
+ allow_unseparated_quick_replies=self._supports_quick_replies(
+ target_context
+ ),
+ keep_file_links=True,
)
persisted_output = persist_agent_message(
target_context,
diff --git a/core/reply_enhancer.py b/core/reply_enhancer.py
index 011a07e1c..bb81b1e23 100644
--- a/core/reply_enhancer.py
+++ b/core/reply_enhancer.py
@@ -8,8 +8,9 @@ Extracts special syntaxes from agent reply text:
2. **File links** – Markdown links whose URL starts with ``file://``
e.g. ``[screenshot](file:///tmp/shot.png)``
-3. **Quick-reply buttons** – A ``---`` separator followed by
- ``[button text]`` tokens separated by ``|``
+3. **Quick-reply buttons** – A trailing row of ``[button text]`` tokens
+ separated by ``|``. The preferred form starts with a ``---`` separator;
+ pipe-separated rows are also accepted without it for compatibility.
e.g. ``---\\n[👌好的] | [✅提交PR] | [先review一下]``
"""
@@ -293,6 +294,25 @@ _BUTTON_BLOCK_RE = re.compile(
r"\s*$", # trailing whitespace / end of string
)
+# Compatibility form for replies that omit the ``---`` line. Keep this more
+# restrictive than the preferred form: it must be one trailing line with at
+# least two tokens and an explicit pipe, so ordinary ``[bracketed text]`` and
+# reference links remain message content.
+_BUTTON_LINE_TOKEN = (
+ r"(?:\[[^\]\r\n]+\]"
+ + _LINK_SUFFIX
+ + r"|<https?://[^|>\r\n]+\|[^>\r\n]+>)"
+)
+_UNSEPARATED_BUTTON_ROW_RE = re.compile(
+ r"\r?\n"
+ r"([ \t]*"
+ + _BUTTON_LINE_TOKEN
+ + r"[ \t]*(?:[||][ \t]*"
+ + _BUTTON_LINE_TOKEN
+ + r"[ \t]*)+(?:[||][ \t]*)?)"
+ r"(?:\r?\n[ \t]*)*$"
+)
+
# Individual button tokens. Link variants are accepted for compatibility only;
# the bracket label (or Slack link text) remains the quick-reply payload.
_BUTTON_TOKEN_RE = re.compile(
@@ -306,6 +326,65 @@ _BUTTON_TOKEN_RE = re.compile(
# (Detection matches the whole block instead of scanning for ``|``, which a URL
# may itself contain.)
_PLAIN_LINKS_ONLY_RE = re.compile(r"(?:\s*\[[^\]]+\]\(" + _PLAIN_URL + r"\)\s*)+")
+_LINK_ONLY_BUTTON_ROW_RE = re.compile(
+ r"\s*(?:\[[^\]\r\n]+\]\((?:<https?://[^>\r\n]+>|"
+ + _PLAIN_URL
+ + r")\)|<https?://[^|>\r\n]+\|[^>\r\n]+>)\s*"
+ r"(?:[||]\s*(?:\[[^\]\r\n]+\]\((?:<https?://[^>\r\n]+>|"
+ + _PLAIN_URL
+ + r")\)|<https?://[^|>\r\n]+\|[^>\r\n]+>)\s*)+"
+)
+
+
+def _is_markdown_table_delimiter_line(line: str) -> bool:
+ """Return whether *line* is a Markdown table delimiter row."""
+ if "|" not in line:
+ return False
+ cells = line.strip().strip("|").split("|")
+ return len(cells) >= 2 and all(
+ re.fullmatch(r"\s*:?\-+:?\s*", cell) for cell in cells
+ )
+
+
+def _is_markdown_table_delimiter_before(markdown_mask: str, start: int) -> bool:
+ """Return whether a separator-free row belongs to the preceding table."""
+ prefix = markdown_mask[:start]
+ if prefix.endswith("\n"):
+ return False
+ lines = prefix.splitlines()
+ if not lines or "|" not in lines[-1]:
+ return False
+
+ # Walk through contiguous table rows so the final row of a multi-row table
+ # is not mistaken for a quick-reply footer.
+ index = len(lines) - 1
+ while index >= 0 and "|" in lines[index]:
+ if _is_markdown_table_delimiter_line(lines[index]):
+ return index > 0 and "|" in lines[index - 1]
+ index -= 1
+ return False
+
+
+def _markdown_container_level_at(text: str, start: int) -> int:
+ """Return the CommonMark container nesting level for a candidate row."""
+ newline = re.match(r"\r\n|\r|\n", text[start:])
+ if newline is None:
+ return 0
+
+ line_offsets = [0]
+ line_offsets.extend(
+ match.end() for match in re.finditer(r"\r\n|\r|\n", text)
+ )
+ candidate_position = start + newline.end()
+ line_index = bisect_left(line_offsets, candidate_position + 1) - 1
+ for token in _BLOCK_MARKDOWN.parse(text):
+ if (
+ token.type == "inline"
+ and token.map is not None
+ and token.map[0] <= line_index < token.map[1]
+ ):
+ return token.level
+ return 0
# Silent output blocks are intentionally simple and model-facing. Once a real
# opener is found outside code, its contents are opaque until the closing tag.
@@ -334,7 +413,11 @@ _SECRET_REQUEST_RE = re.compile(r"\$<([A-Za-z_][A-Za-z0-9_]*)>")
def process_reply(
- text: str, *, include_quick_replies: bool = True, keep_file_links: bool = False
+ text: str,
+ *,
+ include_quick_replies: bool = True,
+ allow_unseparated_quick_replies: bool = True,
+ keep_file_links: bool = False,
) -> EnhancedReply:
"""Parse *text* and return an ``EnhancedReply``.
@@ -346,6 +429,9 @@ def process_reply(
workbench needs the links in place so it can rewrite them to media-proxy URLs
for inline rendering; IM keeps the default (links stripped to plain labels and
uploaded to the platform separately).
+
+ ``allow_unseparated_quick_replies`` gates only the compatibility syntax;
+ explicit ``---`` button blocks retain their existing behavior.
"""
text, markdown_mask = _strip_silent_blocks_with_mask(text)
visible_text = text
@@ -360,7 +446,11 @@ def process_reply(
markdown_mask,
)
if include_quick_replies:
- buttons, text_clean = _extract_buttons(text_no_files, mask_no_files)
+ buttons, text_clean = _extract_buttons(
+ text_no_files,
+ mask_no_files,
+ allow_unseparated=allow_unseparated_quick_replies,
+ )
else:
buttons, text_clean = [], text_no_files
return EnhancedReply(
@@ -1369,13 +1459,19 @@ def _raw_html_end(
def _extract_buttons(
text: str,
markdown_mask: str | None = None,
+ *,
+ allow_unseparated: bool = True,
) -> Tuple[List[QuickReplyButton], str]:
"""Extract trailing quick-reply buttons and return ``(buttons, cleaned_text)``."""
mask = markdown_mask if markdown_mask is not None else _mask_markdown_code(text)
- masked_match = _BUTTON_BLOCK_RE.search(mask)
+ pattern = _BUTTON_BLOCK_RE
+ masked_match = pattern.search(mask)
+ if masked_match is None and allow_unseparated:
+ pattern = _UNSEPARATED_BUTTON_ROW_RE
+ masked_match = pattern.search(mask)
if masked_match is None:
return [], text
- m = _BUTTON_BLOCK_RE.fullmatch(
+ m = pattern.fullmatch(
text,
masked_match.start(),
masked_match.end(),
@@ -1383,7 +1479,31 @@ def _extract_buttons(
if m is None:
return [], text
+ if pattern is _UNSEPARATED_BUTTON_ROW_RE and not text[: m.start()].strip():
+ return [], text
+
+ if pattern is _UNSEPARATED_BUTTON_ROW_RE:
+ code_ranges, _, blocking_ranges = _markdown_block_ranges(text)
+ html_block_ranges = [
+ source_range
+ for source_range in blocking_ranges
+ if source_range not in code_ranges
+ ]
+ if any(start <= m.start(1) < end for start, end in html_block_ranges):
+ return [], text
+ if _markdown_container_level_at(text, m.start()) > 1:
+ return [], text
+
+ if pattern is _UNSEPARATED_BUTTON_ROW_RE and _is_markdown_table_delimiter_before(
+ mask, m.start()
+ ):
+ return [], text
+
block = m.group(1)
+ if pattern is _UNSEPARATED_BUTTON_ROW_RE and _LINK_ONLY_BUTTON_ROW_RE.fullmatch(
+ block.strip()
+ ):
+ return [], text
# A block made up solely of plain Markdown links with no ``|``/``|``
# separator is a genuine reference-link section (``---\n[Release notes](…)``,
# possibly several on their own lines), not a button group — leave the text
@@ -1402,8 +1522,20 @@ def _extract_buttons(
if not buttons:
return [], text
+ if pattern is _UNSEPARATED_BUTTON_ROW_RE and len(buttons) > 5:
+ return [], text
+
+ if pattern is _UNSEPARATED_BUTTON_ROW_RE and len(buttons) < 2:
+ return [], text
+
# Enforce a reasonable upper bound on button count
buttons = buttons[:5]
cleaned = text[: m.start()]
return buttons, cleaned
+
+
+def strip_quick_reply_buttons(text: str) -> str:
+ """Remove a trailing quick-reply row while preserving all other markup."""
+ _, cleaned = _extract_buttons(text)
+ return cleaned
diff --git a/modules/agents/native_sessions/base.py b/modules/agents/native_sessions/base.py
index 8a1cd0fd1..fbcdb0531 100644
--- a/modules/agents/native_sessions/base.py
+++ b/modules/agents/native_sessions/base.py
@@ -6,6 +6,7 @@ from datetime import datetime
from pathlib import Path
from typing import Protocol
+from core.reply_enhancer import strip_quick_reply_buttons
from .types import BackendSessionTitle, NativeResumeSession
logger = logging.getLogger(__name__)
@@ -31,10 +32,12 @@ class NativeSessionProvider(Protocol):
"""Return a backfillable title for a native session, if available."""
-def normalize_preview_text(text: str) -> str:
+def normalize_preview_text(text: str, *, strip_quick_replies: bool = True) -> str:
if not text:
return ""
cleaned = text.replace("\r\n", "\n").replace("\r", "\n")
+ if strip_quick_replies:
+ cleaned = strip_quick_reply_buttons(cleaned)
if "\n---\n" in cleaned:
cleaned = cleaned.split("\n---\n", 1)[0]
lines = [line.strip() for line in cleaned.split("\n") if line.strip()]
@@ -42,16 +45,22 @@ def normalize_preview_text(text: str) -> str:
def normalize_title_text(text: str, *, limit: int | None = None) -> str:
- cleaned = normalize_preview_text(text)
+ cleaned = normalize_preview_text(text, strip_quick_replies=False)
if not cleaned:
return ""
return cleaned[:limit] if limit is not None else cleaned
-def normalize_multiline_preview_text(text: str) -> str:
+def normalize_multiline_preview_text(
+ text: str,
+ *,
+ strip_quick_replies: bool = True,
+) -> str:
if not text:
return ""
cleaned = text.replace("\r\n", "\n").replace("\r", "\n")
+ if strip_quick_replies:
+ cleaned = strip_quick_reply_buttons(cleaned)
if "\n---\n" in cleaned:
cleaned = cleaned.split("\n---\n", 1)[0]
@@ -79,8 +88,14 @@ def trim_edge_symbols(text: str) -> str:
return (text or "").strip(EDGE_SYMBOLS)
-def build_trailing_excerpt(text: str, limit: int, *, prefix_ellipsis: bool = True) -> str:
- cleaned = normalize_preview_text(text)
+def build_trailing_excerpt(
+ text: str,
+ limit: int,
+ *,
+ prefix_ellipsis: bool = True,
+ strip_quick_replies: bool = True,
+) -> str:
+ cleaned = normalize_preview_text(text, strip_quick_replies=strip_quick_replies)
if not cleaned:
return ""
excerpt = cleaned if len(cleaned) <= limit else cleaned[-limit:]
@@ -92,12 +107,30 @@ def build_trailing_excerpt(text: str, limit: int, *, prefix_ellipsis: bool = Tru
return f"...{excerpt}" if prefix_ellipsis else excerpt
-def build_tail_preview(text: str, limit: int = 15) -> str:
- return build_trailing_excerpt(text, limit, prefix_ellipsis=True)
-
-
-def build_resume_preview(text: str, limit: int = 200) -> str:
- cleaned = normalize_multiline_preview_text(text)
+def build_tail_preview(
+ text: str,
+ limit: int = 15,
+ *,
+ strip_quick_replies: bool = True,
+) -> str:
+ return build_trailing_excerpt(
+ text,
+ limit,
+ prefix_ellipsis=True,
+ strip_quick_replies=strip_quick_replies,
+ )
+
+
+def build_resume_preview(
+ text: str,
+ limit: int = 200,
+ *,
+ strip_quick_replies: bool = True,
+) -> str:
+ cleaned = normalize_multiline_preview_text(
+ text,
+ strip_quick_replies=strip_quick_replies,
+ )
if not cleaned:
return ""
excerpt = cleaned if len(cleaned) <= limit else cleaned[-limit:]
diff --git a/tests/test_message_dispatcher_result_fallback.py b/tests/test_message_dispatcher_result_fallback.py
index e389f219e..ff922cbf0 100644
--- a/tests/test_message_dispatcher_result_fallback.py
+++ b/tests/test_message_dispatcher_result_fallback.py
@@ -810,6 +810,49 @@ class MessageDispatcherResultFallbackTests(unittest.IsolatedAsyncioTestCase):
self.assertIsNone(reply_to)
self.assertEqual([button.text for button in keyboard.buttons[0]], ["Continue", "Stop"])
+ async def test_wechat_result_preserves_separator_free_button_like_text(self):
+ im_client = _StubIMClient()
+ controller = _StubController(
+ platform="wechat",
+ im_client=im_client,
+ reply_enhancements=True,
+ )
+ dispatcher = ConsolidatedMessageDispatcher(controller)
+ context = MessageContext(user_id="wx1", channel_id="wx1", platform="wechat")
+
+ message_id = await dispatcher.emit_agent_message(
+ context,
+ "result",
+ "Compare:\n[A] | [B]",
+ )
+
+ self.assertEqual(message_id, "msg-1")
+ self.assertEqual(im_client.sent_messages[0][1], "Compare:\n[A] | [B]")
+
+ async def test_separator_free_parsing_uses_delivery_target_capability(self):
+ im_client = _StubIMClient()
+ controller = _StubController(
+ platform="slack",
+ im_client=im_client,
+ reply_enhancements=True,
+ )
+ dispatcher = ConsolidatedMessageDispatcher(controller)
+ context = MessageContext(
+ user_id="U1",
+ channel_id="C1",
+ platform="slack",
+ platform_specific={
+ "delivery_override": {
+ "platform": "wechat",
+ "channel_id": "wx1",
+ }
+ },
+ )
+
+ await dispatcher.emit_agent_message(context, "result", "Compare:\n[A] | [B]")
+
+ self.assertEqual(im_client.sent_messages[0][1], "Compare:\n[A] | [B]")
+
async def test_result_footer_rides_subtext_on_status_bubble_platform(self):
"""On a ``supports_status_bubble`` platform (Slack) the show_duration
footnote is delivered as the de-emphasized ``subtext`` footer and the body
@@ -968,6 +1011,20 @@ class MessageDispatcherResultFallbackTests(unittest.IsolatedAsyncioTestCase):
self.assertNotIn("[✅ Yes]", persist.call_args.args[2])
self.assertIn("Pick one", persist.call_args.args[2])
+ async def test_avibe_result_persists_unseparated_quick_replies_for_workbench(self):
+ controller = _StubController(platform="avibe", reply_enhancements=True)
+ dispatcher = ConsolidatedMessageDispatcher(controller)
+ context = MessageContext(user_id="U1", channel_id="C1", platform="avibe")
+ raw = "Pick one:\n[✅ Yes] | [🙅 No]"
+
+ with mock.patch("core.message_dispatcher.persist_agent_message") as persist:
+ await dispatcher.emit_agent_message(context, "result", raw)
+
+ persist.assert_called_once()
+ self.assertEqual(persist.call_args.kwargs.get("quick_replies"), ["✅ Yes", "🙅 No"])
+ self.assertNotIn("[✅ Yes]", persist.call_args.args[2])
+ self.assertIn("Pick one", persist.call_args.args[2])
+
async def test_visible_workbench_terminal_result_requires_durable_message(self):
controller = _StubController(platform="avibe")
dispatcher = ConsolidatedMessageDispatcher(controller)
diff --git a/tests/test_native_session_providers.py b/tests/test_native_session_providers.py
index 7b61c1a5f..0e445f14c 100644
--- a/tests/test_native_session_providers.py
+++ b/tests/test_native_session_providers.py
@@ -6,7 +6,13 @@ from pathlib import Path
from types import SimpleNamespace
import json
-from modules.agents.native_sessions.base import build_resume_preview, build_tail_preview
+from modules.agents.native_sessions.base import (
+ build_resume_preview,
+ build_tail_preview,
+ normalize_multiline_preview_text,
+ normalize_preview_text,
+ normalize_title_text,
+)
from modules.agents.native_sessions import claude as claude_module
from modules.agents.native_sessions.claude import ClaudeNativeSessionProvider, encode_project_path
from modules.agents.native_sessions import codex as codex_module
@@ -605,3 +611,17 @@ def test_build_resume_preview_preserves_line_breaks() -> None:
text = "第一段第一行\n第二行\n\n第三行\n---\n[button]"
assert build_resume_preview(text, limit=200) == "第一段第一行\n第二行\n\n第三行"
+
+
+def test_native_session_previews_strip_unseparated_quick_replies() -> None:
+ text = "Done\n[A] | [B]"
+
+ assert normalize_preview_text(text) == "Done"
+ assert normalize_multiline_preview_text(text) == "Done"
+ assert build_tail_preview(text, limit=200) == "Done"
+
+
+def test_native_session_titles_preserve_button_like_user_prompt_content() -> None:
+ text = "Compare these values:\n[A] | [B]"
+
+ assert normalize_title_text(text) == "Compare these values: [A] | [B]"
diff --git a/tests/test_reply_enhancer_platform.py b/tests/test_reply_enhancer_platform.py
index 412894682..5fe32b848 100644
--- a/tests/test_reply_enhancer_platform.py
+++ b/tests/test_reply_enhancer_platform.py
@@ -599,6 +599,44 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(reply.text, text)
self.assertEqual(reply.buttons, [])
+ def test_process_reply_preserves_unseparated_button_row_in_code(self):
+ text = "```markdown\n[Yes] | [No]\n```"
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_preserves_unseparated_button_row_in_raw_html(self):
+ text = "<div>\n[A] | [B]"
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_accepts_row_after_closed_raw_html_block(self):
+ reply = process_reply("<script>\ncontent\n</script>\n[A] | [B]")
+
+ self.assertEqual(reply.text, "<script>\ncontent\n</script>")
+ self.assertEqual([button.text for button in reply.buttons], ["A", "B"])
+
+ def test_process_reply_preserves_oversized_separator_free_row(self):
+ text = "Grades:\n[A] | [B] | [C] | [D] | [E] | [F]"
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_ignores_indented_code_when_scanning_table_context(self):
+ text = " Head | Status\n --- | ---\n[A] | [B]"
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, " Head | Status\n --- | ---")
+ self.assertEqual([button.text for button in reply.buttons], ["A", "B"])
+
def test_silent_parser_preserves_inline_code_and_trailing_report_byte_for_byte(self):
trailing_report = "\n".join(
[
@@ -1449,6 +1487,22 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual([file.path for file in reply.files], ["/tmp/report.txt"])
self.assertEqual(reply.buttons, [])
+ def test_process_reply_can_disable_only_separator_free_parsing(self):
+ reply = process_reply(
+ "Done.\n[A] | [B]",
+ allow_unseparated_quick_replies=False,
+ )
+
+ self.assertEqual(reply.text, "Done.\n[A] | [B]")
+ self.assertEqual(reply.buttons, [])
+
+ explicit = process_reply(
+ "Done.\n---\n[A] | [B]",
+ allow_unseparated_quick_replies=False,
+ )
+ self.assertEqual(explicit.text, "Done.")
+ self.assertEqual([button.text for button in explicit.buttons], ["A", "B"])
+
def test_process_reply_accepts_markdown_link_style_quick_reply_button(self):
reply = process_reply(
"Done.\n\n---\n"
@@ -1462,6 +1516,43 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
[":eyes: 看 PR", ":rocket: 等评审完合并", ":test_tube: 先回归测一遍"],
)
+ def test_process_reply_preserves_bodyless_pipe_row_without_rule(self):
+ text = "[A] | [B]"
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_preserves_whitespace_only_body_without_rule(self):
+ text = "\n[A] | [B]"
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_preserves_final_row_of_markdown_table(self):
+ text = (
+ "Option | Status\n"
+ "--- | ---\n"
+ "[Docs](https://example.com) | [Open]\n"
+ "[Issue](https://example.com/1) | [Closed]"
+ )
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_preserves_short_markdown_table_delimiter(self):
+ text = "Option | Status\n- | -\n[A] | [B]"
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
def test_process_reply_accepts_slack_angle_link_style_quick_reply_button(self):
reply = process_reply(
"Done.\n\n---\n"
@@ -1475,6 +1566,113 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
[":eyes: 看 PR", ":rocket: 等评审完合并", ":test_tube: 先回归测一遍"],
)
+ def test_process_reply_accepts_pipe_separated_buttons_without_rule(self):
+ reply = process_reply("Done.\n[查看冲突] | [继续修复]")
+
+ self.assertEqual(reply.text, "Done.")
+ self.assertEqual(
+ [button.text for button in reply.buttons],
+ ["查看冲突", "继续修复"],
+ )
+
+ def test_process_reply_accepts_buttons_after_blank_line(self):
+ reply = process_reply("Table | Value\n\n[A] | [B]")
+
+ self.assertEqual(reply.text, "Table | Value")
+ self.assertEqual([button.text for button in reply.buttons], ["A", "B"])
+
+ def test_process_reply_preserves_lazy_markdown_container_continuations(self):
+ for text in (
+ "> Compare these states:\n[A] | [B]",
+ "- Compare these states:\n[A] | [B]",
+ "1. Compare these states:\n[A] | [B]",
+ ):
+ with self.subTest(text=text):
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_accepts_fullwidth_pipe_without_rule(self):
+ reply = process_reply("Done.\n[A] | [B]")
+
+ self.assertEqual(reply.text, "Done.")
+ self.assertEqual([button.text for button in reply.buttons], ["A", "B"])
+
+ def test_process_reply_accepts_trailing_pipe_without_rule(self):
+ for text in ("Done.\n[A] | [B] |", "Done.\n[A] | [B] |"):
+ with self.subTest(text=text):
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, "Done.")
+ self.assertEqual([button.text for button in reply.buttons], ["A", "B"])
+
+ def test_process_reply_preserves_single_bracket_line_without_rule(self):
+ text = "Use this value:\n[example]"
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_preserves_unseparated_row_with_blank_button_label(self):
+ text = "Checkbox states:\n[ ] | [Checked]"
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_preserves_plain_link_without_rule(self):
+ text = "Done.\n[Release notes](https://example.com)"
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_preserves_separator_free_markdown_link_list(self):
+ text = (
+ "Links\n"
+ "[Documentation](https://example.com/docs) | "
+ "[Issues](https://example.com/issues)"
+ )
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_preserves_separator_free_slack_link_list(self):
+ text = (
+ "Links\n"
+ "[Documentation](<https://example.com/docs>) | "
+ "<https://example.com/issues|Issues>"
+ )
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_preserves_markdown_table_last_row(self):
+ text = (
+ "Option | Status\n"
+ "--- | ---\n"
+ "[Docs](https://example.com) | [Issue](https://example.com/1)"
+ )
+
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_accepts_unseparated_buttons_with_crlf(self):
+ reply = process_reply("Done\r\n[A] | [B]\r\n")
+
+ self.assertEqual(reply.text, "Done")
+ self.assertEqual([button.text for button in reply.buttons], ["A", "B"])
+
def test_process_reply_ignores_bare_angle_link_as_quick_reply_button(self):
text = "Done.\n\n---\n<https://github.com/avibe-bot/avibe/pull/298>"
reply = process_reply(text)