fix: skip history for interaction exit notices

This commit is contained in:
jxxghp
2026-06-23 12:05:27 +08:00
parent 3e3883a57f
commit d18c2d6f72
5 changed files with 77 additions and 0 deletions

View File

@@ -789,6 +789,7 @@ class SiteChain(ChainBase):
userid=userid,
username=username,
title="站点交互已结束",
save_history=False,
)
)
return True

View File

@@ -266,6 +266,7 @@ class SkillsChain(ChainBase):
userid=userid,
username=username,
title="技能交互已结束",
save_history=False,
)
)
return True

View File

@@ -2240,6 +2240,7 @@ class SubscribeChain(ChainBase):
userid=userid,
username=username,
title="订阅交互已结束",
save_history=False,
)
)
return True

View File

@@ -90,6 +90,30 @@ class TestSkillsCommand(unittest.TestCase):
handle_text.assert_called_once()
handle_ai.assert_not_called()
def test_skills_text_exit_skips_notification_history(self):
chain = SkillsChain()
skills_interaction_manager.create_or_replace(
user_id="10001",
channel=MessageChannel.Telegram,
source="telegram-test",
username="tester",
)
with patch.object(chain, "post_message") as post_message:
handled = chain.handle_text_interaction(
channel=MessageChannel.Telegram,
source="telegram-test",
userid="10001",
username="tester",
text="退出",
)
self.assertTrue(handled)
notification = post_message.call_args.args[0]
self.assertEqual(notification.title, "技能交互已结束")
self.assertFalse(notification.save_history)
self.assertIsNone(skills_interaction_manager.get_by_user("10001"))
def test_callback_routes_to_skills_chain(self):
chain = MessageChain()
request = skills_interaction_manager.create_or_replace(

View File

@@ -147,6 +147,56 @@ class TestSlashCommandInteractions(unittest.TestCase):
handle_callback.assert_called_once()
def test_sites_text_exit_skips_notification_history(self):
chain = SiteChain()
site_interaction_manager.create_or_replace(
user_id="10001",
command="/sites",
channel=MessageChannel.Telegram,
source="telegram-test",
username="tester",
)
with patch.object(chain, "post_message") as post_message:
handled = chain.handle_text_interaction(
channel=MessageChannel.Telegram,
source="telegram-test",
userid="10001",
username="tester",
text="退出",
)
self.assertTrue(handled)
notification = post_message.call_args.args[0]
self.assertEqual(notification.title, "站点交互已结束")
self.assertFalse(notification.save_history)
self.assertIsNone(site_interaction_manager.get_by_user("10001"))
def test_subscribes_text_exit_skips_notification_history(self):
chain = SubscribeChain()
subscribe_interaction_manager.create_or_replace(
user_id="10001",
command="/subscribes",
channel=MessageChannel.Telegram,
source="telegram-test",
username="tester",
)
with patch.object(chain, "post_message") as post_message:
handled = chain.handle_text_interaction(
channel=MessageChannel.Telegram,
source="telegram-test",
userid="10001",
username="tester",
text="退出",
)
self.assertTrue(handled)
notification = post_message.call_args.args[0]
self.assertEqual(notification.title, "订阅交互已结束")
self.assertFalse(notification.save_history)
self.assertIsNone(subscribe_interaction_manager.get_by_user("10001"))
def test_sites_renders_markdown_table_when_channel_supports_markdown(self):
chain = SiteChain()
fake_sites = [