fix(telegram,core): first message seeds the branch, registered commands, no ellipses, html drafts

This commit is contained in:
hh
2026-08-28 18:25:46 +02:00
parent 9663fbf956
commit 0110cbd1cc
5 changed files with 111 additions and 78 deletions
+20 -19
View File
@@ -234,7 +234,8 @@ async def stack() -> Stack:
async def test_general_is_master_and_reply_has_no_thread(stack: Stack) -> None:
stack.bot.message("hi")
reply = await stack.until(lambda: stack.sent_with("ok:hi"), what="reply")
reply = await stack.until(lambda: stack.sent_with("hi"), what="reply")
assert reply["text"].startswith("ok:[сид: clean] master")
assert reply["thread"] == 901
assert reply["parse_mode"] == "HTML"
assert stack.bot.topics == ["🦫 General"]
@@ -244,7 +245,7 @@ async def test_general_is_master_and_reply_has_no_thread(stack: Stack) -> None:
assert master is not None and master.kind == "master"
assert stack.bot.drafts and stack.bot.drafts[0]["chat_id"] == USER
rows = await stack.world.conversations.queue.recent(master.id)
assert {r.origin for r in rows} == {"сид:clean", "telegram"}
assert [r.origin for r in rows] == ["telegram"]
async def test_new_topic_becomes_morning_branch_and_replies_in_thread(
@@ -252,8 +253,9 @@ async def test_new_topic_becomes_morning_branch_and_replies_in_thread(
) -> None:
stack.bot.topic_created("план", 7)
stack.bot.message("hello topic", thread=7)
reply = await stack.until(lambda: stack.sent_with("ok:hello topic"), what="reply")
reply = await stack.until(lambda: stack.sent_with("hello topic"), what="reply")
assert reply["thread"] == 7
assert len([m for m in stack.bot.sent if m["thread"] == 7]) == 1
branch = await stack.world.conversations.find_bound(
frontend="telegram", external_id=f"{USER}/7"
)
@@ -266,6 +268,7 @@ async def test_new_topic_becomes_morning_branch_and_replies_in_thread(
prompts = [p for c in ScriptedClient.instances for p in c.prompts]
seed = next(p for p in prompts if p.startswith("[сид: morning] branch «план»"))
assert "Хендаут не приехал." in seed
assert seed.endswith("hello topic")
assert stack.bot.drafts[-1]["message_thread_id"] == 7
@@ -317,7 +320,7 @@ async def test_message_into_merged_branch_rebinds_the_topic(stack: Stack) -> Non
async def test_reply_from_another_window_is_mirrored_with_marker(stack: Stack) -> None:
stack.bot.message("hi")
await stack.until(lambda: stack.sent_with("ok:hi"), what="reply")
await stack.until(lambda: stack.sent_with("hi"), what="reply")
master = await stack.world.conversations.find_bound(
frontend="telegram", external_id=GENERAL
)
@@ -331,7 +334,7 @@ async def test_reply_from_another_window_is_mirrored_with_marker(stack: Stack) -
async def test_say_is_delivered_and_inject_turns_are_silent(stack: Stack) -> None:
stack.bot.message("hi")
await stack.until(lambda: stack.sent_with("ok:hi"), what="reply")
await stack.until(lambda: stack.sent_with("hi"), what="reply")
master = await stack.world.conversations.find_bound(
frontend="telegram", external_id=GENERAL
)
@@ -339,7 +342,7 @@ async def test_say_is_delivered_and_inject_turns_are_silent(stack: Stack) -> Non
await stack.world.conversations.inject(
master, "cron tick", urgency="urgent", origin="крон"
)
await stack.world.settle(master, 3)
await stack.world.settle(master, 2)
await asyncio.sleep(0.2)
assert len(stack.bot.sent) == before
await stack.world.conversations.say(master, "psst")
@@ -348,7 +351,7 @@ async def test_say_is_delivered_and_inject_turns_are_silent(stack: Stack) -> Non
async def test_question_becomes_buttons_and_callback_answers(stack: Stack) -> None:
stack.bot.message("hi")
await stack.until(lambda: stack.sent_with("ok:hi"), what="reply")
await stack.until(lambda: stack.sent_with("hi"), what="reply")
master = await stack.world.conversations.find_bound(
frontend="telegram", external_id=GENERAL
)
@@ -393,7 +396,7 @@ async def test_question_timeout_renders_text_and_free_text_answers(
stack: Stack,
) -> None:
stack.bot.message("hi")
await stack.until(lambda: stack.sent_with("ok:hi"), what="reply")
await stack.until(lambda: stack.sent_with("hi"), what="reply")
master = await stack.world.conversations.find_bound(
frontend="telegram", external_id=GENERAL
)
@@ -455,16 +458,16 @@ async def test_commands_status_merge_and_new(stack: Stack) -> None:
async def test_master_topic_survives_rotation(stack: Stack) -> None:
stack.bot.message("hi")
await stack.until(lambda: stack.sent_with("ok:hi"), what="reply")
await stack.until(lambda: stack.sent_with("hi"), what="reply")
master = await stack.world.conversations.find_bound(
frontend="telegram", external_id=GENERAL
)
stack.bot.message("into general", thread=901)
await stack.until(lambda: stack.sent_with("ok:into general"), what="reply")
await stack.until(lambda: stack.sent_with("into general"), what="reply")
assert (await stack.world.conversations.find(kind="branch")) == []
await stack.world.conversations.set_status(master, "closed")
stack.bot.message("after rotation", thread=901)
await stack.until(lambda: stack.sent_with("ok:after rotation"), what="reply")
await stack.until(lambda: stack.sent_with("after rotation"), what="reply")
fresh = await stack.world.conversations.find_bound(
frontend="telegram", external_id=GENERAL
)
@@ -475,7 +478,7 @@ async def test_master_topic_survives_rotation(stack: Stack) -> None:
async def test_inbox_stores_first_and_replays_after_restart(stack: Stack) -> None:
stack.bot.message("hi")
await stack.until(lambda: stack.sent_with("ok:hi"), what="reply")
await stack.until(lambda: stack.sent_with("hi"), what="reply")
async with stack.world.db.session() as session:
rows = list((await session.exec(select(TelegramUpdate))).all())
assert [r.update_id for r in rows] == [1000]
@@ -498,7 +501,7 @@ async def test_inbox_stores_first_and_replays_after_restart(stack: Stack) -> Non
)
await session.commit()
await stack.until(
lambda: stack.sent_with("ok:replayed"), timeout=8, what="replayed reply"
lambda: stack.sent_with("replayed"), timeout=8, what="replayed reply"
)
stack.bot.message("stranger", uid=1)
await asyncio.sleep(0.3)
@@ -509,7 +512,7 @@ async def test_outbox_retries_and_falls_back_to_plain(stack: Stack) -> None:
stack.bot.fail_sends = 2
stack.bot.reject_html = True
stack.bot.message("**bold**")
reply = await stack.until(lambda: stack.sent_with("ok:**bold**"), what="reply")
reply = await stack.until(lambda: stack.sent_with("**bold**"), what="reply")
assert reply["parse_mode"] is None
async with stack.world.db.session() as session:
rows = list((await session.exec(select(Delivery))).all())
@@ -548,8 +551,6 @@ def test_render_helpers() -> None:
)
parts = chunks("абв\n\n" + "г" * 30 + "\n\n" + "д" * 30, limit=40)
assert parts == ["абв\n\n" + "г" * 30, "д" * 30]
assert status_label("Read", {"file_path": "/x"}) == "читаю vault"
assert (
status_label("mcp__firefly__list_accounts", None) == "firefly: list_accounts…"
)
assert status_label("Foo", {"command": "ls -la"}) == "Foo ls -la…"
assert status_label("Read", {"file_path": "/x"}) == "читаю vault"
assert status_label("mcp__firefly__list_accounts", None) == "firefly: list_accounts"
assert status_label("Foo", {"command": "ls -la"}) == "Foo ls -la"